MediaWiki:Common.js: различия между версиями
Страница интерфейса MediaWiki
Дополнительные действия
Actn2k (обсуждение | вклад) Нет описания правки |
Actn2k (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
const pageName = mw.config.get("wgPageName"); | const pageName = mw.config.get("wgPageName"); | ||
if (pageName == "Заглавная_страница" || pageName == "Test2") { | if (pageName == "Заглавная_страница" || pageName == "Test2") { | ||
| Строка 89: | Строка 85: | ||
toggleSecret(); | toggleSecret(); | ||
}; | }; | ||
}) | }) if (localStorage.getItem('ѾmodeEnabled') === 'true') { | ||
startSecret(); | |||
} | |||
}); | }); | ||
| Строка 120: | Строка 118: | ||
} | } | ||
} | } | ||
function replaceNext() { | function replaceNext() { | ||
if (available.length === 0) return; | if (available.length === 0) return; | ||
Версия от 12:02, 12 августа 2025
const pageName = mw.config.get("wgPageName");
if (pageName == "Заглавная_страница" || pageName == "Test2") {
document.documentElement.classList.replace('skin-theme-clientpref-day', 'skin-theme-clientpref-night');
}
document.querySelectorAll(".server-hook").forEach(function(element) {
var ip = element.getAttribute("data-ip");
var port = element.getAttribute("data-port");
var url = "https://wiki.ss13-bluemoon.ru/nodeapi/status?ip=" + encodeURIComponent(ip) + "&port=" + encodeURIComponent(port);
fetch(url).then(function(response) {
if (!response.ok) {
throw new Error(response.status);
}
return response.json();
}).then(function(data) {
element.textContent = data.response.players;
}).catch(function(error) {
element.textContent = "⨉";
});
});
if (pageName != "Шаблон:Таблица_Космический_Закон") {
let current = null;
let currentCell = null;
const table = document.getElementById("law");
if (table) {
table.addEventListener("click", function(event) {
const cell = event.target.closest("td");
if (!cell) return;
if (!cell.dataset.id) return;
if (current !== null) {
document.getElementById(current).style.display = "none";
if (currentCell) currentCell.classList.remove("law-selected");
}
if (cell.dataset.id === current) {
current = null;
currentCell = null;
return;
}
current = cell.dataset.id;
currentCell = cell;
document.getElementById(current).style.display = "block";
cell.classList.add("law-selected");
});
}
} else {
const allObjects = document.querySelectorAll(".law-object");
allObjects.forEach(el => el.style.display = "block");
}
mw.loader.using('jquery', function() {
$(function() {
$('.vtabs').each(function() {
const $container = $(this);
const $buttons = $container.find('.vtabs-button');
const $contents = $container.find('.vtabs-content');
$buttons.each(function(index) {
$(this).on('click', function() {
$buttons.removeClass('active');
$contents.removeClass('active');
$(this).addClass('active');
$contents.eq(index).addClass('active');
});
});
});
});
});
mw.loader.using('mediawiki.util', function() {
$(function() {
$('.colstr-header').each(function() {
$(this).on('click', function() {
const $panel = $(this).closest('.colstr-panel');
const isOpen = $panel.toggleClass('open').hasClass('open');
$(this).attr('aria-expanded', isOpen);
});
});
});
});
mw.loader.using('mediawiki.util', function() {
mw.util.addPortletLink('p-personal', '#', 'Режим Ѿ', 'pt-omode', 'Режим Ѿ').addEventListener('click', function(e) {
e.preventDefault();
toggleSecret();
};
}) if (localStorage.getItem('ѾmodeEnabled') === 'true') {
startSecret();
}
});
function startSecret() {
function getVisibleTextNodes(root) {
let nodes = [];
function walk(node) {
if (node.nodeType === Node.TEXT_NODE) {
if (node.nodeValue.trim() !== "" && node.parentNode.offsetParent !== null) {
nodes.push(node);
}
} else if (node.nodeType === Node.ELEMENT_NODE && node.tagName !== "SCRIPT" && node.tagName !== "STYLE") {
for (let child of node.childNodes) walk(child);
}
}
walk(root);
return nodes;
}
let textNodes = getVisibleTextNodes(document.body);
let available = [];
for (let node of textNodes) {
for (let i = 0; i < node.nodeValue.length; i++) {
if (!/[\s]/.test(node.nodeValue[i])) {
available.push({
node,
index: i
});
}
}
}
function replaceNext() {
if (available.length === 0) return;
let randIndex = Math.floor(Math.random() * available.length);
let {
node,
index
} = available.splice(randIndex, 1)[0];
let chars = node.nodeValue.split("");
chars[index] = "Ѿ";
node.nodeValue = chars.join("");
setTimeout(replaceNext, 1);
}
replaceNext();
}
function toggleSecret() {
let enabled = localStorage.getItem(STORAGE_KEY) === 'true';
if (enabled) {
localStorage.setItem(STORAGE_KEY, 'false');
location.reload();
} else {
localStorage.setItem(STORAGE_KEY, 'true');
location.reload();
}
}