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    }; /* 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];    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) return {wiki: "dark"};            return {wiki: "light"};        }); }).then(function (themes) { 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"; return themes; });       });    }).then(function (themes) { var use_theme = mw.util.getParamValue("usetheme"); if ((use_theme !== "wiki") && (use_theme !== "light")           && (use_theme !== "dark")) use_theme = themes.user; if (use_theme === "wiki") { css_link.href = css_link.href.replace(param_regex, function (m, p1, p2) {               if (p2 === "&") {                    if (p1 === "?") return "?";                    return "&";                }                return "";            }); use_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=" + use_theme + p2;            }); } else { css_link.href = css_link.href + "&variant=" + use_theme; }       if (use_theme === "dark") { document.body.classList.remove("theme-fandomdesktop-light"); } else { document.body.classList.remove("theme-fandomdesktop-dark"); }       document.body.classList.add("theme-fandomdesktop-" + use_theme); }); });