2 const comments
= document
.querySelector(".comment-tree > tbody");
4 let selectedComment
= comments
.firstElementChild
5 selectedComment
.style
.outline
= '1px dashed black';
7 const visible
= (element
) => {
8 let bounds
= element
.getBoundingClientRect();
9 return bounds
.top
>= 0 && bounds
.bottom
<= window
.innerHeight
;
12 const changeWithVisibleCallback
= (comment
, callback
) => {
13 if (comment
== null) {
16 selectedComment
.style
.outline
= '';
17 selectedComment
= comment
;
18 selectedComment
.style
.outline
= '1px dashed black';
19 if (!visible(comment
)) {
24 const change
= (comment
) => {
25 changeWithVisibleCallback(comment
, () => {});
28 // Curry callback for moving downpage
29 const changeDownpage
= (comment
) => {
30 changeWithVisibleCallback(comment
, () => {window
.scrollTo(0, window
.scrollY
+ comment
.offsetHeight
)});
33 // Curry callback for moving up page
34 const changeUppage
= (comment
) => {
35 changeWithVisibleCallback(comment
, () => {window
.scrollTo(0, window
.scrollY
- comment
.offsetHeight
)});
38 document
.addEventListener("click", (e
) => {
39 change(e
.target
.closest("tr.athing"));
41 document
.addEventListener("keydown", (e
) => {
47 changeDownpage(selectedComment
.nextElementSibling
);
48 } while (selectedComment
.classList
.contains("noshow"));
52 changeUppage(selectedComment
.previousElementSibling
);
53 } while (selectedComment
.classList
.contains("noshow"));
55 if (e
.key
== "Enter") {
56 let togg
= selectedComment
.querySelector(".togg");
57 let more
= selectedComment
.querySelector(".morelink");