|
14 | 14 | } |
15 | 15 |
|
16 | 16 | 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 = []; |
20 | 19 | var node; |
21 | 20 | 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); |
26 | 22 | } |
| 23 | + matches.forEach(function (textNode) { |
| 24 | + textNode.parentNode.replaceChild(createIcon(), textNode); |
| 25 | + }); |
27 | 26 | } |
28 | 27 |
|
29 | 28 | fix(); |
|
32 | 31 |
|
33 | 32 | // The Sapper bundle re-renders this section on hydration and on each |
34 | 33 | // 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, { |
39 | 40 | childList: true, |
40 | 41 | subtree: true, |
41 | 42 | characterData: true, |
|
0 commit comments