User:Kofirs2634/global.js

importArticles({	type: 'script',	articles: [		'u:nkch:MediaWiki:nkchCSS.js',		'u:dev:MediaWiki:QuickDiff/code.js',		'u:dev:MediaWiki:FirstEditDate.js'	] });

// For mobile and Safari 15: set the browser header's color to wiki's background color // not a copy of ChromeToolbarColor, just a bicycle $(function {	if (mw.config.get('skin') != 'fandomdesktop') return	if ($('meta[name="theme-color"]').length) return	$('head').append($(' ', { name: 'theme-color' }))	setInterval(function { $('meta[name="theme-color"]').attr('content', getComputedStyle(document.body).getPropertyValue('--theme-body-background-color')) }, 1000) })

// Pages' Length mw.loader.using('mediawiki.api', function {    if (window.PagesLength) return;    window.PagesLength = true;

const c = mw.config.get(['wgPageName', 'wgNamespaceNumber', 'skin']), api = new mw.Api;

if (c.wgNamespaceNumber % 2 != 0 || c.wgNamespaceNumber == -1) return; if (!['fandomdesktop', 'oasis'].includes(c.skin)) return;

api.get({       action: 'query',        prop: 'revisions',        rvlimit: 2,        rvprop: 'size',        titles: c.wgPageName    }) .done(render) .fail(function(e) {       console.error('Pages\' Length caught an error:', e);        var selector = c.skin == 'oasis' ? '.page-header__main' : '.page-header__top';        $(selector).prepend($(' ', { class: 'pages-length' }).css('color', '#F00').text('При загрузке Pages\' Length произошла ошибка.'))    }) function render(d) { var r = d.query.pages[Object.keys(d.query.pages)[0]].revisions, diff, percent, el = $(' ', { class: 'pages-length' }), co = $(' '); if (d.missing == '') diff = percent = 0; if (r.length) { if (r.length == 1) { diff = r[0].size; percent = 100 } else { diff = r[0].size - r[1].size; percent = ((r[0].size / r[1].size - 1) * 100).toFixed(2) }       }

el.html(' Размер: ' + (r.length ? r[0].size : diff) + ' байт '); if (diff == 0) co.addClass('mw-plusminus-null').text('(0; = 0%)') else if (diff > 0) co.addClass('mw-plusminus-pos').text('(+' + diff + '; ▲+' + percent + '%)') else if (diff < 0) co.addClass('mw-plusminus-neg').text('(' + diff + '; ▼' + percent + '%)'); if (Math.abs(diff) >= 500) co.css('font-weight', 'bold');

if (c.skin == 'oasis') $('.page-header__main').prepend(el.append(co)) else { $('.page-header__top').prepend(el.append(co)); $('head').append($(' ', { id: 'pageslength-styles', text: '.page-header__top { flex-wrap: wrap } .pages-length { width: 100% }' + '.mw-plusminus-pos{color:#006400}.mw-plusminus-neg{color:#8b0000}.mw-plusminus-null{color:#a2a9b1}' }))		}   } });

// WhileYouWereAway $(function {	if (window.WhileYouWereAway) return;	window.WhileYouWereAway = true;	const c = mw.config.get('wgCanonicalSpecialPageName');	var storage = localStorage.getItem('WYWATimemark');	if (c != 'Recentchanges') return;

var mark = findEntry('table'), firstTable = $('table.mw-changeslist-line').eq(0).attr('data-mw-ts'), submark = findEntry('tr'), firstTr = $('tr.mw-changeslist-line').eq(0).attr('data-mw-ts') function findEntry(el) { return $(el + '.mw-changeslist-line') .map(function(n, e) { return $(e).attr('data-mw-ts') }) .toArray.find(function(e) { return e < storage }) }	function toggleMark(e) { var state = $(e.target).parents.eq(3).hasClass('mw-collapsed'); $('.wywa-mark').css('display', state ? 'block' : 'none') }

if (!mark) $('.mw-changeslist').append($(' ', { class: 'wywa-mark' })) else if (firstTable != mark) $('table[data-mw-ts="' + mark + '"]').before($(' ', { class: 'wywa-mark' }))

if (submark && firstTr != submark) { $('tr[data-mw-ts="' + submark + '"]').before($(' ', { class: 'wywa-submark' }).append($(' ', { colspan: 99 }))); $('.wywa-submark').siblings.eq(0).find('.mw-collapsible-toggle').click(toggleMark) }	$('.wywa-mark, .wywa-submark').click(function(e) { $(e.target).remove }) storage = new Date.toISOString.match(/\d/g).join('').slice(0, 14) localStorage.setItem('WYWATimemark', storage) });

// themetoggler Кочана 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"        }); } );