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

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


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



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

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

	function colorize($content) {
		$content.find("*").each(function () {
			var $el = $(this);
			if ($el.is("h1,h2,h3,h4,h5,h6,th,table,code,pre")) 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);
	});
})();