MediaWiki:Common.js: различия между версиями
User (обсуждение | вклад) Нет описания правки |
User (обсуждение | вклад) Нет описания правки |
||
| Строка 15: | Строка 15: | ||
href: "/wiki/Вики-энциклопедия_университета", | href: "/wiki/Вики-энциклопедия_университета", | ||
title: "Главная", | title: "Главная", | ||
spanText: "Главная" | spanText: "Главная" | ||
}, { | }, { | ||
href: "/wiki/Правила", | href: "/wiki/Правила", | ||
title: "Правила", | title: "Правила", | ||
spanText: "Правила" | spanText: "Правила" | ||
}, { | }, { | ||
href: "/wiki/Служебная:Все_страницы", | href: "/wiki/Служебная:Все_страницы", | ||
title: "Все страницы", | title: "Все страницы", | ||
spanText: "Статьи" | spanText: "Статьи" | ||
}, { | }, { | ||
href: "/wiki/Служебная:Свежие_правки", | href: "/wiki/Служебная:Свежие_правки", | ||
title: "Свежие правки", | title: "Свежие правки", | ||
spanText: "История правок" | spanText: "История правок" | ||
}, { | }, { | ||
href: "/wiki/Инструкции", | href: "/wiki/Инструкции", | ||
title: "Инструкции", | title: "Инструкции", | ||
spanText: "Инструкции" | spanText: "Инструкции" | ||
}, { | }, { | ||
href: "/wiki/Контакты", | href: "/wiki/Контакты", | ||
title: "Заголовок 2", | title: "Заголовок 2", | ||
spanText: "Контакты" | spanText: "Контакты" | ||
}]; | }]; | ||
| Строка 48: | Строка 42: | ||
a.href = item.href; | a.href = item.href; | ||
a.title = item.title; | a.title = item.title; | ||
var span = document.createElement("span"); | var span = document.createElement("span"); | ||
span.textContent = item.spanText; | span.textContent = item.spanText; | ||
Версия от 14:33, 14 мая 2024
if (document.readyState !== 'loading') {
console.log('document is already ready, just execute code here');
myInitCode();
} else {
document.addEventListener('DOMContentLoaded', function () {
console.log('document was not ready, place code here');
myInitCode();
});
}
function myInitCode() {
var node = document.getElementById("content");
var content = document.createElement("ul");
content.classList.add("custom-top-menu");
var items = [{
href: "/wiki/Вики-энциклопедия_университета",
title: "Главная",
spanText: "Главная"
}, {
href: "/wiki/Правила",
title: "Правила",
spanText: "Правила"
}, {
href: "/wiki/Служебная:Все_страницы",
title: "Все страницы",
spanText: "Статьи"
}, {
href: "/wiki/Служебная:Свежие_правки",
title: "Свежие правки",
spanText: "История правок"
}, {
href: "/wiki/Инструкции",
title: "Инструкции",
spanText: "Инструкции"
}, {
href: "/wiki/Контакты",
title: "Заголовок 2",
spanText: "Контакты"
}];
items.forEach(function (item) {
var li = document.createElement("li");
var a = document.createElement("a");
a.href = item.href;
a.title = item.title;
var span = document.createElement("span");
span.textContent = item.spanText;
a.appendChild(span);
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 = link.getAttribute('href').trim();
console.log(currentPageHref + '=' + linkhref);
if (currentPageHref.indexOf(linkhref) > -1) {
link.closest('li').classList.add('a-current');
}
});
}