Skip to content

Commit f42b23f

Browse files
committed
chore: update status-icons
1 parent e59f999 commit f42b23f

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

client/status-icon-fix.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
}
1515

1616
function fix() {
17-
var article = document.querySelector("article.up");
18-
if (!article) return;
19-
var walker = document.createTreeWalker(article, NodeFilter.SHOW_TEXT, null);
17+
var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null);
18+
var matches = [];
2019
var node;
2120
while ((node = walker.nextNode())) {
22-
if (node.nodeValue.trim() === "✅") {
23-
node.parentNode.replaceChild(createIcon(), node);
24-
break;
25-
}
21+
if (node.nodeValue.trim() === "✅") matches.push(node);
2622
}
23+
matches.forEach(function (textNode) {
24+
textNode.parentNode.replaceChild(createIcon(), textNode);
25+
});
2726
}
2827

2928
fix();
@@ -32,10 +31,12 @@
3231

3332
// The Sapper bundle re-renders this section on hydration and on each
3433
// data poll, reinstating the emoji text node — watch for that and
35-
// swap it back to the SVG.
36-
var target = document.querySelector("main.container");
37-
if (target && window.MutationObserver) {
38-
new MutationObserver(fix).observe(target, {
34+
// swap it back to the SVG. This script runs from a <script> tag in
35+
// <nav>, before <main> exists, so observe document.body (already
36+
// present when the tag executes) rather than a more specific
37+
// container that isn't in the DOM yet.
38+
if (window.MutationObserver) {
39+
new MutationObserver(fix).observe(document.body, {
3940
childList: true,
4041
subtree: true,
4142
characterData: true,

0 commit comments

Comments
 (0)