User:CannonProductions/monacobookbeta.js

From MediaWiki
Revision as of 11:27, 30 December 2025 by CannonProductions (talk | contribs)
Jump to navigationJump to search

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.
document.body.insertAdjacentHTML(
  "afterbegin",
  '<div id="js-test-badge" style="position:fixed;top:0;left:0;z-index:999999;padding:6px 10px;background:#e11;color:#fff;font:12px sans-serif">User JS RUNNING</div>'
);

(() => {
  const BASE_W = 468;
  const BASE_H = 60;

  function rescaleBanner() {
    const ad = document.getElementById("top-ad");
    if (!ad) return;

    const iframe = ad.querySelector("iframe");
    if (!iframe) return;

    const available = ad.getBoundingClientRect().width || window.innerWidth;

    let scale = available / BASE_W;
    if (scale > 1) scale = 1;       // don’t upscale past 100%
    if (scale < 0.5) scale = 0.5;   // safety floor for tiny widths

    document.documentElement.style.setProperty("--tfwiki-banner-scale", scale.toFixed(4));

    // Make layout height match the scaled visual height
    ad.style.height = (BASE_H * scale) + "px";
  }

  // Run now + on resize (debounced)
  let t;
  function onResize() {
    clearTimeout(t);
    t = setTimeout(rescaleBanner, 50);
  }

  window.addEventListener("load", rescaleBanner, { once: true });
  window.addEventListener("resize", onResize);
  window.addEventListener("orientationchange", onResize);

  rescaleBanner();
})();