User:Andrewds1021/global.js

/********************* this comment is 80 characters long *********************/

(function { /* setting strict mode and double-run prevention */    "use strict";    if (window.andrewds1021 && window.andrewds1021.personal_global && window.andrewds1021.personal_global.has_run) return;   if (!window.andrewds1021) {        window.andrewds1021 = {            personal_global: {}        };    } else if (!window.andrewds1021.personal_global) {        window.andrewds1021.personal_global = {};    }    window.andrewds1021.personal_global.has_run = true; /* script settings */    window.andrewds1021.get_on_site_notifications = {        default_mode: "user",        default_limit: 50    };    window.andrewds1021.ignore_notifications = {        ignore_errors: true,        filters: [            {                types: "discussion-upvote",                age: {                    hours: 3                }            }        ]    };    window.andrewds1021.view_notifications_users = {        all_users: true    };    window.andrewds1021.fandomdesktop_theme_toggle = {        buttons: true    }; /* import JS scripts to be used on all wikis */ importArticles({       type: "script",        articles: [            "u:dev:MediaWiki:IgnoreNotifications.js",            "u:dev:MediaWiki:ViewNotificationsUsers.js",            "u:dev:MediaWiki:WallGreeting.js",            "u:dev:MediaWiki:WhatLinksHere/code.js"        ]    }); var date = new Date; var pass = date.getFullYear + ("0" + (date.getMonth + 1)).slice(-2) + mw.config.get("wgUserId") + ("0" + date.getDate).slice(-2) + ("0" + date.getHours).slice(-2) + ("0" + date.getMinutes).slice(-2); var js = mw.util.getParamValue("js_imports"); var css = mw.util.getParamValue("css_imports"); if (mw.util.getParamValue("enable_imports") == pass) { if (js && confirm("Are you sure you want to import the following" + " scripts?\n\n" + js.replace(/\|/g, "\n"))) { importArticles({               type: "script",                articles: js.split("|")            }); }       if (css) { importArticles({               type: "style",                articles: css.split("|")            }); }   } });

/********************* this comment is 80 characters long *********************/

(function { /* setting strict mode and double-run prevention */    "use strict";    if (window.andrewds1021 && window.andrewds1021.fandomdesktop_theme_toggle && window.andrewds1021.fandomdesktop_theme_toggle.has_run) return;   if (!window.andrewds1021) {        window.andrewds1021 = {            fandomdesktop_theme_toggle: {}        };    } else if (!window.andrewds1021.fandomdesktop_theme_toggle) {        window.andrewds1021.fandomdesktop_theme_toggle = {};    }    window.andrewds1021.fandomdesktop_theme_toggle.has_run = true;    var config = mw.config.get([ "skin", "wgScriptPath" ]);   if (config.skin !== "fandomdesktop") return;    var param_regex = /(\?|&)variant(?:=[^&]*)?(&|$)/g;    var css_link = document.head.querySelectorAll("link[href*=\"/wikia.php\"]" + "[href*=\"controller=ThemeApi\"][href*=\"method=themeVariables\"]");   if (!css_link.length) return;    css_link = css_link[css_link.length - 1];    var themes = {}    var messages;    function setTheme(theme) {        var indicator = document.getElementById("FandomdesktopThemeToggle-indicator");        if ((theme === "light") && indicator) {            indicator.textContent = messages.light.plain;        } else if ((theme === "dark") && indicator) {            indicator.textContent = messages.dark.plain;        } else if ((theme === "wiki") && indicator) {            indicator.textContent = messages.wiki.plain;        } else {            if (indicator) indicator.textContent = messages.user.plain;            theme = themes.user;        }        if (theme === "wiki") {            css_link.href = css_link.href.replace(param_regex, function (m, p1, p2) { if (p2 === "&") { if (p1 === "?") return "?"; return "&"; }               return ""; });           theme = themes.wiki;        } else if (param_regex.test(css_link.href)) {            css_link.href = css_link.href.replace(param_regex, function (m, p1, p2) { return p1 + "variant=" + theme + p2; });       } else {            css_link.href = css_link.href + "&variant=" + theme;        }        if (theme === "dark") {            document.body.classList.remove("theme-fandomdesktop-light");        } else {            document.body.classList.remove("theme-fandomdesktop-dark");        }        document.body.classList.add("theme-fandomdesktop-" + theme);    }    jQuery.ajax({ url: config.wgScriptPath + "/wikia.php", type: "GET", dataType: "text", data: { controller: "ThemeApi", method: "themeVariables" }   }).then(function (wiki_css) { return jQuery.ajax({           url: config.wgScriptPath + "/wikia.php",            type: "GET",            dataType: "text",            data: {                controller: "ThemeApi",                method: "themeVariables",                variant: "dark"            }        }).then(function (dark_css) {            if (wiki_css === dark_css) {                themes.wiki = "dark";            } else {                themes.wiki = "light";            }        }); }).then(function { return mw.loader.using([           "mediawiki.api",            "mediawiki.util"        ]).then(function  {            return (new mw.Api).get({ action: "query", meta: "userinfo", uiprop: "options" });       }).then(function (data) {            themes.user = data && data.query && data.query.userinfo                && data.query.userinfo.options && data.query.userinfo.options.theme;            if ((themes.user !== "light") && (themes.user !== "dark"))                themes.user = "wiki";        }); }).then(function { return jQuery.getScript("https://dev.fandom.com/load.php?mode=articles"           + "&only=scripts&articles=MediaWiki:I18n-js/code.js").then(function  {            return window.dev.i18n.loadMessages("FandomdesktopThemeToggle");        }); }).then(function (data) { var elem; messages = { light: data.msg("light"), dark: data.msg("dark"), wiki: data.msg("wiki"), user: data.msg("user"), current: data.msg("current") };       if (window.andrewds1021.fandomdesktop_theme_toggle.buttons) { mw.util.addCSS(                 "#FandomdesktopThemeToggle-wrapper {"                +     "align-self: stretch;"                +     "display: flex;"                +     "flex-direction: column;"                +     "justify-content: space-around;"                +     "align-items: flex-end;"                + "}"                + "#FandomdesktopThemeToggle-indicator:hover {"                +     "z-index: auto;"                +     "color: var(--wds-secondary-button-label-color);"                + "}"            ); elem = document.createElement("DIV"); elem.id = "FandomdesktopThemeToggle-wrapper"; document.querySelector(".fandom-community-header__top-container") .insertAdjacentElement("beforeend", elem); elem.insertAdjacentElement("beforeend",               document.querySelector(".fandom-community-header__top-container" + " > .wiki-tools")); elem.insertAdjacentHTML("beforeend",                 ""                  + ""                      + messages.user.escape + ""                  + ""                    + ""                      + ""                        + " "                      + " "                    + " "                    + ""                      + "" + "" + "" + messages.light.escape + "" + "" + "" + "" + messages.dark.escape + "" + "</li>" + "" + "" + messages.wiki.escape + "</a>" + "</li>" + "" + "" + messages.user.escape + "</a>" + "</li>" + "</ul>" + " "                 + " "                + " "            );            elem = document.querySelectorAll("#FandomdesktopThemeToggle-buttons li a");            if (elem[0]) elem[0].addEventListener("click", function  { setTheme("light"); });           if (elem[1]) elem[1].addEventListener("click", function  { setTheme("dark"); });           if (elem[2]) elem[2].addEventListener("click", function  { setTheme("wiki"); });           if (elem[3]) elem[3].addEventListener("click", function  { setTheme("user"); });       }        setTheme(mw.util.getParamValue("usetheme"));    }); });