From bde0b9f99d70b3718b60d84b18b20761446320f4 Mon Sep 17 00:00:00 2001 From: "Alex Pooley (@zuedev)" Date: Tue, 26 May 2026 05:03:29 +0100 Subject: add replaceWordsWithLinks --- communities/174bg/handbook/public/index.html | 53 ++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'communities') diff --git a/communities/174bg/handbook/public/index.html b/communities/174bg/handbook/public/index.html index 04e42b0..1bb815d 100644 --- a/communities/174bg/handbook/public/index.html +++ b/communities/174bg/handbook/public/index.html @@ -882,9 +882,7 @@ @@ -1195,6 +1193,8 @@ console.log("DOMContentLoaded"); generateTableOfContents(); + + replaceWordsWithLinks(); }); function generateTableOfContents() { @@ -1266,5 +1266,52 @@ } }); } + + function replaceWordsWithLinks() { + const linkMap = { + "Hull C": "https://starcitizen.tools/Hull_C", + "Hull E": "https://starcitizen.tools/Hull_E", + }; + + const walker = document.createTreeWalker( + document.body, + NodeFilter.SHOW_TEXT, + null, + false, + ); + + let node; + while ((node = walker.nextNode())) { + const parent = node.parentNode; + if (parent && parent.tagName !== "A") { + let text = node.textContent; + let replaced = false; + + for (const [word, url] of Object.entries(linkMap)) { + const regex = new RegExp(`\\b${word}\\b`, "g"); + if (regex.test(text)) { + const link = document.createElement("a"); + link.href = url; + link.textContent = word; + text = text.replace(regex, link.outerHTML); + replaced = true; + + console.log( + `Replaced "${word}" with link to ${url} in text: "${node.textContent.trim()}"`, + ); + } + } + + if (replaced) { + const tempDiv = document.createElement("div"); + tempDiv.innerHTML = text; + while (tempDiv.firstChild) { + parent.insertBefore(tempDiv.firstChild, node); + } + parent.removeChild(node); + } + } + } + } -- cgit v1.2.3