add favicon error indicator
This commit is contained in:
parent
acba0733db
commit
5dfc80b2f2
4 changed files with 18 additions and 1 deletions
BIN
d2cli/static/favicon-err.ico
Normal file
BIN
d2cli/static/favicon-err.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
d2cli/static/favicon.ico
Normal file
BIN
d2cli/static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
|
|
@ -28,7 +28,7 @@ function init(reconnectDelay) {
|
||||||
// we can't just set `d2SVG.innerHTML = msg.svg` need to parse this as xml not html
|
// 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");
|
const parsedXML = new DOMParser().parseFromString(msg.svg, "text/xml");
|
||||||
d2SVG.replaceChildren(parsedXML.documentElement);
|
d2SVG.replaceChildren(parsedXML.documentElement);
|
||||||
|
changeFavicon("./static/favicon.ico");
|
||||||
const svgEl = d2SVG.querySelector("#d2-svg");
|
const svgEl = d2SVG.querySelector("#d2-svg");
|
||||||
// just use inner SVG in watch mode
|
// just use inner SVG in watch mode
|
||||||
svgEl.parentElement.replaceWith(svgEl);
|
svgEl.parentElement.replaceWith(svgEl);
|
||||||
|
|
@ -56,6 +56,7 @@ function init(reconnectDelay) {
|
||||||
if (msg.err) {
|
if (msg.err) {
|
||||||
d2ErrDiv.innerText = msg.err;
|
d2ErrDiv.innerText = msg.err;
|
||||||
d2ErrDiv.style.display = "block";
|
d2ErrDiv.style.display = "block";
|
||||||
|
changeFavicon("./static/favicon-err.ico");
|
||||||
d2ErrDiv.scrollIntoView();
|
d2ErrDiv.scrollIntoView();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -73,3 +74,18 @@ function init(reconnectDelay) {
|
||||||
}, 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());
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -429,6 +429,7 @@ func (w *watcher) handleRoot(hw http.ResponseWriter, r *http.Request) {
|
||||||
<title>%s</title>
|
<title>%s</title>
|
||||||
<script src="./static/watch.js"></script>
|
<script src="./static/watch.js"></script>
|
||||||
<link rel="stylesheet" href="./static/watch.css">
|
<link rel="stylesheet" href="./static/watch.css">
|
||||||
|
<link rel="icon" href="./static/favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
<body data-d2-dev-mode=%t>
|
<body data-d2-dev-mode=%t>
|
||||||
<div id="d2-err" style="display: none"></div>
|
<div id="d2-err" style="display: none"></div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue