Jump to content

MediaWiki:Common.js

From ICE List Wiki
Revision as of 08:30, 30 June 2026 by AdminBot (talk | contribs) (Replace volunteer-app SPA loader with simple logged-in toggle)

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.
/* Load CRUST brand fonts โ€” ResourceLoader strips @import in Common.css, so inject the link here */
(function(){
  var l=document.createElement('link'); l.rel='stylesheet';
  l.href='https://fonts.googleapis.com/css2?family=Anton&family=Libre+Franklin:wght@400;500;600;700;800;900&family=Spline+Sans+Mono:wght@400;500;600&display=swap';
  document.head.appendChild(l);
})();

(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;

    // If empty, do nothing
    var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim();
    if (!txt) return;

    siteNotice.classList.add('icelist-anon-donate');

    // 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 = 'ร—';
      siteNotice.insertBefore(btn, siteNotice.firstChild);

      btn.addEventListener('click', function (e) {
        e.preventDefault();
        siteNotice.style.display = 'none';
        localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
      });
    }
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', mount);
  } else {
    mount();
  }
})();

$(function () {
    var s = document.createElement('script');
    s.src = 'https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js';
    s.setAttribute('data-name', 'BMC-Widget');
    s.setAttribute('data-cfasync', 'false');
    s.setAttribute('data-id', 'crustnews');
    s.setAttribute('data-description', 'Support me on Buy me a coffee!');
    s.setAttribute('data-message', '');
    s.setAttribute('data-color', '#FF5F5F');
    s.setAttribute('data-position', 'Right');
    s.setAttribute('data-x_margin', '18');
    s.setAttribute('data-y_margin', '18');
    document.body.appendChild(s);
});
// Tag agent pages (any page showing an agent card) so the duplicate title/heading can be hidden
if ( document.querySelector( '.ic-agent-card' ) ) {
    document.body.classList.add( 'ic-agent-page' );
}

/* ---- Volunteer app loader (loads only on the 'Volunteer app' page) ---- */
if (/Volunteer_app$/.test(mw.config.get('wgPageName'))) {
  mw.loader.using(['mediawiki.util']).then(function () {
    window.ICELIST_EMBEDDED = true;
    window.ICELIST_API = mw.util.wikiScript('api');
    if (document.documentElement.classList.contains('skin-theme-clientpref-night'))
      document.documentElement.dataset.theme = 'dark';
    var base = mw.config.get('wgScript');
    mw.loader.load(base + '?title=MediaWiki:Volapp.css&action=raw&ctype=text/css&maxage=0&smaxage=0', 'text/css');
    mw.loader.load(base + '?title=MediaWiki:Volapp.js&action=raw&ctype=text/javascript&maxage=0&smaxage=0');
  });
}
/* ---- Volunteer portal: hide the login banner for logged-in users ---- */
if (/Volunteer_app$/.test(mw.config.get('wgPageName')) && !mw.user.isAnon()) {
  document.documentElement.classList.add('vol-loggedin');
}