Fix chemistry page after FermiChem merge

This commit is contained in:
Hamcha 2021-02-12 10:28:39 +01:00
parent 20971ee185
commit 8583fc3b70
Signed by: hamcha
GPG Key ID: 41467804B19A3315
3 changed files with 25 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import { welcomeScript } from "./pages/welcome";
export const PAGE_VERSIONS = { export const PAGE_VERSIONS = {
Infections: "fcebeda2fddb46d924f4538cd9c0daeb55aa4c9b", Infections: "fcebeda2fddb46d924f4538cd9c0daeb55aa4c9b",
Guide_to_food_and_drinks: "131e010df66ed689d31df53c3ca17ad16635a827", Guide_to_food_and_drinks: "131e010df66ed689d31df53c3ca17ad16635a827",
Guide_to_chemistry: "20971ee185888fd37128bdc1c097a740982e94b2",
$DEFAULT: "bb7abd544a19369d4b6b7e3dde3eb3cc34c023d4", $DEFAULT: "bb7abd544a19369d4b6b7e3dde3eb3cc34c023d4",
}; };

View File

@ -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 // Restructure recipes to work in a narrow window
root root
.querySelectorAll<HTMLElement>("div[data-name] .wikitable.sortable tr") .querySelectorAll<HTMLElement>("div[data-name] .wikitable.sortable tr")
@ -82,28 +76,34 @@ export function processChemistry(root: HTMLElement): void {
return; return;
} }
const rows = Array.from(row.querySelectorAll("td")).slice(1); const rows = Array.from(row.querySelectorAll("td")).slice(1);
let ph: HTMLTableCellElement = null;
let treatment: HTMLTableCellElement = null; let treatment: HTMLTableCellElement = null;
let desc: HTMLTableCellElement = null; let desc: HTMLTableCellElement = null;
let metabolism: HTMLTableCellElement = null; let metabolism: HTMLTableCellElement = null;
let overdose: HTMLTableCellElement = null; let overdose: HTMLTableCellElement = null;
let addiction: HTMLTableCellElement = null; let addiction: HTMLTableCellElement = null;
// Handle special cases // Handle special cases
console.log(section);
switch (section) { switch (section) {
case "Components": case "Components":
[ph, desc] = rows;
break;
case "Virology Recipes": case "Virology Recipes":
[desc] = rows; [desc] = rows;
break; break;
case "Narcotics": case "Narcotics":
[desc, metabolism, overdose, addiction] = rows; [ph, desc, metabolism, overdose, addiction] = rows;
break;
case "Other Reagents":
[ph, desc, metabolism] = rows;
break; break;
case "Explosive Strength": case "Explosive Strength":
case "Other Reagents":
case "Mutation Toxins": case "Mutation Toxins":
[desc, metabolism] = rows; [desc, metabolism] = rows;
break; break;
default: default:
// All fields // All fields
[treatment, desc, metabolism, overdose, addiction] = rows; [ph, treatment, desc, metabolism, overdose, addiction] = rows;
} }
const title = row.querySelector("th"); const title = row.querySelector("th");
let content = `<div class="reagent-header">${title.innerHTML}</div>`; let content = `<div class="reagent-header">${title.innerHTML}</div>`;
@ -122,6 +122,9 @@ export function processChemistry(root: HTMLElement): void {
if (desc) { if (desc) {
content += `<p>${desc.innerHTML}</p>`; content += `<p>${desc.innerHTML}</p>`;
} }
if (ph) {
content += `<p class="ph">${ph.innerHTML}</p>`;
}
title.classList.add("reagent-ext"); title.classList.add("reagent-ext");
title.innerHTML = content; title.innerHTML = content;
if (desc) desc.parentElement.removeChild(desc); if (desc) desc.parentElement.removeChild(desc);
@ -129,6 +132,7 @@ export function processChemistry(root: HTMLElement): void {
if (metabolism) metabolism.parentElement.removeChild(metabolism); if (metabolism) metabolism.parentElement.removeChild(metabolism);
if (overdose) overdose.parentElement.removeChild(overdose); if (overdose) overdose.parentElement.removeChild(overdose);
if (addiction) addiction.parentElement.removeChild(addiction); 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)" "table.wikitable > tbody > tr:not(:first-child)"
) )
); );
const test = el
.map((element, id) => [
element,
element.querySelector("th .reagent-header"),
])
.filter(([a, b]) => !b);
registerSearchEntries( registerSearchEntries(
el.map((element, id) => ({ el.map((element, id) => ({
page: "Guide_to_chemistry", page: "Guide_to_chemistry",

View File

@ -1,6 +1,10 @@
import { findParent } from "../utils"; import { findParent } from "../utils";
import { darken, ColorFmt, lighten } from "../darkmode"; 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 { export function processGlobal(root: HTMLElement, docname: string): void {
// Add header // Add header
const header = document.createElement("h1"); const header = document.createElement("h1");
@ -79,7 +83,7 @@ export function processGlobal(root: HTMLElement, docname: string): void {
const parent = h3.parentNode; const parent = h3.parentNode;
const div = document.createElement("div"); const div = document.createElement("div");
parent.insertBefore(div, h3); parent.insertBefore(div, h3);
while (h3.nextSibling && !h3.nextSibling.nodeName.startsWith("H")) { while (h3.nextSibling && !isHeader(h3.nextSibling.nodeName)) {
const sibling = h3.nextSibling; const sibling = h3.nextSibling;
parent.removeChild(sibling); parent.removeChild(sibling);
div.appendChild(sibling); div.appendChild(sibling);