MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
* - ONLY runs for anonymous users | * - ONLY runs for anonymous users | ||
* - ONLY styles when Anonnotice has content | * - ONLY styles when Anonnotice has content | ||
* - Adds a close (×) button | * - Adds a close (×) button | ||
* - Remembers dismissal in localStorage | * - Remembers dismissal in localStorage | ||
*/ | */ | ||
| Line 11: | Line 11: | ||
var DAYS = 14; | var DAYS = 14; | ||
if (!mw.user.isAnon()) return; | if (!mw.user.isAnon()) return; | ||
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 22: | Line 20: | ||
if (!siteNotice) return; | if (!siteNotice) return; | ||
var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim(); | var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim(); | ||
if (!txt) return; | if (!txt) return; | ||
siteNotice.classList.add('icelist-anon-donate'); | siteNotice.classList.add('icelist-anon-donate'); | ||
// | // Donate link hook (optional) + fallback | ||
var donateLink = siteNotice.querySelector('.icelist-donate-cta a') | |||
|| siteNotice.querySelector('a[href*="ICE_List_Wiki:Donate"]'); | |||
var donateLink = siteNotice.querySelector('.icelist-donate-cta a') | |||
if (donateLink) donateLink.classList.add('icelist-donate-btn'); | if (donateLink) donateLink.classList.add('icelist-donate-btn'); | ||
// Add close button | // Add close button once | ||
if (!siteNotice.querySelector('.icelist-notice-close')) { | if (!siteNotice.querySelector('.icelist-notice-close')) { | ||
var btn = document.createElement('button'); | var btn = document.createElement('button'); | ||
| Line 47: | Line 38: | ||
btn.textContent = '×'; | btn.textContent = '×'; | ||
// | // put it at the top so it can't get shoved off-screen by table layout | ||
siteNotice.insertBefore(btn, siteNotice.firstChild); | siteNotice.insertBefore(btn, siteNotice.firstChild); | ||
| Line 59: | Line 50: | ||
} | } | ||
// | // run when page content is ready (MW-safe) | ||
mw.hook('wikipage.content').add(mount); | |||
})(); | })(); | ||
Revision as of 22:10, 20 December 2025
/* ICE List – Anon donate banner (safe + scoped)
* - ONLY runs for anonymous users
* - ONLY styles when Anonnotice has content
* - Adds a close (×) button
* - Remembers dismissal in localStorage
*/
(function () {
'use strict';
var KEY = 'icelist_anon_donate_dismiss_until';
var DAYS = 14;
if (!mw.user.isAnon()) return;
var until = parseInt(localStorage.getItem(KEY) || '0', 10);
if (Date.now() < until) return;
function mount() {
var siteNotice = document.getElementById('siteNotice');
if (!siteNotice) return;
var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim();
if (!txt) return;
siteNotice.classList.add('icelist-anon-donate');
// Donate link hook (optional) + fallback
var donateLink = siteNotice.querySelector('.icelist-donate-cta a')
|| siteNotice.querySelector('a[href*="ICE_List_Wiki:Donate"]');
if (donateLink) donateLink.classList.add('icelist-donate-btn');
// Add close button once
if (!siteNotice.querySelector('.icelist-notice-close')) {
var btn = document.createElement('button');
btn.type = 'button';
btn.className = 'icelist-notice-close';
btn.setAttribute('aria-label', 'Close');
btn.textContent = '×';
// put it at the top so it can't get shoved off-screen by table layout
siteNotice.insertBefore(btn, siteNotice.firstChild);
btn.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
siteNotice.style.display = 'none';
localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
});
}
}
// run when page content is ready (MW-safe)
mw.hook('wikipage.content').add(mount);
})();