MediaWiki:Common.js: Difference between revisions

From ICE List Wiki
Jump to navigation Jump to search
Created page with "Any JavaScript here will be loaded for all users on every page load.: var d=document,w="https://tally.so/widgets/embed.js", v=function(){ if (typeof Tally !== "undefined") { Tally.loadEmbeds(); } else { d.querySelectorAll("iframe[data-tally-src]:not([src])").forEach(function(e){ e.src=e.dataset.tallySrc; }); } }; if (typeof Tally !== "undefined") { v(); } else if (d.querySelector('script[src="'+w+'"]') == null) {..."
 
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
var d=document,w="https://tally.so/widgets/embed.js",
  'use strict';
v=function(){
 
     if (typeof Tally !== "undefined") {
  var KEY = 'icelist_anon_donate_dismiss_until';
        Tally.loadEmbeds();
  var DAYS = 14;
     } else {
 
        d.querySelectorAll("iframe[data-tally-src]:not([src])").forEach(function(e){
  if (!mw.user.isAnon()) return;
            e.src=e.dataset.tallySrc;
 
        });
  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 (typeof Tally !== "undefined") {
 
     v();
  if (document.readyState === 'loading') {
} else if (d.querySelector('script[src="'+w+'"]') == null) {
     document.addEventListener('DOMContentLoaded', mount);
     var s=d.createElement("script");
  } else {
    s.src=w;
     mount();
    s.onload=v;
  }
    s.onerror=v;
})();
    d.body.appendChild(s);
}

Latest revision as of 22:13, 20 December 2025

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