diff --git a/content.js b/content.js index 89fc613..7e9672f 100644 --- a/content.js +++ b/content.js @@ -235,7 +235,9 @@ } const isCore = CORE_MENU_SLUGS.has(hrefRel); - const isCurrent = keep.has(hrefRel) || link.classList.contains('current'); + const isCurrent = keep.has(hrefRel) || + link.classList.contains('current') || + li.classList.contains('wp-has-current-submenu'); // Mark with data attributes for CSS targeting if (isCore) { @@ -259,17 +261,24 @@ // Handle submenu items const submenu = li.querySelector('.wp-submenu'); if (submenu && (isCore || isCurrent)) { - cleanSubmenu(submenu, allowed, keep); + const showAllItems = li.classList.contains('wp-has-current-submenu'); + cleanSubmenu(submenu, allowed, keep, showAllItems); } }); // CSS is now handled by content.css file injected by manifest } - function cleanSubmenu(submenu, allowed, currentSlugs) { + function cleanSubmenu(submenu, allowed, currentSlugs, showAll = false) { // Mark submenu items with data attributes for CSS targeting const submenuItems = submenu.querySelectorAll('li'); submenuItems.forEach((li) => { + // If showAll is true, mark all items as core to keep them visible + if (showAll) { + li.setAttribute('data-vgp-core', 'true'); + return; + } + const link = li.querySelector('a'); if (!link) { // If no link, mark as core to be safe @@ -290,17 +299,17 @@ } const isCore = allowed.has(hrefRel); - const isCurrent = currentSlugs.has(hrefRel) || + const isCurrent = currentSlugs.has(hrefRel) || link.classList.contains('current') || li.classList.contains('current'); - + // Mark with data attributes for CSS targeting if (isCore) { li.setAttribute('data-vgp-core', 'true'); } else { li.removeAttribute('data-vgp-core'); } - + if (isCurrent) { li.setAttribute('data-vgp-current', 'true'); } else {