User:CannonProductions/monacobookbeta.js
From MediaWiki
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.
(() => {
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();
})();

