MediaWiki:Test.js: различия между версиями

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 13: Строка 13:
};
};


function colorize($content) {
function colorize($root) {
$content.find("*").each(function () {
$root.find("*").each(function () {
var $el = $(this);
var $el = $(this);
if ($el.is("h1,h2,h3,h4,h5,h6,th,table,code,pre")) return;
if ($el.is("h1,h2,h3,h4,h5,h6,th,table,code,pre,.citizen-section-heading,.mw-headline")) return;
var html = $el.html();
var html = $el.html();
for (var word in words) {
for (var word in words) {
Строка 29: Строка 29:


mw.hook("wikipage.content").add(function ($content) {
mw.hook("wikipage.content").add(function ($content) {
colorize($content);
colorize($content.find(".mw-parser-output"));
});
});
})();
})();

Версия от 22:06, 16 января 2026

(function () {
	var words = {
		"властью": "#e74c3c",
		"ответственность": "#9b59b6",
		"Процедуры": "#2980b9",
		"ядерный": "#f1c40f",
		"диск": "#e67e22",
		"станции": "#1abc9c",
		"ГСБ": "#2c3e50",
		"увольнение": "#c0392b",
		"офицера": "#16a085",
		"банановая": "#d35400"
	};

	function colorize($root) {
		$root.find("*").each(function () {
			var $el = $(this);
			if ($el.is("h1,h2,h3,h4,h5,h6,th,table,code,pre,.citizen-section-heading,.mw-headline")) return;
			var html = $el.html();
			for (var word in words) {
				if (!words.hasOwnProperty(word)) continue;
				var color = words[word];
				var re = new RegExp("\\b(" + word + ")\\b", "g");
				html = html.replace(re, '<span style="color:' + color + '; font-weight:600;">$1</span>');
			}
			$el.html(html);
		});
	}

	mw.hook("wikipage.content").add(function ($content) {
		colorize($content.find(".mw-parser-output"));
	});
})();