MediaWiki:Common.js: различия между версиями
Страница интерфейса MediaWiki
Дополнительные действия
Actn2k (обсуждение | вклад) Нет описания правки |
Rirma4ch (обсуждение | вклад) Нет описания правки |
||
| (не показано 36 промежуточных версий 2 участников) | |||
| Строка 1: | Строка 1: | ||
const pageName = mw.config.get("wgPageName"); | const pageName = mw.config.get("wgPageName"); | ||
mw.loader.using([], function () { | |||
importScript("MediaWiki:PageDefaultAttributes.js"); | |||
} | }); | ||
// Отображение онлайна | |||
document.querySelectorAll(".server-hook").forEach(function(element) { | document.querySelectorAll(".server-hook").forEach(function(element) { | ||
| Строка 20: | Строка 22: | ||
}); | }); | ||
}); | }); | ||
// Интерактивная таблица | |||
if (pageName != "Шаблон:Таблица_Космический_Закон") { | if (pageName != "Шаблон:Таблица_Космический_Закон") { | ||
| Строка 49: | Строка 53: | ||
allObjects.forEach(el => el.style.display = "block"); | allObjects.forEach(el => el.style.display = "block"); | ||
} | } | ||
// Вертикальный tabs | |||
mw.loader.using('jquery', function() { | mw.loader.using('jquery', function() { | ||
| Строка 67: | Строка 73: | ||
}); | }); | ||
}); | }); | ||
// Сворачиваемая строка | |||
mw.loader.using('mediawiki.util', function() { | mw.loader.using('mediawiki.util', function() { | ||
| Строка 79: | Строка 87: | ||
}); | }); | ||
}); | }); | ||
// Пасхалка буква жопа | |||
mw.loader.using('mediawiki.util', function() { | mw.loader.using('mediawiki.util', function() { | ||
| Строка 84: | Строка 94: | ||
'p-personal', | 'p-personal', | ||
'#', | '#', | ||
' | ' ', | ||
'pt-omode', | 'pt-omode', | ||
' | ' ' | ||
).addEventListener('click', function(e) { | ).addEventListener('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
toggleSecret(); | |||
}); | }); | ||
if (localStorage.getItem( | if (localStorage.getItem('ѾmodeEnabled') === 'true') { | ||
startSecret(); | |||
} | } | ||
}); | }); | ||
| Строка 100: | Строка 110: | ||
function getVisibleTextNodes(root) { | function getVisibleTextNodes(root) { | ||
let nodes = []; | let nodes = []; | ||
function walk(node) { | function walk(node) { | ||
if (node.nodeType === Node.TEXT_NODE) { | if (node.nodeType === Node.TEXT_NODE) { | ||
| Строка 113: | Строка 122: | ||
return nodes; | return nodes; | ||
} | } | ||
let textNodes = getVisibleTextNodes(document.body); | let textNodes = getVisibleTextNodes(document.body); | ||
let | let matches = []; | ||
for (let node of textNodes) { | for (let node of textNodes) { | ||
let regex = /от/gi; | |||
let match; | |||
while ((match = regex.exec(node.nodeValue)) !== null) { | |||
matches.push({ | |||
node, | |||
start: match.index, | |||
length: match[0].length | |||
}); | |||
} | } | ||
} | } | ||
function replaceNext() { | function replaceNext() { | ||
if ( | if (matches.length === 0) return; | ||
let randIndex = Math.floor(Math.random() * | let randIndex = Math.floor(Math.random() * matches.length); | ||
let { | let { | ||
node, | node, | ||
start, | |||
} = | length | ||
} = matches.splice(randIndex, 1)[0]; | |||
let chars = node.nodeValue.split(""); | let chars = node.nodeValue.split(""); | ||
chars | chars.splice(start, length, "Ѿ"); | ||
node.nodeValue = chars.join(""); | node.nodeValue = chars.join(""); | ||
matches = matches.filter(m => m.node !== node || m.start > start); | |||
setTimeout(replaceNext, 1); | setTimeout(replaceNext, 1); | ||
} | } | ||
replaceNext(); | replaceNext(); | ||
} | } | ||
function toggleSecret() { | function toggleSecret() { | ||
if (localStorage.getItem('ѾmodeEnabled') === 'true') { | |||
localStorage.setItem('ѾmodeEnabled', 'false'); | |||
localStorage.setItem( | |||
location.reload(); | location.reload(); | ||
} else { | } else { | ||
localStorage.setItem( | localStorage.setItem('ѾmodeEnabled', 'true'); | ||
location.reload(); | location.reload(); | ||
} | } | ||
} | } | ||