User:Tollens/common.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Tollens (talk | contribs) at 09:42, 26 April 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$.when(mw.loader.using(["mediawiki.util"]), $.ready).done(function () {
    const currentPage = mw.config.get("wgPageName");
    const currentNamespace = mw.config.get("wgCanonicalNamespace");

    if (currentPage === "User:Tollens/common.js") {
        const toggleLink = document.createElement("a");
        toggleLink.href = "#";
        toggleLink.textContent = "Toggle dev mode";
        toggleLink.onclick = () => {
            localStorage.setItem(
                "TollensDevMode",
                localStorage.getItem("TollensDevMode") === "true" ? "false" : "true"
            );
            location.reload();
            return false;
        };

        const separator = document.createElement("span");
        separator.textContent = " – ";

        document.getElementById("firstHeading").appendChild(separator);
        document.getElementById("firstHeading").appendChild(toggleLink);
    }

    if (!currentPage.includes("/")) {
        if (currentNamespace === "User" || currentNamespace === "User_talk") {
            const fullAddition = document.createElement("span");
            const contribsLink = document.createElement("a");
            contribsLink.href =
                "https://en.wikipedia.org/wiki/Special:Contributions/" +
                currentPage.substring(currentPage.indexOf(":") + 1);
            contribsLink.textContent = "contribs";
            fullAddition.appendChild(document.createTextNode(" ("));
            fullAddition.appendChild(contribsLink);
            fullAddition.appendChild(document.createTextNode(")"));

            document.getElementById("firstHeading").appendChild(fullAddition);
        }
    }

    mw.util.addPortletLink(
        "p-personal",
        mw.util.getUrl("User:Tollens/Dashboard"),
        "Dashboard",
        "pt-dashboard",
        "View the dashboard",
        null,
        "#pt-preferences"
    );
    mw.util.addPortletLink(
        "p-personal",
        mw.util.getUrl("Special:ShortPages"),
        "Short Pages",
        "pt-shortpages",
        "View the list of short pages",
        null,
        "#pt-preferences"
    );
    mw.util.addPortletLink(
        "p-personal",
        mw.util.getUrl("Special:PendingChanges"),
        "Pending Changes",
        "pt-pendingchanges",
        "View the list of edits awaiting review",
        null,
        "#pt-preferences"
    );
});

if (localStorage.getItem("TollensDevMode") === "true") {
    const devModeWarningSpan = document.createElement("span");
    devModeWarningSpan.style.setProperty("color", "#ff0000", "important");
    devModeWarningSpan.textContent = "DEV MODE: ";
    document.getElementById("firstHeading").prepend(devModeWarningSpan);

    mw.loader.load("http://localhost:5500/Code/localFileToRead.js"); // Import the local dev file

    throw new Error("Dev mode is enabled."); // Prevent execution of external scripts, would be in an else block but then the script installer won't work and I'm too lazy to figure out a better way
}

importScript("User:Terasail/Edit Request Tool.js"); // Backlink: [[User:Terasail/Edit Request Tool.js]]
importScript("User:Enterprisey/cv-revdel.js"); // Backlink: [[User:Enterprisey/cv-revdel.js]]
importScript("User:Tollens/subnetContribs.js"); // Backlink: [[User:Tollens/subnetContribs.js]]
importScript("User:Fred_Gandt/confirmLogout.js"); // Backlink: [[User:Fred_Gandt/confirmLogout.js]]
importScript("User:Awesome Aasim/xfdvote.js"); // Backlink: [[User:Awesome Aasim/xfdvote.js]]
importScript("User:Tollens/watchUser.js"); // Backlink: [[User:Tollens/watchUser.js]]