目次を作る.jsawait (async () => {
if (location.href !== "https://ieyasu03.web.fc2.com/index.html") return;
/**
* @param {Document} fom
* @return {string[]}
*/
const getSubsections = (dom) => {
const main = dom.getElementsByTagName("main")[0];
return [...main.getElementsByTagName("table")]
.flatMap((table) => {
const head = ` ${table.getElementsByTagName("thead")[0].textContent.trim()}`;
const links = [...table.getElementsByTagName("a")]
.map((a) => ` [${a.href} ${a.textContent.trim()}]`);
return [head, ...links];
});
};
const main = document.getElementsByTagName("main")[0];
const body = [];
let section = main.getElementsByTagName("section")[0];
for (const _ of [0, 1, 2]) {
body.push(section.getElementsByTagName("h2")[0].textContent.trim());
const table = section.getElementsByTagName("table")[0];
for (const a of table.getElementsByTagName("a")) {
const dom = new DOMParser().parseFromString(await (await fetch(a.href)).text(),"text/html");
body.push(` [${a.href} ${a.textContent.trim()}]`, ...getSubsections(dom));
}
section = section.querySelector("section.mt-5");
}
console.log(body.join("\n"));
})();