Fix dialog spacing and mini refactor
This commit is contained in:
parent
377a549d17
commit
1591dc013b
2 changed files with 37 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { darken, ColorFmt, lighten } from "./darkmode";
|
import { darken, ColorFmt, lighten } from "./darkmode";
|
||||||
import searchBox from "./search";
|
import searchBox from "./search";
|
||||||
|
import { findParent } from "./utils";
|
||||||
|
|
||||||
export default function userscript(root: HTMLElement, docname: string): void {
|
export default function userscript(root: HTMLElement, docname: string): void {
|
||||||
root.querySelectorAll(".mw-editsection").forEach((editLink) => {
|
root.querySelectorAll(".mw-editsection").forEach((editLink) => {
|
||||||
|
@ -45,6 +46,15 @@ export default function userscript(root: HTMLElement, docname: string): void {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fixup spacing on top quotes
|
||||||
|
root
|
||||||
|
.querySelectorAll<HTMLImageElement>("table .floatright > a > img")
|
||||||
|
.forEach((img) => {
|
||||||
|
const row = findParent(img, (el) => el instanceof HTMLTableRowElement);
|
||||||
|
const td = document.createElement("td");
|
||||||
|
row.appendChild(td);
|
||||||
|
});
|
||||||
|
|
||||||
// Group headers and content so stickies don't overlap
|
// Group headers and content so stickies don't overlap
|
||||||
root.querySelectorAll("h3,h2").forEach((h3) => {
|
root.querySelectorAll("h3,h2").forEach((h3) => {
|
||||||
const parent = h3.parentNode;
|
const parent = h3.parentNode;
|
||||||
|
@ -60,17 +70,16 @@ export default function userscript(root: HTMLElement, docname: string): void {
|
||||||
div.className = "mw-headline-cont";
|
div.className = "mw-headline-cont";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Move id from header to container, if one is found
|
||||||
root.querySelectorAll<HTMLElement>(".mw-headline").forEach((span) => {
|
root.querySelectorAll<HTMLElement>(".mw-headline").forEach((span) => {
|
||||||
// Find nearest container
|
// Find nearest container
|
||||||
let parent = span.parentElement;
|
const container = findParent(span, (el) =>
|
||||||
while (parent !== null) {
|
el.classList.contains("mw-headline-cont")
|
||||||
if (parent.classList.contains("mw-headline-cont")) {
|
);
|
||||||
parent.id = span.id;
|
if (container) {
|
||||||
|
container.id = span.id;
|
||||||
span.id += "-span";
|
span.id += "-span";
|
||||||
parent.dataset.name = span.innerText;
|
container.dataset.name = span.innerText;
|
||||||
return;
|
|
||||||
}
|
|
||||||
parent = parent.parentElement;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -216,10 +225,10 @@ export default function userscript(root: HTMLElement, docname: string): void {
|
||||||
root
|
root
|
||||||
.querySelectorAll<HTMLElement>("div[data-name] .wikitable.sortable tr")
|
.querySelectorAll<HTMLElement>("div[data-name] .wikitable.sortable tr")
|
||||||
.forEach((row) => {
|
.forEach((row) => {
|
||||||
let sectionEl = row.parentElement;
|
const sectionEl = findParent(
|
||||||
while (!sectionEl.dataset.name) {
|
row,
|
||||||
sectionEl = sectionEl.parentElement;
|
(sel) => "name" in sel.dataset && sel.dataset.name !== ""
|
||||||
}
|
);
|
||||||
const section = sectionEl.dataset.name;
|
const section = sectionEl.dataset.name;
|
||||||
if (row.querySelector("td") === null) {
|
if (row.querySelector("td") === null) {
|
||||||
// Remove unused rows if found
|
// Remove unused rows if found
|
||||||
|
|
15
lib/utils.ts
Normal file
15
lib/utils.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
export function findParent(
|
||||||
|
base: HTMLElement,
|
||||||
|
matchFn: (candidate: HTMLElement) => boolean
|
||||||
|
): HTMLElement | null {
|
||||||
|
let parent = base.parentElement;
|
||||||
|
while (parent != null) {
|
||||||
|
if (matchFn(parent)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent = parent.parentElement;
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { findParent };
|
Reference in a new issue