User:NewAqua/global.js

importArticles({	type: "script",	articles: [		'u:dev:MediaWiki:AjaxBatchDelete.js',		'u:dev:MediaWiki:GlobalNavButtons.js',		'u:dev:MediaWiki:MassEdit/code.js',		'u:dev:MediaWiki:MultipleActivity.js',		'u:dev:MediaWiki:PurgeButton/code.js',		'u:dev:MediaWiki:QuickDiff/code.js',		'u:dev:MediaWiki:ThemeToggler.js',		"u:nkch:MediaWiki:nkchCSS.js"	] });

//nkch's GlobalNavButtons window.nkch_navLinks = [{ link: "ru.community", title: "Вики Сообщества" }, {   link: "community", title: "Community Central" }, {   link: "ru.slimerancher", title: "Slime Rancher вики" }, {   link: "ru.spiralka", 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-left");

linkTooltip.style.margin = "-18px 0 0 -9px"; linkTooltip.style.width = "max-content";

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("div"); linkIcon.classList.add("global-navigation__link-icon");

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 a:nth-of-type(3) { margin-top: 18px; }") }   ); }

// nkchCSS nkch_css_configs = { theme: "rubyblue", title: "Не кочан, ксс" }

$(document).ready(   mw.loader.using(["mediawiki.util", "oojs-ui"]).then( function { const versions = { nkchCSS: "1.2.0", codeMirror: "5.62.0", jQueryUI: "1.12.1", colorPicker: "1.9.72" }

var options = { hideInfo: false, theme: "default", title: "nkchCSS", useCookies: false }

mw.hook("dev.wds").add(               function (wds) {                    if (typeof nkch_css_configs !== "undefined") {                        if (typeof nkch_css_configs.hideInfo !== "undefined") {                            options.hideInfo = nkch_css_configs.hideInfo;                        }

if (typeof nkch_css_configs.theme !== "undefined") { options.theme = nkch_css_configs.theme; }

if (typeof nkch_css_configs.title !== "undefined") { options.title = nkch_css_configs.title; }

if (typeof nkch_css_configs.useCookies !== "undefined") { options.useCookies = nkch_css_configs.useCookies; }                   }

const nkchCSS_style = document.createElement("style"); document.head.appendChild(nkchCSS_style);

Promise.all([                       mw.loader.load("https://ajax.googleapis.com/ajax/libs/jqueryui/" + versions.jQueryUI + "/jquery-ui.css", "text/css"),                        mw.loader.load("https://cdnjs.cloudflare.com/ajax/libs/codemirror/" + versions.codeMirror + "/codemirror.css", "text/css"),                        mw.loader.load("https://cdn.jsdelivr.net/npm/codemirror-colorpicker@" + versions.colorPicker + "/dist/codemirror-colorpicker.css", "text/css")                    ]).then(                        function  {                            if (options.theme !== "default") {                                mw.loader.load("https://cdnjs.cloudflare.com/ajax/libs/codemirror/" + versions.codeMirror + "/theme/" + options.theme + ".css", "text/css")                            }                        }                    ).then(                        function  { $.when(                               mw.loader.getScript("https://ajax.googleapis.com/ajax/libs/jqueryui/" + versions.jQueryUI + "/jquery-ui.js"),

mw.loader.getScript("https://cdnjs.cloudflare.com/ajax/libs/codemirror/" + versions.codeMirror + "/codemirror.js"), mw.loader.getScript("https://cdnjs.cloudflare.com/ajax/libs/codemirror/" + versions.codeMirror + "/mode/css/css.js"),

mw.loader.getScript("https://cdnjs.cloudflare.com/ajax/libs/codemirror/" + versions.codeMirror + "/addon/edit/closebrackets.js"), mw.loader.getScript("https://cdn.jsdelivr.net/npm/codemirror-colorpicker@" + versions.colorPicker + "/dist/codemirror-colorpicker.js") ).done( function { var nkch_IsDisabled = false;

var nkchCSS = document.createElement("div"); nkchCSS.classList.add("nkch-css", "is-disabled");

mw.util.addCSS(".nkch-css { background-color: rgba(var(--theme-page-background-color--rgb), .7); backdrop-filter: blur(10px); border: 1px solid var(--theme-border-color); border-radius: 10px; bottom: 50px; height: 300px; position: fixed; right: 20px; width: 450px; z-index: 9999 }");

$("body").after(nkchCSS);

$(nkchCSS).draggable({                                       cancel: ".nkch-css-text, .nkch-css-popup",                                        opacity: 0.8                                    }).resizable({                                        ghost: true,                                        handles: "nw, ne, se, sw",                                        minHeight: 300,                                        minWidth: 450                                    });

const nkchCSS_menu = document.createElement("div"); nkchCSS_menu.classList.add("nkch-css-menu");

mw.util.addCSS(".nkch-css-menu { align-items: center; display: flex; justify-content: space-between; height: 44px; padding: 0 10px; }");

nkchCSS.appendChild(nkchCSS_menu);

const nkchCSS_title = document.createElement("div"); nkchCSS_title.classList.add("nkch-css-title");

mw.util.addCSS(".nkch-css-title { align-items: center; display: flex; max-width: 80%; }");

const nkchCSS_title_text = document.createElement("div"); nkchCSS_title_text.classList.add("nkch-css-title-text");

nkchCSS_title_text.innerHTML = options.title;

mw.util.addCSS(".nkch-css-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }"); mw.util.addCSS(".nkch-css-menu { color: var(--theme-page-text-color); cursor: default; font-family: 'Rubik', sans-serif; font-size: 18px; }");

nkchCSS_menu.appendChild(nkchCSS_title); nkchCSS_title.appendChild(nkchCSS_title_text);

if (options.hideInfo === false) { const nkchCSS_info = new OO.ui.PopupButtonWidget({                                           classes: ["nkch-css-button", "nkch-css-button-info"],                                            framed: false,                                            icon: "info",                                            invisibleLabel: true,                                            label: "Информация",                                            popup: {                                                $content: $(" CodeMirror v. " + versions.codeMirror + " jQueryUI v. " + versions.jQueryUI + " ColorPicker v. " + versions.colorPicker + " "),                                               align: "center",                                                classes: ["nkch-css-popup"],                                                head: true,                                                hideCloseButton: true,                                                label: "nkchCSS v. " + versions.nkchCSS,                                                padded: true                                            }                                        });

mw.util.addCSS(".nkch-css-button-info > .oo-ui-buttonElement-button { margin-left: 5px; padding: 5px 6px; }"); mw.util.addCSS(".nkch-css-popup { font-size: initial; z-index: 99999; }"); mw.util.addCSS(".nkch-css-popup .oo-ui-labelElement-label { font-size: initial; margin-bottom: 5px; }"); mw.util.addCSS(".nkch-css-popup .oo-ui-popupWidget-body { font-size: initial; }"); mw.util.addCSS(".nkch-css-popup .oo-ui-popupWidget-head > .oo-ui-buttonWidget > .oo-ui-buttonElement-button .oo-ui-icon-close { min-height: 18px; min-width: 18px; }");

nkchCSS_title.appendChild(nkchCSS_info.$element[0]); }

const nkchCSS_tools = document.createElement("div"); nkchCSS_tools.classList.add("nkch-css-tools", "wds-button-group"); nkchCSS_menu.appendChild(nkchCSS_tools);

const nkchCSS_tools_toggleButton = document.createElement("button"); nkchCSS_tools_toggleButton.id = "nkch-css-tools-button-toggle"; nkchCSS_tools_toggleButton.classList.add("nkch-css-button", "wds-button", "wds-is-secondary");

nkchCSS_tools_toggleButton.appendChild(wds.icon("eye-small")); nkchCSS_tools_toggleButton.querySelector("svg").style.fill = "var(--theme-success-color)";

nkchCSS_tools_toggleButton.addEventListener("click", function {                                        toggle(editor.getValue);                                    });

nkchCSS_tools.appendChild(nkchCSS_tools_toggleButton);

const nkchCSS_tools_closebutton = document.createElement("button");

nkchCSS_tools_closebutton.id = "nkch-css-tools-button-close"; nkchCSS_tools_closebutton.classList.add("nkch-css-button", "wds-button", "wds-is-secondary");

mw.util.addCSS("#nkch-css-tools-button-close { border-color: var(--theme-alert-color); color: var(--theme-alert-color) }"); mw.util.addCSS("#nkch-css-tools-button-close:hover { border-color: var(--theme-alert-color--hover); color: var(--theme-alert-color--hover) }");

nkchCSS_tools_closebutton.appendChild(wds.icon("close-small"));

nkchCSS_tools_closebutton.addEventListener("click", function {                                        close;                                    });

nkchCSS_tools.appendChild(nkchCSS_tools_closebutton);

mw.util.addCSS(".nkch-css-tools .wds-button.wds-is-secondary { padding: 5px 6px; }");

const nkchCSS_text = document.createElement("div"); nkchCSS_text.classList.add("nkch-css-text");

mw.util.addCSS(".nkch-css-text { height: calc(100% - 44px); padding: 0 10px 10px 10px }");

nkchCSS.appendChild(nkchCSS_text);

const nkchCSS_toolbarButton = document.createElement("li"); const nkchCSS_toolbarButtonLink = document.createElement("a");

nkchCSS_toolbarButtonLink.classList.add("nkch-css-toolbar-button");

nkchCSS_toolbarButtonLink.innerHTML = "nkchCSS";

mw.util.addCSS(".nkch-css-toolbar-button { cursor: pointer }"); mw.util.addCSS(".nkch-css.is-disabled { visibility: hidden; }");

nkchCSS_toolbarButtonLink.addEventListener("click", function {                                        open;                                    });

nkchCSS_toolbarButton.appendChild(nkchCSS_toolbarButtonLink); document.querySelector("#WikiaBar .toolbar .tools").appendChild(nkchCSS_toolbarButton);

var editorOptions = { mode: "css", indentUnit: 4, indentWithTabs: true, lineNumbers: true, lineWrapping: true, tabSize: 4, autoCloseBrackets: true, colorpicker: { mode: "edit", onChange: function { updateCode(editor.getValue); },                                           onLastUpdate: function  { updateCode(editor.getValue); }                                       }                                    }

if (options.theme !== "default") { Object.assign(editorOptions, {                                           theme: options.theme                                        }) }

var editor = CodeMirror(nkchCSS_text, editorOptions);

mw.util.addCSS(".CodeMirror { border-radius: 5px; height: 100%; }"); mw.util.addCSS(".codemirror-colorpicker { z-index: 99999 !important; }");

var textarea = document.querySelector(".CodeMirror");

textarea.addEventListener("keyup", function {                                        updateCode(editor.getValue);                                    });

function updateCode(css) { if (nkch_IsDisabled === false) { nkchCSS_style.innerHTML = css; }                                   }

function open { nkchCSS.classList.remove("is-disabled"); }

function close { nkchCSS.classList.add("is-disabled"); }

function toggle(css) { switch (nkch_IsDisabled) { case true: nkchCSS_tools_toggleButton.querySelector("svg").remove; nkchCSS_tools_toggleButton.appendChild(wds.icon("eye-small")); nkchCSS_tools_toggleButton.querySelector("svg").style.fill = "var(--theme-success-color)"; nkchCSS_style.innerHTML = css; nkch_IsDisabled = false; break; case false: nkchCSS_tools_toggleButton.querySelector("svg").remove; nkchCSS_tools_toggleButton.appendChild(wds.icon("eye-crossed-small")); nkchCSS_tools_toggleButton.querySelector("svg").style.fill = "var(--theme-alert-color)"; nkchCSS_style.innerHTML = ""; nkch_IsDisabled = true; break; }                                   }                                }                            )                        });                });

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