all repos — honk @ d8bf028326bf481c89b6842b537c06e3ff391a27

my fork of honk

some hotkeys from zev
Ted Unangst tedu@tedunangst.com
Sat, 26 Aug 2023 14:39:09 -0400
commit

d8bf028326bf481c89b6842b537c06e3ff391a27

parent

987c0bd46c60734fa93bda7cfdf80dbea5695308

2 files changed, 46 insertions(+), 2 deletions(-)

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

@@ -18,8 +18,8 @@ {{ end }}

</div> {{ if and .HonkCSRF (not .IsPreview) }} <div class="info" id="refreshbox"> -<p><button class="refresh">refresh</button><span></span> -<button class="scrolldown">scroll down</button> +<p><button id="honkrefresher" class="refresh">refresh</button><span></span> +<button id="newerscroller" class="scrolldown">scroll down</button> </div> {{ end }} <div id="honksonpage">
M views/honkpage.jsviews/honkpage.js

@@ -416,6 +416,50 @@ el.value = err.message

}, gpsoptions) } } + +function scrollnexthonk() { + var honks = document.getElementsByClassName("honk"); + for (var i = 0; i < honks.length; i++) { + var h = honks[i]; + var b = h.getBoundingClientRect(); + if (b.top > 1.0) { + h.scrollIntoView(); + break; + } + } +} + +function scrollprevioushonk() { + var honks = document.getElementsByClassName("honk"); + for (var i = 1; i < honks.length; i++) { + var b = honks[i].getBoundingClientRect(); + if (b.top > -1.0) { + honks[i-1].scrollIntoView(); + break; + } + } +} + +document.addEventListener("keydown", function(e) { + if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) + return; + + switch (e.code) { + case "KeyR": + refreshhonks(document.getElementById("honkrefresher")); + break; + case "KeyS": + oldestnewest(document.getElementById("newerscroller")); + break; + case "KeyJ": + scrollnexthonk(); + break; + case "KeyK": + scrollprevioushonk(); + break; + } +}) + function addemu(elem) { const data = elem.alt const box = document.getElementById("honknoise");