用户:Mdtwikibot/首页导航.js
来自Mindustry中文wiki
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* Append as a separately marked block after sandbox verification. */
(function () {
mw.hook('wikipage.content').add(function ($content) {
$content.find('.mdt-home .nav-item').each(function () {
var item = this, list = item.querySelector('.nav-sub'), row = item.querySelector('.nav-row');
if (!list || !row || row.querySelector('.nav-toggle')) return;
var button = document.createElement('button');
button.type = 'button'; button.className = 'nav-toggle';
list.id = 'mdt-nav-' + Math.random().toString(36).slice(2);
var label = row.textContent.trim();
button.setAttribute('aria-controls', list.id);
button.setAttribute('aria-expanded', 'false');
button.setAttribute('aria-label', '展开' + label + '次级导航');
button.innerHTML = '<span aria-hidden="true">›</span>';
list.hidden = true; row.appendChild(button);
button.addEventListener('click', function () {
var expanded = button.getAttribute('aria-expanded') !== 'true';
button.setAttribute('aria-expanded', String(expanded));
button.setAttribute('aria-label', (expanded ? '收起' : '展开') + label + '次级导航');
list.hidden = !expanded; item.classList.toggle('open', expanded);
});
});
});
}());
