User:CannonProductions/monacobookbeta.js: Difference between revisions

From MediaWiki
Jump to navigationJump to search
Created page with "(() => { const BASE_W = 468; const BASE_H = 60; function rescaleBanner() { const ad = document.getElementById("top-ad"); if (!ad) return; const iframe = ad..."
 
No edit summary
Line 1: Line 1:
alert("TFWiki custom JS is running");
(() => {
(() => {
   const BASE_W = 468;
   const BASE_W = 468;

Revision as of 11:23, 30 December 2025

alert("TFWiki custom JS is running");

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