use mutation observer
Anirudh Oppiliappan x@icyphox.sh
Fri, 15 Mar 2024 12:03:06 +0200
1 files changed,
19 insertions(+),
10 deletions(-)
jump to
M
views/honkpage.js
→
views/honkpage.js
@@ -549,16 +549,25 @@ curpagestate.arg = me.dataset.pagearg
tophid[curpagestate.name + ":" + curpagestate.arg] = me.dataset.tophid servermsgs[curpagestate.name + ":" + curpagestate.arg] = me.dataset.srvmsg - var mecount = document.getElementById("mecount") - if (mecount.innerHTML == "" ) { - mecount.style.width = "0px" - } else { - mecount.style.width = "18px" - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { - mecount.style.backgroundColor = "var(--bg-page)" - mecount.style.color = "var(--fg-subtle)" - } - } + var mecountobserver = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.type == "childList") { + var m = mutation.target + if (m.innerHTML !== "") { + m.style.width = "18px" + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + m.style.backgroundColor = "var(--bg-page)" + m.style.color = "var(--fg-subtle)" + } + } else { + m.style.width = "0px" + } + } + }) + }) + + mecountobserver.observe(document.getElementById("mecount"), { childList: true }) + var el = document.getElementById("homelink") el.onclick = pageswitcher("home", "") el = document.getElementById("atmelink")