Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect page #244

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions link/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Are you sure you want to go to this website?</title>
</head>
<body>
<style>
.button {
background-color: green;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
text-decoration: none;
}

.button:hover {
background-color: darkgreen;
}
.cancel {
background-color: gainsboro !important;
color: black !important;
}
.cancel:hover {
background-color: gray !important;
color: white !important;
}
.hidden {
display: none;
}
</style>
<!-- inject:navbar -->
<div class="box hidden">
<h4>Are you sure you want to go to this website?</h4>
<p>
This is the url:
<span id="url-text" style="text-decoration: underline">undefined</span>
</p>
<div style="display: flex; justify-content: space-evenly">
<a href="/" class="button cancel">Cancel</a>
<a href="#" id="url" class="button">Open</a>
</div>
</div>
<div class="box">
<h4>Go to the home page</h4>
<a href="/" class="button cancel">Home</a>
</div>
<!-- inject:footer -->
<script src="/index.js"></script>
<script>
const url = new URL(window.location.href);
function isValidURL(string) {
try {
new URL(string);
return true;
} catch (e) {
return false;
}
}
const paramValue = url.searchParams.get("urlLink");
if (isValidURL(paramValue)) {
document.getElementsByClassName("box")[0].classList.remove("hidden");
document.getElementsByClassName("box")[1].classList.add("hidden");
document.getElementById("url").href = paramValue;
document.getElementById("url-text").innerText = paramValue;
}
</script>
</body>
</html>
39 changes: 36 additions & 3 deletions src/scripts/replacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ function replace(text) {
.replaceAll(/(@breakfast)+/gim, '<a href="https://github.com/breakfast-for-dinner" style="background-color: #bfb08b;height: 16px;display: inline-block;padding: 5px;margin: -5px 3px;border: 1px solid #fff4d7;border-radius: 10px;color: #ffffff;position: relative;top: 2px; text-decoration: none;"><img src="https://github.com/breakfast-for-dinner.png" width="16px" style="border-radius: 50%;"><span style="top: -2px;margin-left: 3px;margin-right: 3px;position: relative;">breakfast</span></a>')
.replaceAll(/(@rubiidev-18|@rubiidev)+/gim, '<a href="https://github.com/Rubiidev-18" style="background-color: #759cd9;height: 16px;display: inline-block;padding: 5px;margin: -5px 3px;border: 1px solid #d7e8ff;border-radius: 10px;color: #ffffff;position: relative;top: 2px; text-decoration: none;"><img src="https://github.com/rubiidev-18.png" width="16px" style="border-radius: 50%;"><span style="top: -2px;margin-left: 3px;margin-right: 3px;position: relative;">Rubiidev</span></a>')
.replaceAll(/(@nmsderp|@mr_rudy)+/gim, '<a href="https://github.com/nmsderp" style="background-color: #7ad975;height: 16px;display: inline-block;padding: 5px;margin: -5px 3px;border: 1px solid #d7ffe0;border-radius: 10px;color: #ffffff;position: relative;top: 2px; text-decoration: none;"><img src="https://github.com/nmsderp.png" width="16px" style="border-radius: 50%;"><span style="top: -2px;margin-left: 3px;margin-right: 3px;position: relative;">nmsderp</span></a>')

// allow newlines
.replaceAll(/\n/g, "<br>")

function getSecondHalf(str, coin) {
return str.split(coin).pop()
Expand All @@ -231,8 +232,7 @@ function replace(text) {
}
}

// allow newlines
.replaceAll(/\n/g, "<br>")


for (const emoji of emojis) {
start = String(start).replaceAll(`${emoji.token}`, `<img src='${emoji.url}' alt=':${emoji.emoji}:' style='margin-bottom: -7px;' width='${emojisize}' height='${emojisize}'>`);
Expand Down Expand Up @@ -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);
Loading