add favicon error indicator

This commit is contained in:
sinyo-matu 2023-05-06 17:31:01 +09:00
parent acba0733db
commit 5dfc80b2f2
No known key found for this signature in database
GPG key ID: 247A7D2762CDC85F
4 changed files with 18 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
d2cli/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -28,7 +28,7 @@ function init(reconnectDelay) {
// we can't just set `d2SVG.innerHTML = msg.svg` need to parse this as xml not html
const parsedXML = new DOMParser().parseFromString(msg.svg, "text/xml");
d2SVG.replaceChildren(parsedXML.documentElement);
changeFavicon("./static/favicon.ico");
const svgEl = d2SVG.querySelector("#d2-svg");
// just use inner SVG in watch mode
svgEl.parentElement.replaceWith(svgEl);
@ -56,6 +56,7 @@ function init(reconnectDelay) {
if (msg.err) {
d2ErrDiv.innerText = msg.err;
d2ErrDiv.style.display = "block";
changeFavicon("./static/favicon-err.ico");
d2ErrDiv.scrollIntoView();
}
};
@ -73,3 +74,18 @@ function init(reconnectDelay) {
}, reconnectDelay);
};
}
const changeFavicon = function (iconURL) {
const head = document.getElementsByTagName("head")[0];
const newLink = document.createElement("link");
newLink.rel = "icon";
newLink.href = iconURL;
removeExistingFavicons();
head.appendChild(newLink);
};
const removeExistingFavicons = function () {
const links = document.getElementsByTagName("link");
Array.from(links)
.filter((link) => /\bicon\b/i.test(link.getAttribute("rel")))
.forEach((link) => link.remove());
};

View file

@ -429,6 +429,7 @@ func (w *watcher) handleRoot(hw http.ResponseWriter, r *http.Request) {
<title>%s</title>
<script src="./static/watch.js"></script>
<link rel="stylesheet" href="./static/watch.css">
<link rel="icon" href="./static/favicon.ico">
</head>
<body data-d2-dev-mode=%t>
<div id="d2-err" style="display: none"></div>