Skip to content

Instantly share code, notes, and snippets.

@wilik16
Last active December 21, 2025 06:30
Show Gist options
  • Select an option

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

Select an option

Save wilik16/06aefb0f147de1c3165d98fbf2785b3a to your computer and use it in GitHub Desktop.
My own version of https://github.com/Skulldorom/Dashboard-dynamic-hostname/blob/main/custom.js (thanks Skulldorom), this replaces the template string with the current domain, useful for when we access the homepage with different IPs (local, tailscale, etc)
var ignore = ""; // domain to ignore (leave empty to always run)
const PLACEHOLDER_HOST = "";
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 replaceHostnameIfPlaceholder(urlString) {
try {
const url = new URL(urlString, window.location.origin);
if (url.hostname === PLACEHOLDER_HOST) {
url.hostname = window.location.hostname;
return url.toString();
}
} catch (e) {
// ignore invalid URLs
}
return null;
}
function updateLinks(callback) {
const services = document.querySelectorAll(".service");
services.forEach(service => {
const links = service.querySelectorAll("a");
links.forEach(link => {
// Update <a href>
if (link.href) {
const newHref = replaceHostnameIfPlaceholder(link.href);
if (newHref) link.href = newHref;
}
// Update <img src> inside <a>
const img = link.querySelector("img");
if (img && img.src) {
const newSrc = replaceHostnameIfPlaceholder(img.src);
if (newSrc) img.src = newSrc;
}
});
});
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