MediaWiki:Common.js: различия между версиями
User (обсуждение | вклад) Нет описания правки |
User (обсуждение | вклад) Нет описания правки |
||
| Строка 48: | Строка 48: | ||
var links = document.querySelectorAll('.custom-top-menu a'); | var links = document.querySelectorAll('.custom-top-menu a'); | ||
links.forEach(function (link) { | links.forEach(function (link) { | ||
var linkhref = ' | var linkhref = location.protocol + '//' + location.host + link.getAttribute('href').trim(); | ||
console.log(currentPageHref + '=' + linkhref); | console.log(currentPageHref + '=' + linkhref); | ||
Версия от 13:52, 15 мая 2024
if (document.readyState !== 'loading') {
myInitCode();
} else {
document.addEventListener('DOMContentLoaded', function () {
myInitCode();
});
}
function myInitCode() {
var node = document.getElementById("content");
var content = document.createElement("ul");
content.classList.add("custom-top-menu");
var items = [{
href: "/wiki/Вики-энциклопедия_университета",
title: "Главная",
text: "Главная",
}, {
href: "/wiki/Вики-энциклопедия_университета:Правила",
title: "Правила",
text: "Правила",
}, {
href: "/wiki/Служебная:Все_страницы",
title: "Все страницы",
text: "Статьи",
}, {
href: "/wiki/Служебная:Свежие_правки",
title: "Свежие правки",
text: "История правок",
}, {
href: "/wiki/Вики-энциклопедия_университета:Инструкции",
title: "Инструкции",
text: "Инструкции",
}, {
href: "/wiki/Вики-энциклопедия_университета:Контакты",
title: "Заголовок 2",
text: "Контакты",
}];
items.forEach(function (item) {
var li = document.createElement("li");
var a = document.createElement("a");
a.href = item.href;
a.title = item.title;
a.textContent = item.text;
li.appendChild(a);
content.appendChild(li);
});
node.parentNode.insertBefore(content, node);
var currentPageHref = decodeURI(window.location.href);
var links = document.querySelectorAll('.custom-top-menu a');
links.forEach(function (link) {
var linkhref = location.protocol + '//' + location.host + link.getAttribute('href').trim();
console.log(currentPageHref + '=' + linkhref);
if (currentPageHref.indexOf(linkhref) > -1) {
link.closest('li').classList.add('a-current');
}
});
}