Restore Navigator top menu entry
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Menu="Navigator"
|
||||
Menu="Tools"
|
||||
Title="U-Navigator"
|
||||
Icon="u-navigator/u-navigator.svg"
|
||||
---
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
Menu="Buttons:99"
|
||||
Title="Navigator"
|
||||
Icon="icon-u-folder"
|
||||
Code="f07b"
|
||||
---
|
||||
<script>
|
||||
(() => {
|
||||
const targetHref = '/Tools/U-Navigator';
|
||||
const targetText = 'NAVIGATOR';
|
||||
|
||||
function normalize(text) {
|
||||
return String(text || '').trim().toUpperCase();
|
||||
}
|
||||
|
||||
function injectUNavigatorNav() {
|
||||
if (document.querySelector('a[href="/Tools/U-Navigator"], a[data-u-navigator-nav="true"]')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const links = [...document.querySelectorAll('a')];
|
||||
const toolsLink = links.find((link) => {
|
||||
const text = normalize(link.textContent);
|
||||
const href = link.getAttribute('href') || '';
|
||||
return text === 'WERKZEUGE' || text === 'TOOLS' || href === '/Tools';
|
||||
});
|
||||
|
||||
if (!toolsLink) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wrapper = toolsLink.parentElement?.tagName === 'LI' ? toolsLink.parentElement : toolsLink;
|
||||
const isListItem = wrapper.tagName === 'LI';
|
||||
const item = isListItem ? document.createElement('li') : document.createElement('a');
|
||||
const link = isListItem ? document.createElement('a') : item;
|
||||
link.className = toolsLink.className || '';
|
||||
link.href = targetHref;
|
||||
link.textContent = targetText;
|
||||
link.setAttribute('data-u-navigator-nav', 'true');
|
||||
link.classList.remove('active', 'selected', 'on');
|
||||
|
||||
if (isListItem) {
|
||||
item.className = wrapper.className || '';
|
||||
item.classList.remove('active', 'selected', 'on');
|
||||
item.appendChild(link);
|
||||
}
|
||||
|
||||
if (location.pathname === targetHref) {
|
||||
toolsLink.classList.remove('active', 'selected', 'on');
|
||||
wrapper.classList?.remove('active', 'selected', 'on');
|
||||
link.classList.add('active');
|
||||
item.classList?.add('active');
|
||||
}
|
||||
|
||||
wrapper.insertAdjacentElement('afterend', item);
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', injectUNavigatorNav);
|
||||
} else {
|
||||
injectUNavigatorNav();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user