MediaWiki:Common.js
From Polcompball Wiki
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. */
$('#discord-widget').html('<iframe src="https://discord.com/widget?id=1067108134319038494&theme=dark" width="270" height="570" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>');
/**
* @param {HTMLImageElement} img
*/
function fixBrokenImg(img) {
var pattern = /\/w\/thumb\.php\?f=([\w%\-]+)\.svg/gi;
var result = pattern.exec(img.src);
if (result) {
img.src = "/wiki/Special:FilePath/" + result[1] + ".svg";
}
}
function findBrokenImages() {
$('figure[typeof="mw:File/Thumb"]>a.mw-file-description>img').each(function (_index, elm) {
if (elm instanceof HTMLImageElement && (!elm.complete || elm.naturalWidth === 0)) {
fixBrokenImg(elm);
}
});
}
var windowLoaded = false;
window.addEventListener("load", function () {
if (!windowLoaded) {
windowLoaded = true;
findBrokenImages();
}
});
setTimeout(function () {
if (!windowLoaded) {
window.dispatchEvent(new Event("load"))
}
}, 1000);