Inject U-Navigator into main navigation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Menu="U-Navigator"
|
||||
Menu="Tools"
|
||||
Title="U-Navigator"
|
||||
Icon="folder-open"
|
||||
---
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
Menu="Buttons:99"
|
||||
Title="U-Navigator"
|
||||
Icon="icon-u-folder"
|
||||
Code="f07b"
|
||||
---
|
||||
<script>
|
||||
(() => {
|
||||
const targetHref = '/Tools/U-Navigator';
|
||||
const targetText = 'U-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 item = wrapper.cloneNode(true);
|
||||
const link = item.tagName === 'A' ? item : item.querySelector('a');
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
|
||||
link.href = targetHref;
|
||||
link.textContent = targetText;
|
||||
link.setAttribute('data-u-navigator-nav', 'true');
|
||||
link.classList.remove('active', 'selected');
|
||||
item.classList?.remove('active', 'selected');
|
||||
wrapper.insertAdjacentElement('afterend', item);
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', injectUNavigatorNav);
|
||||
} else {
|
||||
injectUNavigatorNav();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user