User:Не кочан/global.js

nkch_css_configs = { saveWithCookies: true }

importArticles({   type: "script",    articles: [        'u:dev:MediaWiki:PortableCSSPad/code.js',        'u:nkch:MediaWiki:nkchCSS.js',        'u:dev:MediaWiki:PurgeButton/code.js',        'u:dev:MediaWiki:QuickDiff/code.js',        'u:nkch:MediaWiki:ProfileBanner.js',        'u:nkch:MediaWiki:WhatLeavesHere.js'        //'u:dev:MediaWiki:MultipleActivity.js'    ] });

mw.loader.using(["mediawiki.api", "mediawiki.util"]).then(   function  {        const api = new mw.Api;

mw.hook("dev.wds").add(           function (wds) {                var currentTheme = mw.user.options.get("theme");

const themeTogglerWrapper = document.createElement("div");

themeTogglerWrapper.classList.add("nkch-theme-toggler__wrapper");

mw.util.addCSS(".nkch-theme-toggler__wrapper { background: var(--theme-body-background-color); border: 1px solid var(--theme-body-text-color); border-radius: 15px; display: flex; height: 30px; justify-content: center; margin-right: 6px; position: relative; }");

const themeToggler = document.createElement("div");

themeToggler.classList.add("nkch-theme-toggler");

mw.util.addCSS(".nkch-theme-toggler { border-radius: 15px; display: flex; overflow: hidden; position: relative; z-index: 2; }");

const themeTogglerButton__dark = document.createElement("button"); themeTogglerButton__dark.classList.add("nkch-theme-toggler__button", "nkch-theme-toggler__button-dark");

const themeTogglerButtonIcon__dark = document.createElement("div"); themeTogglerButtonIcon__dark.classList.add("nkch-theme-toggler__button-icon", "nkch-theme-toggler__button-icon-dark");

mw.util.addCSS(".nkch-theme-toggler__button-dark { animation: anim-theme-toggler-slide-in--dark .5s ease; }"); mw.util.addCSS("@keyframes anim-theme-toggler-slide-in--dark { 0% { opacity: 0; transform: translateY(20px); } 60% { transform: translateY(-5px); } 100% { opacity: 1; transform: translateY(0); } }");

mw.util.addCSS(".nkch-theme-toggler__button-icon-dark { margin-left: -2px; }");

themeTogglerButtonIcon__dark.appendChild(wds.icon("moon-small"));

const themeTogglerButton__default = document.createElement("button"); themeTogglerButton__default.classList.add("nkch-theme-toggler__button", "nkch-theme-toggler__button-default");

mw.util.addCSS(".nkch-theme-toggler__button-default { animation: anim-theme-toggler-slide-in--default .5s ease; }"); mw.util.addCSS("@keyframes anim-theme-toggler-slide-in--default { 0% { opacity: 0; transform: translateY(20px); } 65% { transform: translateY(-5px); } 100% { opacity: 1; transform: translateY(0); } }");

const themeTogglerButtonIcon__default = document.createElement("div"); themeTogglerButtonIcon__default.classList.add("nkch-theme-toggler__button-icon", "nkch-theme-toggler__button-icon-default");

themeTogglerButtonIcon__default.appendChild(wds.icon("radio-empty-small"));

const themeTogglerButton__light = document.createElement("button"); themeTogglerButton__light.classList.add("nkch-theme-toggler__button", "nkch-theme-toggler__button-light");

const themeTogglerButtonIcon__light = document.createElement("div"); themeTogglerButtonIcon__light.classList.add("nkch-theme-toggler__button-icon", "nkch-theme-toggler__button-icon-light");

mw.util.addCSS(".nkch-theme-toggler__button-light { animation: anim-theme-toggler-slide-in--light .5s ease; }"); mw.util.addCSS("@keyframes anim-theme-toggler-slide-in--light { 0% { opacity: 0; transform: translateY(20px); } 70% { transform: translateY(-5px); } 100% { opacity: 1; transform: translateY(0); } }");

mw.util.addCSS(".nkch-theme-toggler__button-icon-light { margin-right: -2px; }");

themeTogglerButtonIcon__light.appendChild(wds.icon("sun-small"));

switch (currentTheme) { case "light": themeTogglerButton__light.classList.add("is-active"); break; case "dark": themeTogglerButton__dark.classList.add("is-active"); break; case "wiki": themeTogglerButton__default.classList.add("is-active"); break; }

function switchButton(button) { document.querySelectorAll(".nkch-theme-toggler > .nkch-theme-toggler__button").forEach(                       function (e) {                            e.classList.remove("is-active");                        }                    );

button.classList.add("is-active"); }

function changeTheme(theme) { if (theme === "light" && document.body.classList.contains("theme-fandomdesktop-dark")) { document.body.classList.remove("theme-fandomdesktop-dark"); document.body.classList.add("theme-fandomdesktop-light"); } else if (theme === "dark" && document.body.classList.contains("theme-fandomdesktop-light")) { document.body.classList.remove("theme-fandomdesktop-light"); document.body.classList.add("theme-fandomdesktop-dark"); }

if (theme !== "wiki" && (theme === "light" || theme === "dark")) { $.ajax({                           method: "GET",                            url: mw.util.wikiScript("wikia"),                            data: {                                controller: "ThemeApi",                                method: "themeVariables",                                variant: theme                            }                        }).done(                            function (data) {                                mw.util.addCSS(data);

api.postWithToken('csrf', {                                   action: "options",                                    optionname: "theme",                                    optionvalue: theme                                }); }                       );                    } else {                        api.postWithToken('csrf', { action: "options", optionname: "theme", optionvalue: theme });                   }                }

themeTogglerButton__dark.addEventListener("click", function {                    switchButton(themeTogglerButton__dark);                    changeTheme("dark");                });

themeTogglerButton__default.addEventListener("click", function {                    switchButton(themeTogglerButton__default);                    changeTheme("wiki");                });

themeTogglerButton__light.addEventListener("click", function {                    switchButton(themeTogglerButton__light);                    changeTheme("light");                });

const themeTogglerPointerWrapper = document.createElement("div"); themeTogglerPointerWrapper.classList.add("nkch-theme-toggler__pointer-wrapper");

if (themeTogglerButton__dark.classList.contains("is-active")) { themeTogglerPointerWrapper.style.marginLeft = "-61px"; }

if (themeTogglerButton__light.classList.contains("is-active")) { themeTogglerPointerWrapper.style.marginRight = "-61px"; }

mw.util.addCSS(".nkch-theme-toggler__pointer-wrapper { align-items: center; animation: anim-theme-toggler-jump-in .5s ease; display: flex; height: 28px; justify-content: center; position: absolute; top: 0; transition: .3s; width: 30px; z-index: 1; will-change: transform, z-index ;}"); mw.util.addCSS("@keyframes anim-theme-toggler-jump-in { 0% { transform: translateY(0); z-index: -1; } 40% { transform: translateY(-30px); z-index: -1; } 50% { transform: translateY(-30px); z-index: 1; } 90% { transform: translateY(2px); z-index: 1; } 100% { transform: translateY(0); z-index: 1; } }");

const themeTogglerPointer = document.createElement("div"); themeTogglerPointer.classList.add("nkch-theme-toggler__pointer");

mw.util.addCSS(".nkch-theme-toggler__pointer { background: var(--theme-body-text-color); border-radius: 15px; height: 26px; margin: 1px; width: 26px; }");

mw.util.addCSS(".nkch-theme-toggler__button { align-items: center; background: none; border: none; cursor: pointer; display: flex; height: 28px; justify-content: center; width: 30px; z-index: 2; }"); mw.util.addCSS(".nkch-theme-toggler__button-icon { color: currentColor; height: 18px; width: 18px; }"); mw.util.addCSS(".nkch-theme-toggler__button-icon .wds-icon-small { fill: var(--theme-body-text-color); transition: .5s; }"); mw.util.addCSS(".nkch-theme-toggler__button.is-active .wds-icon-small { fill: var(--theme-body-background-color); transition: .7s; }");

function checkIfActive { if (themeTogglerButton__default.classList.contains("is-active")) { themeTogglerPointerWrapper.style.marginLeft = null; themeTogglerPointerWrapper.style.marginRight = null; } else if (themeTogglerButton__dark.classList.contains("is-active")) { themeTogglerPointerWrapper.style.marginLeft = "-61px"; themeTogglerPointerWrapper.style.marginRight = null; } else if (themeTogglerButton__light.classList.contains("is-active")) { themeTogglerPointerWrapper.style.marginLeft = null; themeTogglerPointerWrapper.style.marginRight = "-61px"; }               }

setInterval(checkIfActive, 100);

document.querySelector(".page-counter").after(themeTogglerWrapper);

themeTogglerWrapper.appendChild(themeToggler);

themeToggler.appendChild(themeTogglerButton__dark); themeTogglerButton__dark.appendChild(themeTogglerButtonIcon__dark); themeToggler.appendChild(themeTogglerButton__default); themeTogglerButton__default.appendChild(themeTogglerButtonIcon__default); themeToggler.appendChild(themeTogglerButton__light); themeTogglerButton__light.appendChild(themeTogglerButtonIcon__light);

themeTogglerWrapper.appendChild(themeTogglerPointerWrapper); themeTogglerPointerWrapper.appendChild(themeTogglerPointer); }       )

importArticle({           type: "script",            article: "u:dev:MediaWiki:WDSIcons/code.js"        }); } );

window.nkch_navLinks = [{ link: "ru.community", title: "Вики Сообщества" }, {   link: "community", title: "Community Central" }, {   link: "ru.wikies", title: "Викии Вики" }, {   link: "ru.dayr", title: "Day R Wiki" }, {   link: "ru.rabi-ribi", title: "Rabi-Ribi вики" }, {   link: "ru.nkch", title: "Не вики" }];

if (typeof window.nkch_navLinks !== "undefined" && Array.isArray(window.nkch_navLinks)) { mw.loader.using(["mediawiki.api", "oojs-ui"]).then(       function  {            const api = new mw.Api;            var originalLinks = document.querySelectorAll(".global-navigation__link:not(.start-a-wiki):not(div)");

originalLinks.forEach(               function (el) {                    el.remove;                }            );

var navLinksWrapper = document.createElement("div");

navLinksWrapper.classList.add("navLinksWrapper")

Object.assign(navLinksWrapper.style, {               width: "100%",                overflowY: "auto",                maxHeight: "500px"            });

if (skin == "fandomdesktop") { document.querySelector(".global-navigation__search.global-navigation__icon").after(navLinksWrapper); };

for (var i in window.nkch_navLinks) { if (typeof window.nkch_navLinks[i].link !== "undefined") { var link = window.nkch_navLinks[i].link.split(".");

var l;                   if (link.length === 1) { l = "https://" + link[0] + ".fandom.com"; } else if (link.length === 2) { l = "https://" + link[1] + ".fandom.com/" + link[0]; };

var favicon = l + "/wiki/Special:Filepath/Site-favicon.ico";

var linkWrapper = document.createElement("a"); linkWrapper.classList.add("global-navigation__link", "navLink");

linkWrapper.href = l;

linkTooltip = document.createElement("div"); linkTooltip.classList.add("wds-tooltip", "is-right");

linkTooltip.style.transform = "translate(65px, -30px)";

if (typeof window.nkch_navLinks[i].title !== "undefined") { linkTooltip.innerHTML = window.nkch_navLinks[i].title; } else { linkTooltip.innerHTML = "[ " + window.nkch_navLinks[i].link + " ]"; };

var linkIcon = document.createElement("span"); linkIcon.classList.add("global-navigation__icon", "has-background");

var linkIconSrc = document.createElement("img");

linkIconSrc.src = favicon; linkIconSrc.setAttribute("width", "16px");

navLinksWrapper.appendChild(linkWrapper); linkWrapper.appendChild(linkIcon); linkWrapper.after(linkTooltip); linkIcon.appendChild(linkIconSrc); }           };

mw.util.addCSS(".navLink + .wds-tooltip { display: none; }"); mw.util.addCSS(".navLink:hover + .wds-tooltip { display: inline-block; }"); mw.util.addCSS(".global-navigation__link { margin-top: 10px; }"); mw.util.addCSS(".global-navigation__link:first-child { margin-top: 0; }"); mw.util.addCSS(".global-navigation__link:nth-of-type(3) { margin-top: 10px; }"); }   ); }

mw.loader.using(["mediawiki.api", "mediawiki.cookie"]).then(   function  {        function checkCookie(cookie, prefix) {            var result;            var c = mw.cookie.get(cookie, prefix);            if (c === null || c === "false") {                result = false;            } else if (c === "true") {                result = true;            }

return result; }

const toolbarButtonWrapper = document.createElement("li"); document.querySelector("#WikiaBar .toolbar .tools").appendChild(toolbarButtonWrapper);

const toolbarButton = document.createElement("a"); toolbarButtonWrapper.appendChild(toolbarButton);

Object.assign(toolbarButton.style, {           display: "flex",            alignItems: "center"        });

const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg"); icon.setAttributeNS(null, "viewBox", "0 0 18 18");

icon.classList.add("wds-icon", "wds-icon-small");

Object.assign(icon.style, {           background: "white",            borderRadius: "3px",            cursor: "pointer",            padding: "2px"        });

switch (checkCookie("openLinksInEditMode", "nkch_")) { case true: icon.style.fill = "var(--theme-success-color)"; break; case false: icon.style.fill = "var(--theme-alert-color)"; break; }

toolbarButton.appendChild(icon);

const iconSrc = document.createElementNS("http://www.w3.org/2000/svg", "use"); iconSrc.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "#wds-icons-external-small"); icon.appendChild(iconSrc);

toolbarButton.addEventListener("click", function {            switch (checkCookie("openLinksInEditMode", "nkch_")) {                case true:                    mw.cookie.set("openLinksInEditMode", "false", { prefix: "nkch_", });                   icon.style.fill = "var(--theme-alert-color)";                    break;                case false:                    mw.cookie.set("openLinksInEditMode", "true", { prefix: "nkch_", });                   icon.style.fill = "var(--theme-success-color)";                    break;            }        });

document.querySelectorAll("#content a:not(.extiw):not(.external):not([href*='?action']):not([href*='" + encodeURI(mw.config.get("wgFormattedNamespaces")[-1]) + ":'])").forEach(           function (link) {                if (link.href.indexOf(location.protocol + "//" + location.hostname) === 0) {                    const linkHref = link.getAttribute("href");

link.addEventListener("mouseover", function (event) {                       setInterval(checkKey(event), 100);                    })

link.addEventListener("mouseout", function (event) {                       link.setAttribute("href", linkHref);                    })

function checkKey(e) { if (checkCookie("openLinksInEditMode", "nkch_") === true) { if (e.ctrlKey) { link.setAttribute("href", linkHref + "?action=edit"); } else { link.setAttribute("href", linkHref); }                       }                    };                };            }        );    } );

if (mw.config.get("wgCanonicalSpecialPageName") === "Newimages") { mw.loader.using(["mediawiki.api", "mediawiki.util"]).then(       function  {            const api = new mw.Api;

const files = document.querySelectorAll(".wikia-gallery-item .lightbox"); const fileCaptions = document.querySelectorAll(".wikia-gallery-item .lightbox-caption");

var fileNames = [];

for (var f = 0; i < usage.length; i++) { fileNames.push(usage[f].href.split("/wiki/")[1]); }

for (let i = 0; i < fileCaptions.length; i++) { api.get({                   action: "query",                    titles: decodeURI(fileNames[i]),                    prop: "fileusage",                    format: "json"                }).done(                    function (data) {                        var fileUsage = document.createElement("div");                        var usage = data.query.pagesObject.keys(data.query.pages)[0].fileusage;

if (typeof usage !== "undefined") { var usageText = document.createElement("span"); usageText.innerHTML = "Используется в: ";

usageText.style.fontSize = "14px";

for (var p = 0; i < usage.length; i++) { var usageLinkWrapper = document.createElement("span");

usageLinkWrapper.classList.add("file-used-in");

mw.util.addCSS(".file-used-in:not(:first-child):before { content: ', ' }");

var usageLink = document.createElement("a");

usageLink.href = mw.util.getUrl(usage[p].title); usageLink.innerHTML = usage[p].title;

usageText.appendChild(usageLinkWrapper);

usageLinkWrapper.appendChild(usageLink); }

fileUsage.appendChild(usageText);

fileCaptions[i].after(fileUsage); }                   }                );            }        }    ); }