User:TheRunyx/common.js

/* Config */ window.syntaxHighlighterConfig = { 'backgroundColor': '#fefefe', 'foregroundColor': '#3a3a3a', 'boldOrItalicColor': '#e4e5f3', 'commentColor': '#f8dbda', 'entityColor': '#DFD', 'externalLinkColor': '#dbeceb', 'headingColor': '#e4e5f3', 'hrColor': '#e4e5f3', 'listOrIndentColor': '#f8dbda', 'parameterColor': '#66331e', 'signatureColor': '#f5e0d8', 'tagColor': '#f6dde9', 'tableColor': '#f0ebdb', 'templateColor': '#f0ebdb', 'wikilinkColor': '#d9eaf6' };

/** * Adds syntax highlighting to wikitext editor * * Some modifications by Rail * Code from MediaWiki.org by Remember_the_dot - https://www.mediawiki.org/wiki/User:Remember_the_dot/Syntax_highlighter.js */ mw.loader.using('jquery.client', function {	'use strict';

var config = mw.config.get([			'wgAction',			'wgUrlProtocols',			'wgUserLanguage',			'wgPageContentModel'		]), g, h, m, f, p, y, C, x = -1, e = config.wgUrlProtocols, r = "&(?:(?:n(?:bsp|dash)|m(?:dash|inus)|lt|e[mn]sp|thinsp|amp|quot|gt|shy|zwn?j|lrm|rlm|Alpha|Beta|Epsilon|Zeta|Eta|Iota|Kappa|[Mm]u|micro|Nu|[Oo]micron|[Rr]ho|Tau|Upsilon|Chi)|#x[0-9a-fA-F]+);\n*", t = "\\[(?:\\[|(?:" + e + "))|\\{(?:\\{\\{?|\\|)|<(?:[:A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ-῿‌‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�][:\\wÀ-ÖØ-öø-˿Ͱ-ͽͿ-῿‌‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�-\\.·̀-ͯ‿-‿-⁀]*(?=/?>| |\n)|!--[^]*?--\x3e\n*)|(?:" + e.replace("|\\/\\/", "") + ")[^\\s\"<>[\\]{-}]*[^\\s\",\\.:;<>[\\]{-}]\n*|^(?:=|[*#:;]+\n*|-{4,}\n*)|\\\\'\\\\'(?:\\\\')?|~{3,5}\n*|" + r;

function b(e) { return new RegExp("(" + e + ")\n*|" + t, "gm") } var v = new RegExp(t, "gm"), w = b("]][a-zA-Z]*"), H = b("]"), k = b("}}}"), z = b("}}"), E = b("\\|}"), S = b("\n"), T = {}, L = {}; function F { var i, d = (f = h.value).replace(/['\\]/g, "\\$&") + "\n", u = 0, o = "", r = 0, n = !0; function c(e, t) { t != i && (o += "'}#s" + r, n ? (o += ":before{", n = !1) : (o += ":after{", n = !0, ++r), t && (o += "background-color:" + t + ";"), o += "content:'", i = t), o += e;		} var e = Date.now; ! function e(t, i, o, r) { var n;			for (i.lastIndex = u; n = i.exec(d); i.lastIndex = u) { if (n[1]) return c(d.substring(u, i.lastIndex), t), void(u = i.lastIndex); var a = i.lastIndex - n[0].length; switch (u < a && c(d.substring(u, a), t), u = i.lastIndex, n[0].charAt(0)) { case "[": "[" == n[0].charAt(1) ? (c("[[", syntaxHighlighterConfig.wikilinkColor || t), e(syntaxHighlighterConfig.wikilinkColor || t, w)) : (c(n[0], syntaxHighlighterConfig.externalLinkColor || t), e(syntaxHighlighterConfig.externalLinkColor || t, H));						break;					case '{':						'{' == n[0].charAt(1) ? 3 == n[0].length ? (c('{{{', syntaxHighlighterConfig.parameterColor || t), e(syntaxHighlighterConfig.parameterColor || t, k)) : (c("{{", syntaxHighlighterConfig.templateColor || t), e(syntaxHighlighterConfig.templateColor || t, z)) : (c("{|", syntaxHighlighterConfig.tableColor || t), e(syntaxHighlighterConfig.tableColor || t, E));						break;					case "<":						if ("!" == n[0].charAt(1)) {							c(n[0], syntaxHighlighterConfig.commentColor || t);							break;						}						var s = d.indexOf(">", u) + 1;						if (0 === s) {							c("<", t), u = u - n[0].length + 1;							break;						}						if ("/" == d.charAt(s - 2)) c(d.substring(u - n[0].length, s), syntaxHighlighterConfig.tagColor || t), u = s;						else {							var l = n[0].substring(1);							if (-1 != syntaxHighlighterConfig.sourceTags.indexOf(l)) {								var g = "",									h = d.indexOf(g, u); - 1 == h ? h = d.length : h += g.length, c(d.substring(u - n[0].length, h), syntaxHighlighterConfig.tagColor || t), u = h;							} else -1 != syntaxHighlighterConfig.nowikiTags.indexOf(l) ? (c(d.substring(u - n[0].length, s), syntaxHighlighterConfig.tagColor || t), u = s, e(syntaxHighlighterConfig.tagColor || t, L[l])) : (c(d.substring(u - n[0].length, s), syntaxHighlighterConfig.tagColor || t), u = s, T[l] || (T[l] = b("")), e(syntaxHighlighterConfig.tagColor || t, T[l]));						}						break;					case '=':						/[^=]=+$/.test(d.substring(u, d.indexOf("\n", u))) ? (c("=", syntaxHighlighterConfig.headingColor || t), e(syntaxHighlighterConfig.headingColor || t, S)) : c("=", t);						break;					case '*':					case '#':					case ':':						c(n[0], syntaxHighlighterConfig.listOrIndentColor || t);						break;					case ';':						c(';', syntaxHighlighterConfig.headingColor || t), e( syntaxHighlighterConfig.headingColor || t, S);						break;					case '-':						c(n[0], syntaxHighlighterConfig.hrColor || t);						break;					case '\\':						if (c(n[0], syntaxHighlighterConfig.boldOrItalicColor || t), 6 == n[0].length)							if (o) {								if (!r) return;								o = !1;							} else r ? o = !0 : e(syntaxHighlighterConfig.boldOrItalicColor || t, v, !0, !1);						else if (r) {							if (!o) return;							r = !1;						} else o ? r = !0 : e(syntaxHighlighterConfig.boldOrItalicColor || t, v, !1, !0);						break;					case '&':						c(n[0], syntaxHighlighterConfig.entityColor || t);						break;					case '~':						c(n[0], syntaxHighlighterConfig.signatureColor || t);						break;					default: c(n[0], syntaxHighlighterConfig.externalLinkColor || t);				}			}		}("", v), u < d.length && c(d.substring(u), );		var t = Date.now;		if (t - e > syntaxHighlighterConfig.timeout) {			clearInterval(p), h.removeEventListener('input', F), h.removeEventListener('scroll', I), h.removeEventListener('scroll', O), y.disconnect, C.disconnect, m.nodeValue = ;			var a = {					en: 'Syntax highlighting on this page was disabled because it took too long. The maximum allowed highlighting time is $1ms, and your computer took $2ms. Try closing some tabs and programs and clicking "Show preview" or "Show changes". If that doesn\'t work, try a different web browser, and if that doesn\'t work, try a faster computer.',					pl: 'Podświetlanie składni nie zostało załadowane na tej stronie, ponieważ jego wygenerowanie zabrało zbyt wiele czasu. Maksymalnym czasem na załadowanie podświetlania jest $1ms, a twój komputer potrzebował na to $2ms. Spróbuj zamknąć karty i programy działające w tle, a następnie kliknij „Pokaż podgląd” lub „Podgląd zmian”. Jeżeli to nie pomoże, użyj innej przeglądarki. Jeśli to nie pomoże, użyj szybszego komputera.'				},				s = config.wgUserLanguage;			return a = a[s] || a[s.substring(0, s.indexOf('-'))] || a.en, h.style.backgroundColor = "", h.style.marginTop = "0", g.removeAttribute("dir"), g.removeAttribute("lang"), g.setAttribute("style", "color:red; font-size:small"), void(g.textContent = a.replace('$1', syntaxHighlighterConfig.timeout).replace('$2', t - e));		}		if (x < r) {			for (var l = document.createDocumentFragment; l.appendChild(document.createElement("span")).id = "s" + ++x, x < r;);			g.appendChild(l);		}		m.nodeValue = o.substring(2).replace(/\n/g, "\\A ") + "'}";	}	function I { g.scrollLeft = h.scrollLeft }	function O { g.scrollTop = h.scrollTop }	function n { g.dir = h.dir }	function a {		h.previousSibling != g && (h.parentNode.insertBefore(g, h), C.disconnect, C.observe(h.parentNode, {			childList: !0		}));	}	function s {		if (h.value != f && new F, h.scrollLeft != g.scrollLeft && new I, h.scrollTop != g.scrollTop && O, h.offsetHeight != g.offsetHeight) {			var e = h.offsetHeight + "px";			g.style.height = e, h.style.marginTop = "-" + e;		}	}	function i {		function e(e, t, i) {			if (void 0 === syntaxHighlighterConfig[e] && (syntaxHighlighterConfig[e] = syntaxHighlighterSiteConfig[e]), "normal" == syntaxHighlighterConfig[e]) syntaxHighlighterConfig[e] = t;			else {				if (void 0 !== syntaxHighlighterConfig[e]) return;				void 0 !== syntaxHighlighterConfig.defaultColor && i ? syntaxHighlighterConfig[e] = syntaxHighlighterConfig.defaultColor : syntaxHighlighterConfig[e] = t;			}		}		window.syntaxHighlighterSiteConfig = window.syntaxHighlighterSiteConfig || {}, window.syntaxHighlighterConfig = window.syntaxHighlighterConfig || {}, e("backgroundColor", "#111", !1), e("foregroundColor", "#d5d4d4", !1), e("boldOrItalicColor", "#44466d", !0), e("commentColor", "#4d1a19", !0), e("entityColor", "#DFD", !0), e("externalLinkColor", "#467699", !0), e("headingColor", "#44466d", !0), e("hrColor", "#44466d", !0), e("listOrIndentColor", "#4d1a19", !0), e("parameterColor", "#66331e", !0), e("signatureColor", "#66331e", !0), e("tagColor", "#662946", !0), e("tableColor", "#5e5129", !0), e("templateColor", "#5e5129", !0), e("wikilinkColor", "#245477", !0), syntaxHighlighterConfig.nowikiTags = syntaxHighlighterConfig.nowikiTags || syntaxHighlighterSiteConfig.nowikiTags || ["nowiki", "pre"], syntaxHighlighterConfig.sourceTags = syntaxHighlighterConfig.sourceTags || syntaxHighlighterSiteConfig.sourceTags || ["math", "syntaxhighlight", "source", "timeline", "hiero"], syntaxHighlighterConfig.timeout = syntaxHighlighterConfig.timeout || syntaxHighlighterSiteConfig.timeout || 50, syntaxHighlighterConfig.nowikiTags.forEach(function(e) {			L[e] = new RegExp("()\n*|" + r, "gm");		}), g = document.createElement("div"), h = document.getElementById("wpTextbox1");		var t = document.createElement("style");		m = t.appendChild(document.createTextNode(""));		var i = window.getComputedStyle(h),			o = "vertical" == i.resize || "both" == i.resize ? "vertical" : "none";		g.dir = h.dir, g.id = "wpTextbox0", g.lang = h.lang, g.style.backgroundColor = syntaxHighlighterConfig.backgroundColor, g.style.border = "1px solid transparent", g.style.boxSizing = "border-box", g.style.clear = i.clear, g.style.color = "transparent", g.style.fontFamily = i.fontFamily, g.style.fontSize = i.fontSize, g.style.lineHeight = "normal", g.style.marginBottom = "0", g.style.marginLeft = "0", g.style.marginRight = "0", g.style.marginTop = "0", g.style.overflowX = "auto", g.style.overflowY = "scroll", g.style.resize = o, g.style.tabSize = i.tabSize, g.style.whiteSpace = "pre-wrap", g.style.width = "100%", g.style.wordWrap = "normal", h.style.backgroundColor = "transparent", h.style.border = "1px inset gray", h.style.boxSizing = "border-box", h.style.color = syntaxHighlighterConfig.foregroundColor, h.style.fontSize = i.fontSize, h.style.lineHeight = "normal", h.style.marginBottom = i.marginBottom, h.style.marginLeft = "0", h.style.marginRight = "0", h.style.overflowX = "auto", h.style.overflowY = "scroll", h.style.padding = "0", h.style.resize = o, h.style.width = "100%", h.style.wordWrap = "normal", h.style.height = g.style.height = h.offsetHeight + "px", h.style.marginTop = -h.offsetHeight + "px", h.parentNode.insertBefore(g, h), document.head.appendChild(t), h.addEventListener("input", F), h.addEventListener("scroll", I), h.addEventListener("scroll", O), (y = new MutationObserver(n)).observe(h, {			attributes: !0		}), (C = new MutationObserver(a)).observe(h.parentNode, {			childList: !0		}), p = setInterval(s, 500), new F;	}	var o = config.wgAction,		l = $.client.profile.layout;	'edit' !== o && 'submit' !== o ||	'wikitext' !== config.wgPageContentModel ||	'trident' === l ||	'edge' === l ||	('complete' === document.readyState ? i : window.addEventListener('load', i)); });