MediaWiki:Common.js

Revision as of 21:12, 20 December 2025 by ICEListAdmin6 (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* 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 = '&times;';
      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();
  }
})();