(function () {
function isNoise(href) {
if (!href) return false;
return /^#(subcommands|options|arguments)(-\d+)?$/.test(href);
}
function dropNoise(root) {
root.querySelectorAll('.header-item').forEach((li) => {
const a = li.querySelector('a.header-in-summary');
if (a && isNoise(a.getAttribute('href'))) li.remove();
});
}
function nestByPrefix(root) {
const items = Array.from(root.querySelectorAll(':scope > .header-item'));
if (items.length === 0) return;
const byTokens = new Map();
items.forEach((li) => {
const a = li.querySelector('a.header-in-summary');
const tokens = (a ? a.textContent : '').trim().split(/\s+/);
li.dataset.tokens = tokens.join(' ');
byTokens.set(tokens.join(' '), li);
});
const sorted = [...items].sort(
(a, b) => b.dataset.tokens.split(' ').length - a.dataset.tokens.split(' ').length,
);
for (const li of sorted) {
const tokens = li.dataset.tokens.split(' ');
if (tokens.length < 2) continue;
for (let len = tokens.length - 1; len >= 1; len--) {
const key = tokens.slice(0, len).join(' ');
const parent = byTokens.get(key);
if (!parent) continue;
let ol = parent.querySelector(':scope > ol.section');
if (!ol) {
ol = document.createElement('ol');
ol.classList.add('section');
parent.appendChild(ol);
}
ol.appendChild(li);
const a = li.querySelector('a.header-in-summary');
if (a) {
const remaining = tokens.slice(len).join(' ');
a.textContent = remaining;
}
break;
}
}
}
function liftRoot(root) {
const rootLi = root.querySelector(':scope > .header-item');
if (!rootLi) return;
const a = rootLi.querySelector('a.header-in-summary');
if (!a || a.textContent.trim() !== 'zenops') return;
const childOl = rootLi.querySelector(':scope > ol.section');
if (childOl) {
for (const child of Array.from(childOl.children)) {
root.appendChild(child);
}
}
rootLi.remove();
}
function cleanup() {
const root = document.querySelector('.on-this-page > ol.section');
if (!root) return;
dropNoise(root);
nestByPrefix(root);
liftRoot(root);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => setTimeout(cleanup, 0));
} else {
setTimeout(cleanup, 0);
}
})();