Dantes (обсуждение | вклад) Нет описания правки |
Dantes (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
(function () { | (function () { | ||
var words = { | var words = { | ||
"властью": "#e74c3c", | |||
"ответственность": "#9b59b6", | |||
"Процедуры": "#2980b9", | |||
"ядерный": "#f1c40f", | |||
"диск": "#e67e22", | |||
"станции": "#1abc9c", | |||
"ГСБ": "#2c3e50", | |||
"увольнение": "#c0392b", | |||
"офицера": "#16a085", | |||
"банановая": "#d35400" | |||
}; | }; | ||
function colorize($content) { | function colorize($content) { | ||
var html = $ | $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); | |||
}); | |||
} | } | ||
Версия от 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);
});
})();