all repos — honk @ 1a6d7ff9a8960ce83b3ec36be42317fe5f2ef88d

my fork of honk

rework mecount script
Anirudh Oppiliappan x@icyphox.sh
Wed, 10 Jul 2024 14:30:46 +0300
commit

1a6d7ff9a8960ce83b3ec36be42317fe5f2ef88d

parent

24ca3b753ef34752f2549e4528ffc067a17a4dcc

4 files changed, 25 insertions(+), 18 deletions(-)

jump to
M views/honkpage.htmlviews/honkpage.html

@@ -12,6 +12,7 @@ </div>

</div> {{ if .HonkCSRF }} {{ template "honkform.html" . }} +<script src="/mecount.js"></script> <script src="/honkpage.js{{ .JSParam }}" defer data-csrf="{{ .HonkCSRF }}" data-pagename="{{ .PageName }}" data-pagearg="{{ .PageArg }}" data-tophid="{{ .TopHID }}" data-srvmsg="{{ .ServerMessage }}"></script> {{ end }} {{ if .LocalJSParam }}
M views/honkpage.jsviews/honkpage.js

@@ -549,24 +549,6 @@ curpagestate.arg = me.dataset.pagearg

tophid[curpagestate.name + ":" + curpagestate.arg] = me.dataset.tophid servermsgs[curpagestate.name + ":" + curpagestate.arg] = me.dataset.srvmsg - 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", "")
A views/mecount.js

@@ -0,0 +1,22 @@

+document.addEventListener('DOMContentLoaded', function() { + 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" + } + + document.title = document.title + " (" + m.innerHTML + ")" + } + }) + }) + + mecountobserver.observe(document.getElementById("mecount"), { childList: true }) +});
M web.goweb.go

@@ -3124,6 +3124,7 @@ assets := []string{

viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js", + viewDir + "/views/mecount.js", viewDir + "/views/misc.js", dataDir + "/views/local.js", viewDir + "/views/manifest.webmanifest",

@@ -3186,6 +3187,7 @@

getters.HandleFunc("/style.css", serveviewasset) getters.HandleFunc("/sw.js", serveviewasset) getters.HandleFunc("/honkpage.js", serveviewasset) + getters.HandleFunc("/mecount.js", serveviewasset) getters.HandleFunc("/misc.js", serveviewasset) getters.HandleFunc("/local.css", servedataasset) getters.HandleFunc("/local.js", servedataasset)