From ffe0b2f424c1a01aa565807020ae13933b1c0d4c Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Sun, 20 Oct 2019 18:00:25 -0500 Subject: [PATCH] Initial commit --- README.md | 3 +++ hnim.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ hnim.xpi | Bin 0 -> 8380 bytes manifest.json | 14 +++++++++++ 4 files changed, 83 insertions(+) create mode 100644 README.md create mode 100644 hnim.js create mode 100644 hnim.xpi create mode 100644 manifest.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff7ffdb --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Adds some VIM keybindings to HackerNews comments. + +Download [hnim.xpi](hnim.xpi) diff --git a/hnim.js b/hnim.js new file mode 100644 index 0000000..2ec6a73 --- /dev/null +++ b/hnim.js @@ -0,0 +1,66 @@ +(() => { + const comments = document.querySelector(".comment-tree > tbody"); + + let selectedComment = comments.firstElementChild + selectedComment.style.outline = '1px dashed black'; + + const visible = (element) => { + let bounds = element.getBoundingClientRect(); + return bounds.top >= 0 && bounds.bottom <= window.innerHeight; + } + + const changeWithVisibleCallback = (comment, callback) => { + if (comment == null) { + return; + } + selectedComment.style.outline = ''; + selectedComment = comment; + selectedComment.style.outline = '1px dashed black'; + if (!visible(comment)) { + callback(); + } + } + + const change = (comment) => { + changeWithVisibleCallback(comment, () => {}); + } + + // Curry callback for moving downpage + const changeDownpage = (comment) => { + changeWithVisibleCallback(comment, () => {window.scrollTo(0, window.scrollY + comment.offsetHeight)}); + } + + // Curry callback for moving up page + const changeUppage = (comment) => { + changeWithVisibleCallback(comment, () => {window.scrollTo(0, window.scrollY - comment.offsetHeight)}); + } + + document.addEventListener("click", (e) => { + change(e.target.closest("tr.athing")); + }) + document.addEventListener("keydown", (e) => { + if (e.isComposing) { + return; + } + if (e.key == "j") { + do { + changeDownpage(selectedComment.nextElementSibling); + } while (selectedComment.classList.contains("noshow")); + } + if (e.key == "k") { + do { + changeUppage(selectedComment.previousElementSibling); + } while (selectedComment.classList.contains("noshow")); + } + if (e.key == "Enter") { + let togg = selectedComment.querySelector(".togg"); + let more = selectedComment.querySelector(".morelink"); + if (togg) { + togg.click(); + } + else if (more) { + more.click(); + } + } + }) +})(); diff --git a/hnim.xpi b/hnim.xpi new file mode 100644 index 0000000000000000000000000000000000000000..aff0e738fe78c3779e22f1265ef4083cb6f6f8f4 GIT binary patch literal 8380 zcmaKRWmH|uvNgUp?(XjH!QEYgLvVNZ1ef5!A-Dv~#+~369D>Wng1hVEjQj36=brDo zuX^;4UTbu9&+7V7v!<#7Gz=C5@NN9l0B;|x9c>&~Y~9+wD7nqBp@pB`W5=LY3Dw*3 z18zn4kO0al@nGvwLVcYn0-GGJ-n%Z&=pED~)pxy$tX0$BVmEQUPNgq-k(nMy z``3Agw1}RTJT4+%D&nBu=TCaSM#zes?@N3_DcrDe5)KuArH%Fj+qIN;mPSpFX5z4~ z+4vhu&aOi()F`?x-9}Ovt0vEAQ;10KAemh4lzOQ%&Zoc`p)GvG8ixy!=yWVDqUL$vfD&4Ty$Z%_Iy=_m1D+-Z71YBmfxs_#h z=Hk6YqFMc1GK#j`U9C<4rjkDR$#48Q!JJQHpg)oP{S?b=5D6%d0CXCgJVp?sFIDA7 zKIGSHZI$<;YssJ>t3r~qwNAhqBh5zIOdc}fvOTytnRc!ja2LM> zCLb!z1l*tB=T)E1u$&`yK|?^izN#t!fM4bZ-kU)|Kp4EGp6Y+iOXRn_bok(CV`<^$ z{+63gj*@ZgPCcSXVYiRiDkN$t^~7}^g%bE}n&=3)O+-VU*!ohy^L55JO(v4g)BAlx z3{ei-d(-%1)(IoU@<9bR%y$SHsCrJ(s?_l?LJbqMMTFT4mj;2R=ruFj&X@y(%K~x! zYuGu_fdW0>NiGwABY!1Yl+@`>OSLDc1a)}vU*9Q0IF~n#$F~1wu%7eExfot{<5|Qe z?%n0da%UvSe2wT8YMZAx?zSm=$_yqqoH2d_@Gro^3QPNqZ>xv5`QHKKy!};@(iCHs zQ29QYq4jiOw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v78BTDCi7@!z%$waBvpTseE^^tkInAEZPN9#>w3 zVnuD_JnawQg1F#Nnnj5OheX`rMOa1XA&|fM#i(cgG$n9HdcpJ6ZB=UHE zzF54U_;EZ!JSahD_*BurnD5EDg%wAfLuid8#O_op@I)o<9bIGLXse@f{fl6&;wIyL zzjx=z(xo+uP_jjuCTDE~Fil_1JE*tcyCw%)Wuxnjf&PomZRmjOKfj5FfH!qWRRIzT z3*s-m`|pb5AA0wH+W)HG|J?L<)$R{5@-It&JM_;6#2?b+Kezr}#`;6n`^%!&q;G)!jDo{oq*_%07VeK@0B@uDt-o+W^2h3b0C@v7F#rGn literal 0 HcmV?d00001 diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..f95615d --- /dev/null +++ b/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "HNim", + "version": "0.1", + + "description": "Adds some VIM keybindings to HackerNews comments", + + "content_scripts": [ + { + "matches": ["*://news.ycombinator.com/*"], + "js": ["hnim.js"] + } + ] +} -- 2.20.1