MediaWiki:DisableCode/code.js

/** * @name:          DisableCode * @description:   Allows users to disable personal/site-wide JS/CSS for testing purposes * @author:        Count of Howard  * @date:          25/03/17 * @notes:         Designed for the Oasis skin; Monobook support may eventually be added */

/*jslint browser*/ /*global window, jQuery, mediaWiki*/

(function ($, mw) {   "use strict";

var config = mw.config.get([       "skin",        "wgPageName",        "wgArticlePath",        "wgUserLanguage"    ]);

if (       $("#disablecode").length ||        $.inArray(config.skin, ["monobook", "uncyclopedia", "wowwiki"]) !== -1    ) { return; }

var i18n = { "en": { title: "DisableCode", reset: "Reset", userJS: "Disable User JS", userCSS: "Disable User CSS", siteJS: "Disable Wiki JS", siteCSS: "Disable Wiki CSS" }       },        parameters = { userJS: "useuserjs", userCSS: "useusercss", siteJS: "usesitejs", siteCSS: "usesitecss" },       lang = i18n[config.wgUserLanguage] || i18n[config.wgUserLanguage.split("-")[0]] || i18n.en;

function assembleLink(text, p) { var href, search = (window.location.search) ? "&" : "?";

if (text === lang.reset) { href = config.wgArticlePath.replace("$1", config.wgPageName); } else { href = window.location.href.replace(/#.*/, "") + search + p + "=" + 0; }

return mw.html.element("li", {           class: "overflow"        }, new mw.html.Raw( mw.html.element("a", {               href: href,                title: text,                id: p            }, text) ));   }

function init { var $userJS = assembleLink(lang.userJS, parameters.userJS), $userCSS = assembleLink(lang.userCSS, parameters.userCSS), $siteJS = assembleLink(lang.siteJS, parameters.siteJS), $siteCSS = assembleLink(lang.siteCSS, parameters.siteCSS), $reset = assembleLink(lang.reset, "reset-parameters");

mw.util.addCSS(           "#disablecode-menu {" +                "left: 10px;" +                "right: auto;" +                "display: none;" +            "}"        );

$("", {           class: "mytools menu",            id: "disablecode"        }).html(            " " +                " " +            " " +            "" +                lang.title +            "" +            ""        ).prependTo(".toolbar .tools");

$("#disablecode-menu").append(           $reset,            $userJS,            $userCSS,            $siteJS,            $siteCSS        );

$("#disablecode").click(           function  {                $("#disablecode-menu").slideToggle("fast");            }        ); }

init; }(jQuery, mediaWiki));