|
| 1 | +document.addEventListener("DOMContentLoaded", () => { |
| 2 | + const toc = document.querySelector("#pst-page-toc-nav") || |
| 3 | + document.querySelector(".bd-toc-nav"); |
| 4 | + if (!toc) return; |
| 5 | + |
| 6 | + // Get all TOC links |
| 7 | + const links = toc.querySelectorAll("a"); |
| 8 | + |
| 9 | + const seen = new Set(); |
| 10 | + links.forEach(link => { |
| 11 | + let text = link.textContent.trim(); |
| 12 | + let norm = text.replace(/\(\)$/, ""); // strip trailing () |
| 13 | + |
| 14 | + if (seen.has(norm)) { |
| 15 | + // hide duplicate |
| 16 | + link.parentElement.style.display = "none"; |
| 17 | + } else { |
| 18 | + seen.add(norm); |
| 19 | + } |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | +document.addEventListener("DOMContentLoaded", () => { |
| 24 | + const toc = document.querySelector(".toctree-wrapper"); |
| 25 | + if (!toc) return; |
| 26 | + |
| 27 | + const leaf_traversal_fn = (leaf) => { |
| 28 | + try { |
| 29 | + const links = leaf.querySelectorAll("a"); |
| 30 | + if (!links) return; |
| 31 | + const seen = new Set(); |
| 32 | + links.forEach(link => { |
| 33 | + let text = link.textContent.trim(); |
| 34 | + let norm = text.replace(/\(\)$/, ""); // strip trailing () |
| 35 | + |
| 36 | + if (seen.has(norm)) { |
| 37 | + // hide duplicate |
| 38 | + link.parentElement.style.display = "none"; |
| 39 | + } else { |
| 40 | + seen.add(norm); |
| 41 | + } |
| 42 | + }); |
| 43 | + } catch (error) { |
| 44 | + console.error(error); |
| 45 | + } |
| 46 | + }; |
| 47 | + queue = [toc.querySelector("li")]; |
| 48 | + while (queue.length > 0) { |
| 49 | + const tree = queue.shift(); |
| 50 | + try { |
| 51 | + if (tree.childElementCount > 1 && |
| 52 | + tree.firstChild.hasAttribute("href") && |
| 53 | + tree.firstChild.attributes["href"].value.includes("#")) { |
| 54 | + leaf_traversal_fn(tree.childNodes[1]); |
| 55 | + } else { |
| 56 | + const child = tree.querySelector("li"); |
| 57 | + if (child) { |
| 58 | + queue.push(child); |
| 59 | + } |
| 60 | + } |
| 61 | + } catch (error) { |
| 62 | + console.error(error); |
| 63 | + } |
| 64 | + if (tree.nextElementSibling) { |
| 65 | + queue.push(tree.nextElementSibling); |
| 66 | + } |
| 67 | + } |
| 68 | + }); |
0 commit comments