User:Kofirs2634/global.js

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

mw.loader.using('mediawiki.api', function {	if (window.linkThumb || mw.config.get('wgCanonicalSpecialPageName') == 'Newimages') return	window.linkThumb = true	if (!window.linkThumbConfig) window.linkThumbConfig = {}	const c = mw.config.get(['wgScriptPath', 'wgFormattedNamespaces', 'wgArticlePath']),		api = new mw.Api	var requestTimer, closeTimer	var i18n	function init {		// append preview block and its styles		$('body').append($(' ', { id: 'linkThumb-prev' }))		$('head').append($(' ', { id: 'linkThumb-styles', text:			'#linkThumb-prev{position:fixed;bottom:20px;left:80px;z-index:9999;color:var(--theme-body-text-color)}' +			'#linkThumb-prev.error{background:var(--theme-page-background-color);border:1px solid #F00;padding:0 4px;color:var(--theme-page-text-color)}'		}))		// search all links leading to files' pages		var selector = '#mw-content-text a[href^="' + c.wgArticlePath.replace('$1', encodeURI(c.wgFormattedNamespaces[6])) + '"]' $(selector) .mouseenter(function(e) {			if ($(e.target).prop('tagName') != 'A') return			// cut out start of link and keep only namespaced file title			var title = $(e.target).attr('href').substr(c.wgArticlePath.replace('$1', '').length)			// some mess with timers			clearTimeout(closeTimer)			clearTimeout(requestTimer)			// send request with small delay			requestTimer = setTimeout( function { getImg(title) }, window.linkThumbConfig.requestTimeout >= 500 ? window.linkThumbConfig.requestTimeout : 1000 )		})		.mouseleave(function(e) {			clearTimeout(requestTimer)			// close preview			closeTimer = setTimeout( function { $('#linkThumb-prev').empty.removeClass('error') }, window.linkThumbConfig.closeTimeout || 2000 )		})	}

function getImg(title) { // while request is pending, show the loading text $('#linkThumb-prev').removeClass('error').text(i18n.msg('loading').plain) api.get({			action: 'query',			titles: decodeURI(title),			prop: 'imageinfo',			iiprop: 'url',			iiurlwidth: window.linkThumbConfig.width > 0 ? window.linkThumbConfig.width : 200,			redirects: true		}).done(function(r) {			var path = r.query.pages[Object.keys(r.query.pages)[0]]			if (path.missing !== undefined) { // file doesn't exist, show error				$('#linkThumb-prev').addClass('error').html(i18n.msg('error-unexist', c.wgArticlePath.replace('$1', title), decodeURI(title)).plain)			} else if (typeof path.imageinfo == 'undefined') {				$('#linkThumb-prev').addClass('error').html(i18n.msg('error-no-thumb', c.wgArticlePath.replace('$1', title), decodeURI(title)).plain)			} else { // file exists, show it				$('#linkThumb-prev').empty.append($(' ', {					src: r.query.pages[Object.keys(r.query.pages)[0]].imageinfo[0].thumburl				}))			}		}).fail(function(e) { // catching uncaught errors console.error('linkThumb got an error:', e)			$('#linkThumb-prev').addClass('error').html(i18n.msg('error-failed', c.wgArticlePath.replace('$1', title), decodeURI(title)).plain) })	}

mw.hook('dev.i18n').add(function(i) {		i.loadMessages('u:ru.koffee:MediaWiki:Custom-I18nTests/i18n.json').then(function(i) { i18n = i; i18n.useUserLang; init })	})

importArticle({ type: 'script', article: 'u:dev:MediaWiki:i18n-js/code.js' }) });

// 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"        }); } );