From 2c5a05137615a2fe3e0c573aaad85ccbff6f422d Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 26 Aug 2023 14:39:09 -0400 Subject: [PATCH] some hotkeys from zev --- views/honkpage.html | 4 ++-- views/honkpage.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/views/honkpage.html b/views/honkpage.html index cbb1565..15d4b96 100644 --- a/views/honkpage.html +++ b/views/honkpage.html @@ -18,8 +18,8 @@ {{ if and .HonkCSRF (not .IsPreview) }}
-

- +

+

{{ end }}
diff --git a/views/honkpage.js b/views/honkpage.js index 3e22cd2..f94cd21 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -416,6 +416,50 @@ function fillcheckin() { }, 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");