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
) => {
48 changeDownpage(selectedComment
.nextElementSibling
);
49 } while (selectedComment
.classList
.contains("noshow"));
53 changeUppage(selectedComment
.previousElementSibling
);
54 } while (selectedComment
.classList
.contains("noshow"));
58 let togg
= selectedComment
.querySelector(".togg");
59 let more
= selectedComment
.querySelector(".morelink");
68 while (selectedComment
.querySelector("td.ind").firstElementChild
.width
!= 0) {
69 changeUppage(selectedComment
.previousElementSibling
);