MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* | /* ICE List — Anon donate banner (safe + minimal) | ||
* - Styles are done in Common.css (targets #siteNotice.icelist-donate-notice) | |||
* - Adds an X close button | |||
* - Hides empty #siteNotice for logged-in users (prevents the blank grey bar) | |||
* - Remembers dismissal for 14 days (localStorage) | |||
*/ | |||
(function () { | |||
'use strict'; | |||
var KEY = 'icelist_donate_notice_until'; | |||
var DAYS = 14; | |||
var | function run() { | ||
var siteNotice = document.getElementById('siteNotice'); | |||
if (!siteNotice) return; | |||
var isAnon = (mw.user && mw.user.isAnon && mw.user.isAnon()); | |||
// Logged-in users: if the wrapper exists but there's no content, kill it. | |||
if (!isAnon) { | |||
if (((siteNotice.textContent || '').trim()) === '') { | |||
siteNotice.style.display = 'none'; | |||
} | |||
return; | |||
} | |||
// Anonymous users: respect dismissal window | |||
var until = parseInt(localStorage.getItem(KEY) || '0', 10); | |||
if (Date.now() < until) { | |||
siteNotice.style.display = 'none'; | |||
return; | |||
} | |||
// Mark for CSS to style | |||
siteNotice.classList.add('icelist-donate-notice'); | |||
// Add close button if missing | |||
var closeBtn = siteNotice.querySelector('.icelist-notice-close'); | |||
if (!closeBtn) { | |||
closeBtn = document.createElement('button'); | |||
closeBtn.type = 'button'; | |||
closeBtn.className = 'icelist-notice-close'; | |||
closeBtn.setAttribute('aria-label', 'Close'); | |||
closeBtn.innerHTML = '×'; | |||
siteNotice.appendChild(closeBtn); | |||
} | |||
closeBtn.addEventListener('click', function () { | |||
siteNotice.style.display = 'none'; | |||
localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000)); | |||
} | }); | ||
} | |||
// Run on initial load + when MW swaps content | |||
}); | if (window.mw && mw.hook) { | ||
mw.hook('wikipage.content').add(run); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', run); | |||
} else { | |||
run(); | |||
} | |||
})(); | |||
Revision as of 21:12, 20 December 2025
/* ICE List — Anon donate banner (safe + minimal)
* - Styles are done in Common.css (targets #siteNotice.icelist-donate-notice)
* - Adds an X close button
* - Hides empty #siteNotice for logged-in users (prevents the blank grey bar)
* - Remembers dismissal for 14 days (localStorage)
*/
(function () {
'use strict';
var KEY = 'icelist_donate_notice_until';
var DAYS = 14;
function run() {
var siteNotice = document.getElementById('siteNotice');
if (!siteNotice) return;
var isAnon = (mw.user && mw.user.isAnon && mw.user.isAnon());
// Logged-in users: if the wrapper exists but there's no content, kill it.
if (!isAnon) {
if (((siteNotice.textContent || '').trim()) === '') {
siteNotice.style.display = 'none';
}
return;
}
// Anonymous users: respect dismissal window
var until = parseInt(localStorage.getItem(KEY) || '0', 10);
if (Date.now() < until) {
siteNotice.style.display = 'none';
return;
}
// Mark for CSS to style
siteNotice.classList.add('icelist-donate-notice');
// Add close button if missing
var closeBtn = siteNotice.querySelector('.icelist-notice-close');
if (!closeBtn) {
closeBtn = document.createElement('button');
closeBtn.type = 'button';
closeBtn.className = 'icelist-notice-close';
closeBtn.setAttribute('aria-label', 'Close');
closeBtn.innerHTML = '×';
siteNotice.appendChild(closeBtn);
}
closeBtn.addEventListener('click', function () {
siteNotice.style.display = 'none';
localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
});
}
// Run on initial load + when MW swaps content
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(run);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', run);
} else {
run();
}
})();