MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* ICE List – Donate notice controller | |||
* - Shows a big top notice for anonymous users | |||
* - Dismissible with X | |||
* - Remembers dismissal for N days via localStorage | |||
* - Replaces whatever is in #siteNotice (including plain Anonnotice text) | |||
*/ | |||
(function () { | (function () { | ||
'use strict'; | |||
// === CONFIG === | |||
var KEY = 'icelist_donate_notice_until'; | var KEY = 'icelist_donate_notice_until'; | ||
var DAYS = 14; | var DAYS = 14; | ||
// Show only to anonymous users | |||
if (!mw.user.isAnon()) return; | if (!mw.user.isAnon()) return; | ||
// Respect dismissal window | |||
var until = parseInt(localStorage.getItem(KEY) || '0', 10); | var until = parseInt(localStorage.getItem(KEY) || '0', 10); | ||
if (Date.now() < until) return; | if (Date.now() < until) return; | ||
| Line 46: | Line 24: | ||
if (!siteNotice) return; | if (!siteNotice) return; | ||
// If | // If there is literally no notice area text/content, still allow injection. | ||
// (Some skins may render an empty wrapper; that’s fine.) | |||
siteNotice.innerHTML = | // Build the banner as real DOM/HTML (NOT escaped entities) | ||
siteNotice.innerHTML = | |||
'<div id="donate-top-notice">' + | '<div id="donate-top-notice">' + | ||
'<div class="donate-notice-inner">' + | '<div class="donate-notice-inner">' + | ||
| Line 57: | Line 34: | ||
'<span class="donate-text">We document federal immigration enforcement, identify agents, and preserve evidence that would otherwise disappear. Donations keep this work public, independent, and alive.</span>' + | '<span class="donate-text">We document federal immigration enforcement, identify agents, and preserve evidence that would otherwise disappear. Donations keep this work public, independent, and alive.</span>' + | ||
'<a class="donate-btn" href="' + mw.util.getUrl('ICE_List_Wiki:Donate') + '">Donate</a>' + | '<a class="donate-btn" href="' + mw.util.getUrl('ICE_List_Wiki:Donate') + '">Donate</a>' + | ||
'<button id="donate-notice-close" aria-label="Close">×</button>' + | '<button id="donate-notice-close" aria-label="Close" type="button">×</button>' + | ||
'</div>' + | '</div>' + | ||
'</div>' | '</div>'; | ||
); | |||
var closeBtn = document.getElementById('donate-notice-close'); | |||
if (!closeBtn) return; | |||
closeBtn.addEventListener('click', function () { | |||
document.getElementById('donate-top-notice').style.display = 'none'; | var wrap = document.getElementById('donate-top-notice'); | ||
if (wrap) wrap.style.display = 'none'; | |||
localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000)); | localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000)); | ||
}); | }); | ||
} | } | ||
// Ensure DOM is ready | |||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', mount); | document.addEventListener('DOMContentLoaded', mount); | ||
Revision as of 14:14, 20 December 2025
/* ICE List – Donate notice controller
* - Shows a big top notice for anonymous users
* - Dismissible with X
* - Remembers dismissal for N days via localStorage
* - Replaces whatever is in #siteNotice (including plain Anonnotice text)
*/
(function () {
'use strict';
// === CONFIG ===
var KEY = 'icelist_donate_notice_until';
var DAYS = 14;
// Show only to anonymous users
if (!mw.user.isAnon()) return;
// Respect dismissal window
var until = parseInt(localStorage.getItem(KEY) || '0', 10);
if (Date.now() < until) return;
function mount() {
var siteNotice = document.getElementById('siteNotice');
if (!siteNotice) return;
// If there is literally no notice area text/content, still allow injection.
// (Some skins may render an empty wrapper; that’s fine.)
// Build the banner as real DOM/HTML (NOT escaped entities)
siteNotice.innerHTML =
'<div id="donate-top-notice">' +
'<div class="donate-notice-inner">' +
'<span class="donate-title">Support ICE List</span>' +
'<span class="donate-text">We document federal immigration enforcement, identify agents, and preserve evidence that would otherwise disappear. Donations keep this work public, independent, and alive.</span>' +
'<a class="donate-btn" href="' + mw.util.getUrl('ICE_List_Wiki:Donate') + '">Donate</a>' +
'<button id="donate-notice-close" aria-label="Close" type="button">×</button>' +
'</div>' +
'</div>';
var closeBtn = document.getElementById('donate-notice-close');
if (!closeBtn) return;
closeBtn.addEventListener('click', function () {
var wrap = document.getElementById('donate-top-notice');
if (wrap) wrap.style.display = 'none';
localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
});
}
// Ensure DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', mount);
} else {
mount();
}
})();