diff --git a/link/index.html b/link/index.html new file mode 100644 index 00000000..ae87ee01 --- /dev/null +++ b/link/index.html @@ -0,0 +1,73 @@ + + + + + + Are you sure you want to go to this website? + + + + + +
+

Go to the home page

+ Home +
+ + + + + diff --git a/src/scripts/replacer.js b/src/scripts/replacer.js index 3d8cd45e..444261f5 100644 --- a/src/scripts/replacer.js +++ b/src/scripts/replacer.js @@ -211,7 +211,8 @@ function replace(text) { .replaceAll(/(@breakfast)+/gim, 'breakfast') .replaceAll(/(@rubiidev-18|@rubiidev)+/gim, 'Rubiidev') .replaceAll(/(@nmsderp|@mr_rudy)+/gim, 'nmsderp') - + // allow newlines + .replaceAll(/\n/g, "
") function getSecondHalf(str, coin) { return str.split(coin).pop() @@ -231,8 +232,7 @@ function replace(text) { } } - // allow newlines - .replaceAll(/\n/g, "
") + for (const emoji of emojis) { start = String(start).replaceAll(`${emoji.token}`, `:${emoji.emoji}:`); @@ -267,3 +267,36 @@ if (lang) { } + +// Function to replace external URLs +function replaceExternalUrls() { + const currentDomain = window.location.hostname; + const anchors = document.querySelectorAll('a'); + + anchors.forEach(anchor => { + const link = document.createElement('a'); + link.href = anchor.href; + if (link.hostname && link.hostname !== currentDomain) { + const replacementURL = `/link?urlLink=${anchor.href}`; + anchor.href = replacementURL; + } + }); + } + + // Run the function initially to replace existing external URLs + replaceExternalUrls(); + + // Create a MutationObserver to monitor DOM changes + const observer = new MutationObserver(mutations => { + mutations.forEach(mutation => { + if (mutation.addedNodes.length) { + replaceExternalUrls(); + } + }); + }); + + // Configure the observer to monitor for child elements being added + const config = { childList: true, subtree: true }; + + // Start observing the document body for changes + observer.observe(document.body, config); \ No newline at end of file