MediaWiki:Common.js: Difference between revisions

From Polcompball Wiki
Jump to navigationJump to search
Content added Content deleted
No edit summary
No edit summary
 
Line 16: Line 16:
function findBrokenImages() {
function findBrokenImages() {
$('figure[typeof="mw:File/Thumb"]>a.mw-file-description>img').each(function (_index, elm) {
$('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);
}
});
$("div.fullImageLink a img").each(function (_index, elm) {
if (elm instanceof HTMLImageElement && (!elm.complete || elm.naturalWidth === 0)) {
if (elm instanceof HTMLImageElement && (!elm.complete || elm.naturalWidth === 0)) {
fixBrokenImg(elm);
fixBrokenImg(elm);
Line 21: Line 26:
});
});
}
}



var windowLoaded = false;
var windowLoaded = false;

Latest revision as of 22:52, 20 January 2024

/* 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);
        }
    });
    $("div.fullImageLink a 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);