MediaWiki:Common.js — различия между версиями
Adm (обсуждение | вклад) |
Adm (обсуждение | вклад) |
||
Строка 19: | Строка 19: | ||
a.setAttribute('href', a.href.replace(/§ion=1/,'§ion=0')); | a.setAttribute('href', a.href.replace(/§ion=1/,'§ion=0')); | ||
}) | }) | ||
+ | |||
+ | // hasClass() | ||
+ | var hasClass = (function () { | ||
+ | var reCache = {}; | ||
+ | return function (element, className) { | ||
+ | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); | ||
+ | }; | ||
+ | })(); |
Версия 19:35, 3 июля 2021
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
//Edit zero section
if (wgAction == 'view' && wgNamespaceNumber >=0)
addOnloadHook(function(){
var h2s = document.getElementsByTagName('H2');
var h2 = h2s[0];
if (!h2) return;
if (h2.parentNode.id == 'toctitle') h2 = h2s[1];
if (!h2) return;
var span = h2.firstChild;
if (!span || span.className != 'editsection') return;
var zero = span.cloneNode(true);
if (document.getElementById('featured-star')) zero.style.marginRight = '25px'
var parent = document.getElementsByTagName('H1')[0];
parent.insertBefore(zero, parent.firstChild);
var a = zero.getElementsByTagName('A')[0];
a.title = a.title.replace(/:.*$/,' после заголовка');
a.setAttribute('href', a.href.replace(/§ion=1/,'§ion=0'));
})
// hasClass()
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();