MediaWiki:Common.js: Difference between revisions

From Polcompball Wiki
Jump to navigationJump to search
Content added Content deleted
No edit summary
No edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


$( '#discord-widget' ).html( '<iframe src="https://discord.com/widget?id=855837257729835038&theme=dark" width="270" height="570" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>' );
$('#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>');


/**
function addMsgBox() {
* @param {HTMLImageElement} img
var dismissed = localStorage.getItem("dismissed-pcb-msgbox-1");
*/

function fixBrokenImg(img) {
if (dismissed === "true") {
var pattern = /\/w\/thumb\.php\?f=([\w%\-]+)\.svg/gi;
return;
var result = pattern.exec(img.src);
if (result) {
img.src = "/wiki/Special:FilePath/" + result[1] + ".svg";
}
}
}


function findBrokenImages() {
/**@typedef {import("types-mediawiki")}*/
$('figure[typeof="mw:File/Thumb"]>a.mw-file-description>img').each(function (_index, elm) {
var mw = mw || window.mw;
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 currentPage = new mw.Title(mw.config.get("wgPageName"));
var ns = currentPage.namespace;


var windowLoaded = false;
if (ns === 0 || ns === 2 || ns === 200) {
var top = $("#top");


window.addEventListener("load", function () {
if (top.children().length) return;
if (!windowLoaded) {

windowLoaded = true;
top.html('<div id="top" style="background: #1d2021;font-weight: bold;color: white;border: 2px solid #08265c;border-radius: 4px;padding: 2%;font-size: 16px;height: 140px;display: inline-block;width: 96%;"><div><img alt="Council-Communism-Chara-Portrait-Server Profile Picture.png" src="//static.miraheze.org/polcompballwiki/thumb/d/d8/Council-Communism-Chara-Portrait-Server_Profile_Picture.png/200px-Council-Communism-Chara-Portrait-Server_Profile_Picture.png" decoding="async" srcset="//static.miraheze.org/polcompballwiki/thumb/d/d8/Council-Communism-Chara-Portrait-Server_Profile_Picture.png/300px-Council-Communism-Chara-Portrait-Server_Profile_Picture.png 1.5x, //static.miraheze.org/polcompballwiki/thumb/d/d8/Council-Communism-Chara-Portrait-Server_Profile_Picture.png/400px-Council-Communism-Chara-Portrait-Server_Profile_Picture.png 2x" data-file-height="400" data-file-width="400" width="100px" height="100%"><div style="width: 90%;margin-left: 100px;margin-top: -100px;"><div style="font-size: 20px;color: #d40000;">On the 28th of October 2023, we will be migrating to <a href="https://polcompball.wikitide.org/wiki/Main_Page">WikiTide</a>. On the day of migration all the main namespace pages will be locked and transferred to the new platform, any changes made to other pages after this point will not be transferred to the new platform. You will be able to continue editing the pages on WikiTide when the migration is completed.</div><div style="margin-top: 10px;color: #d2d2d2;"><a href="https://polcompball.miraheze.org/wiki/Blog:Announcement_(2023;Week_42)">Full mod announcement</a></div></div></div><div style="width: 2%;margin-left: 99.9%;margin-top: -70px;"><button id="close_top" style="border: 0px;padding: 0px;width: 2%;background: #1d2021;color: #d2d2d2; cursor: pointer;">X</button></div><div>');
findBrokenImages();

$("#close_top").on("click", function () {
localStorage.setItem("dismissed-pcb-msgbox-1", "true");
$("#top").html("");
});
}
}
}

window.addEventListener("load", function () {
addMsgBox();
});
});




setTimeout(function () {
setTimeout(function () {
if (!windowLoaded) {
var ev = new Event("load");
window.dispatchEvent(ev);
window.dispatchEvent(new Event("load"))
}
}, 1000);
}, 1000);

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);