Use custom url in case of self-hosted

This commit is contained in:
Nathanaël Houn 2021-11-22 14:30:09 +01:00
parent 21990398c6
commit fde5fda635
No known key found for this signature in database
GPG key ID: 0D645FFDC857D4BE
2 changed files with 30 additions and 18 deletions

View file

@ -12,6 +12,10 @@
let topics = {};
let currentTopic = "";
let currentTopicUnsubscribeOnClose = false;
let currentUrl = window.location.hostname;
if (window.location.port) {
currentUrl += ':' + window.location.port
}
/* Main view */
const main = document.getElementById("main");
@ -131,15 +135,15 @@ const fetchCachedMessages = async (topic) => {
const showDetail = (topic) => {
currentTopic = topic;
history.replaceState(topic, `ntfy.sh/${topic}`, `/${topic}`);
history.replaceState(topic, `${currentUrl}/${topic}`, `/${topic}`);
window.scrollTo(0, 0);
rerenderDetailView();
return false;
};
const rerenderDetailView = () => {
detailTitle.innerHTML = `ntfy.sh/${currentTopic}`; // document.location.replaceAll(..)
detailTopicUrl.innerHTML = `ntfy.sh/${currentTopic}`;
detailTitle.innerHTML = `${currentUrl}/${currentTopic}`; // document.location.replaceAll(..)
detailTopicUrl.innerHTML = `${currentUrl}/${currentTopic}`;
while (detailEventsList.firstChild) {
detailEventsList.removeChild(detailEventsList.firstChild);
}
@ -347,3 +351,11 @@ document.querySelectorAll('.anchor').forEach((el) => {
el.appendChild(anchor);
}
});
// Change ntfy.sh url and protocol to match self-hosted one
document.querySelectorAll('.ntfyUrl').forEach((el) => {
el.innerHTML = currentUrl;
});
document.querySelectorAll('.ntfyProtocol').forEach((el) => {
el.innerHTML = window.location.protocol + "//";
});