Skip to content

Instantly share code, notes, and snippets.

@wilik16
Created December 21, 2025 05:18
Show Gist options
  • Select an option

  • Save wilik16/bb723315c23a8466038a4a6a16554f2f to your computer and use it in GitHub Desktop.

Select an option

Save wilik16/bb723315c23a8466038a4a6a16554f2f to your computer and use it in GitHub Desktop.
var ignore = ""; // domain to ignore (leave empty to always run)
function triggerNotification() {
// Create notification
const notification = document.createElement("div");
notification.className = "notification";
const loader = document.createElement("div");
loader.className = "loader";
const message = document.createElement("span");
message.textContent = "Loading...";
notification.appendChild(loader);
notification.appendChild(message);
document.body.appendChild(notification);
// Show notification
setTimeout(() => {
notification.classList.add("show");
}, 100);
updateLinks(() => {
// Success state
loader.remove();
message.textContent = "Links Updated";
notification.classList.add("success");
// Hide notification
setTimeout(() => {
notification.classList.remove("show");
notification.addEventListener("transitionend", () => {
notification.remove();
});
}, 2000);
});
}
function updateLinks(callback) {
const services = document.querySelectorAll(".service");
const currentHost = window.location.hostname; // no port
services.forEach(service => {
const links = service.querySelectorAll("a");
links.forEach(link => {
try {
// Ensure absolute URL parsing
// console.log('url', url);
console.log('href', link.href);
console.log('ori', window.location.origin);
const url = new URL(link.href, window.location.origin);
// Only replace when hostname is exactly "<home>"
if (url.hostname === "home.pi") {
url.hostname = currentHost;
link.href = url.toString();
}
} catch (e) {
// Ignore invalid URLs
}
});
});
if (callback) callback();
}
window.addEventListener("load", () => {
if (ignore && window.location.hostname === ignore) return;
triggerNotification();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment