MediaWiki:Common.js
Revision as of 15:53, 14 August 2025 by Thearchivist (talk | contribs) (Created page with "→Any JavaScript here will be loaded for all users on every page load.: →=== AdSense global loader (loads once) ===: (function() { var PUBLISHER_ID = "pub-63493907827...")
Note: After saving, 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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* === AdSense global loader (loads once) === */
(function() {
var PUBLISHER_ID = "pub-6349390782750569"; // <-- replace
if (!window._adsenseLoaded) {
window._adsenseLoaded = true;
// Load the AdSense library
var s = document.createElement('script');
s.async = true;
s.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=" + encodeURIComponent(PUBLISHER_ID);
s.crossOrigin = "anonymous";
document.head.appendChild(s);
}
// Utility: create a responsive ad block
window.createAdsenseBlock = function(slotId) {
var cont = document.createElement('div');
cont.style.margin = "12px 0";
var ins = document.createElement('ins');
ins.className = "adsbygoogle";
ins.style.display = "block";
ins.style.textAlign = "center";
ins.setAttribute("data-ad-client", PUBLISHER_ID);
ins.setAttribute("data-ad-slot", slotId); // <-- pass the slot ID
ins.setAttribute("data-ad-format", "auto");
ins.setAttribute("data-full-width-responsive", "true");
cont.appendChild(ins);
// Kick AdSense to render
(window.adsbygoogle = window.adsbygoogle || []).push({});
return cont;
};
})();