MediaWiki:Common.js

MediaWiki interface page
Revision as of 14:34, 20 February 2023 by Andy (talk | contribs)

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)
  • 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. */


(function () {
    const libQR = document.createElement("script");
    libQR.addEventListener("load", function () {
    	const dark = document.documentElement.classList.contains("skin-citizen-dark");
    	
        QRCode.toDataURL(location.href).then(function (url) {
            const img = document.createElement("img");
            img.title = "QR code for this page";
            img.src = url;

			const label = document.createElement("div");
			label.className = "page-info__label";
			label.textContent = "QR code for this page";
			
			const wrapper = document.createElement("div");
			wrapper.className = "page-info__text";
			wrapper.appendChild(img);

			const section = document.createElement("section");
			section.className = "page-info__item";
			section.append(label, wrapper);

            const footer = document.querySelector(".mw-body-footer > .page-info");
            footer.appendChild(section);
        }).catch(console.error);        
    });
    libQR.src = "https://cdn.jsdelivr.net/npm/qrcode@1.4.4/build/qrcode.min.js";
    document.body.appendChild(libQR);
})();