diff --git a/lib/App.tsx b/lib/App.tsx index a559dde..7a7963e 100644 --- a/lib/App.tsx +++ b/lib/App.tsx @@ -5,8 +5,8 @@ import { useState } from "react"; export default function App() { const [tabs, setTabs] = useState([ - { page: "Guide_to_medicine" }, { page: "Guide_to_chemistry" }, + { page: "Guide_to_medicine" }, ]); const [activeTab, setActiveTab] = useState(0); return ( diff --git a/lib/userscript.ts b/lib/userscript.ts index aa02d64..b39aaf1 100644 --- a/lib/userscript.ts +++ b/lib/userscript.ts @@ -263,33 +263,30 @@ export default function (root: HTMLElement, docname: string) { function betterChemistry() { // Fix inconsistencies with

on random parts // Ideally I'd like a

or something on every part, wrapping it completely, but for now let's just kill 'em - new Set( - Array.from( - root.querySelectorAll( - "table.wikitable > tbody > tr:not(:first-child) > td:nth-child(2) p" - ) - ).map((p) => p.parentNode) - ).forEach((parent) => { - const tmp = parent.cloneNode(); - // The cast to Array is necessary because, while childNodes's NodeList technically has a forEach method, it's a live list and operations mess with its lenght in the middle of the loop - // Nodes can only have one parent so append removes them from the original NodeList and shifts the following one back into the wrong index - Array.from(parent.childNodes).forEach((el: HTMLElement) => { - if (el.tagName === "P") { - tmp.append(...el.childNodes); - } else { - tmp.append(el); - } + document + .querySelectorAll( + "table.wikitable > tbody > tr:not(:first-child) > td:nth-child(2)" + ) + .forEach((td) => { + const tmp = td.cloneNode(); + // The cast to Array is necessary because, while childNodes's NodeList technically has a forEach method, it's a live list and operations mess with its lenght in the middle of the loop. + // Nodes can only have one parent so append removes them from the original NodeList and shifts the following one back into the wrong index. + Array.from(td.childNodes).forEach((el) => { + if (el.tagName === "P") { + tmp.append(...el.childNodes); + } else { + tmp.append(el); + } + }); + td.parentNode.replaceChild(tmp, td); }); - parent.parentNode.replaceChild(tmp, parent); - }); // Enrich "x part" with checkboxes and parts - Array.from(root.querySelectorAll("td")) + Array.from(document.querySelectorAll("td")) .filter((el) => el.innerText.indexOf(" part") >= 0) - .map((el) => [el, el.innerHTML]) - .forEach(([el, innerHTML]) => { - el.innerHTML = innerHTML.replace( - /((\d+)\s+(?:parts?|units?))(.*?(?:<\s*(\/\s*a|br\s*\/?)\s*>|\n|$))/gi, + .forEach((el) => { + el.innerHTML = el.innerHTML.replace( + /((\d+)\s+(?:parts?|units?))(.*?(?:<\/a>|\n|$))/gi, (match, ...m) => `