Wiky.2

Template:Infobox/script.js

document.addEventListener("DOMContentLoaded", function () {

document.querySelectorAll(".content h2").forEach(function (heading) {

if (!heading.textContent.trim().startsWith("Infobox:")) {

return;

}

const title = heading.textContent

.trim()

.substring("Infobox:".length)

.trim();

const infobox = document.createElement("div");

infobox.className = "infobox";

const titleElement = document.createElement("div");

titleElement.className = "infobox-title";

titleElement.textContent = title;

infobox.appendChild(titleElement);

let element = heading.nextElementSibling;

while (element && element.tagName === "P") {

const strong = element.querySelector("strong");

if (!strong) {

break;

}

const row = document.createElement("div");

row.className = "infobox-row";

const label = document.createElement("div");

label.className = "infobox-label";

label.textContent = strong.textContent.replace(/:$/, "").trim();

const value = document.createElement("div");

value.className = "infobox-value";

let child = strong.nextSibling;

while (child) {

const next = child.nextSibling;

value.appendChild(child);

child = next;

}

row.appendChild(label);

row.appendChild(value);

infobox.appendChild(row);

const nextElement = element.nextElementSibling;

element.remove();

element = nextElement;

}

heading.replaceWith(infobox);

});

});

Edit
Last updated: 2026-08-20 17:27:45 by Squirrel