Fix chemistry page after FermiChem merge
This commit is contained in:
parent
20971ee185
commit
8583fc3b70
3 changed files with 25 additions and 10 deletions
|
@ -10,6 +10,7 @@ import { welcomeScript } from "./pages/welcome";
|
|||
export const PAGE_VERSIONS = {
|
||||
Infections: "fcebeda2fddb46d924f4538cd9c0daeb55aa4c9b",
|
||||
Guide_to_food_and_drinks: "131e010df66ed689d31df53c3ca17ad16635a827",
|
||||
Guide_to_chemistry: "20971ee185888fd37128bdc1c097a740982e94b2",
|
||||
$DEFAULT: "bb7abd544a19369d4b6b7e3dde3eb3cc34c023d4",
|
||||
};
|
||||
|
||||
|
|
|
@ -54,12 +54,6 @@ export function processChemistry(root: HTMLElement): void {
|
|||
}
|
||||
});
|
||||
|
||||
// Remove "Removed medicines" section
|
||||
const remTable = root.querySelector(
|
||||
"#Non-craftable_Medicines + h4 + p + div"
|
||||
);
|
||||
remTable.parentElement.removeChild(remTable);
|
||||
|
||||
// Restructure recipes to work in a narrow window
|
||||
root
|
||||
.querySelectorAll<HTMLElement>("div[data-name] .wikitable.sortable tr")
|
||||
|
@ -82,28 +76,34 @@ export function processChemistry(root: HTMLElement): void {
|
|||
return;
|
||||
}
|
||||
const rows = Array.from(row.querySelectorAll("td")).slice(1);
|
||||
let ph: HTMLTableCellElement = null;
|
||||
let treatment: HTMLTableCellElement = null;
|
||||
let desc: HTMLTableCellElement = null;
|
||||
let metabolism: HTMLTableCellElement = null;
|
||||
let overdose: HTMLTableCellElement = null;
|
||||
let addiction: HTMLTableCellElement = null;
|
||||
// Handle special cases
|
||||
console.log(section);
|
||||
switch (section) {
|
||||
case "Components":
|
||||
[ph, desc] = rows;
|
||||
break;
|
||||
case "Virology Recipes":
|
||||
[desc] = rows;
|
||||
break;
|
||||
case "Narcotics":
|
||||
[desc, metabolism, overdose, addiction] = rows;
|
||||
[ph, desc, metabolism, overdose, addiction] = rows;
|
||||
break;
|
||||
case "Other Reagents":
|
||||
[ph, desc, metabolism] = rows;
|
||||
break;
|
||||
case "Explosive Strength":
|
||||
case "Other Reagents":
|
||||
case "Mutation Toxins":
|
||||
[desc, metabolism] = rows;
|
||||
break;
|
||||
default:
|
||||
// All fields
|
||||
[treatment, desc, metabolism, overdose, addiction] = rows;
|
||||
[ph, treatment, desc, metabolism, overdose, addiction] = rows;
|
||||
}
|
||||
const title = row.querySelector("th");
|
||||
let content = `<div class="reagent-header">${title.innerHTML}</div>`;
|
||||
|
@ -122,6 +122,9 @@ export function processChemistry(root: HTMLElement): void {
|
|||
if (desc) {
|
||||
content += `<p>${desc.innerHTML}</p>`;
|
||||
}
|
||||
if (ph) {
|
||||
content += `<p class="ph">${ph.innerHTML}</p>`;
|
||||
}
|
||||
title.classList.add("reagent-ext");
|
||||
title.innerHTML = content;
|
||||
if (desc) desc.parentElement.removeChild(desc);
|
||||
|
@ -129,6 +132,7 @@ export function processChemistry(root: HTMLElement): void {
|
|||
if (metabolism) metabolism.parentElement.removeChild(metabolism);
|
||||
if (overdose) overdose.parentElement.removeChild(overdose);
|
||||
if (addiction) addiction.parentElement.removeChild(addiction);
|
||||
if (ph) ph.parentElement.removeChild(ph);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -187,6 +191,12 @@ export function chemistryScript(root: HTMLElement): void {
|
|||
"table.wikitable > tbody > tr:not(:first-child)"
|
||||
)
|
||||
);
|
||||
const test = el
|
||||
.map((element, id) => [
|
||||
element,
|
||||
element.querySelector("th .reagent-header"),
|
||||
])
|
||||
.filter(([a, b]) => !b);
|
||||
registerSearchEntries(
|
||||
el.map((element, id) => ({
|
||||
page: "Guide_to_chemistry",
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { findParent } from "../utils";
|
||||
import { darken, ColorFmt, lighten } from "../darkmode";
|
||||
|
||||
function isHeader(nodeName: string) {
|
||||
return nodeName === "H1" || nodeName === "H2" || nodeName === "H3";
|
||||
}
|
||||
|
||||
export function processGlobal(root: HTMLElement, docname: string): void {
|
||||
// Add header
|
||||
const header = document.createElement("h1");
|
||||
|
@ -79,7 +83,7 @@ export function processGlobal(root: HTMLElement, docname: string): void {
|
|||
const parent = h3.parentNode;
|
||||
const div = document.createElement("div");
|
||||
parent.insertBefore(div, h3);
|
||||
while (h3.nextSibling && !h3.nextSibling.nodeName.startsWith("H")) {
|
||||
while (h3.nextSibling && !isHeader(h3.nextSibling.nodeName)) {
|
||||
const sibling = h3.nextSibling;
|
||||
parent.removeChild(sibling);
|
||||
div.appendChild(sibling);
|
||||
|
|
Reference in a new issue