Initial Commit
This commit is contained in:
38
js/normal.js
Normal file
38
js/normal.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Strips ".html" from link text, preserving href.
|
||||
* Idempotent and works for dynamically added links.
|
||||
*
|
||||
* @param {HTMLElement} link - The <a> element to process
|
||||
*/
|
||||
function beautifyLinkText(link) {
|
||||
const originalText = link.dataset.originalText || link.textContent;
|
||||
|
||||
// Only strip if the text ends with ".html"
|
||||
if (originalText.endsWith(".html")) {
|
||||
link.textContent = originalText.replace(/\.html$/, "");
|
||||
}
|
||||
|
||||
// Store original text to avoid double-processing
|
||||
link.dataset.originalText = originalText;
|
||||
}
|
||||
|
||||
// Process all existing links
|
||||
document.querySelectorAll("a").forEach(beautifyLinkText);
|
||||
|
||||
// Observe new links added dynamically
|
||||
const observer = new MutationObserver(mutations => {
|
||||
mutations.forEach(mutation => {
|
||||
mutation.addedNodes.forEach(node => {
|
||||
if (node.nodeType !== 1) return; // Not an element
|
||||
|
||||
if (node.tagName === "A") {
|
||||
beautifyLinkText(node);
|
||||
} else {
|
||||
node.querySelectorAll("a").forEach(beautifyLinkText);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
Reference in New Issue
Block a user