Skip to content

Commit

Permalink
Update bettercomments.user.js
Browse files Browse the repository at this point in the history
v1.1 - support for infinite scroll
  • Loading branch information
Hakorr authored Sep 18, 2023
1 parent 326c687 commit 876a56a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Yle.fi/BetterComments/bettercomments.user.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// ==UserScript==
// @name [Yle] BetterComments
// @name BetterComments
// @match https://yle.fi/*
// @grant none
// @version 1.0
// @version 1.1
// @author HKR
// @namespace HKR
// @description Makes Yle's article comment section better
// @run-at document-load
// ==/UserScript==

function main(commentsContainerElem) {
console.log(commentsContainerElem, commentsContainerElem.childNodes);
const processedTopComments = [];

function main(commentsContainerElem) {
[...commentsContainerElem.childNodes].forEach(topCommentElem => {
if(processedTopComments.includes(topCommentElem)) return;

processedTopComments.push(topCommentElem);

const replyCommentContainerElem = topCommentElem.querySelector('ul');

if(!replyCommentContainerElem) return;
Expand Down Expand Up @@ -68,8 +72,6 @@ const waitForElemInterval = setInterval(() => {
const isFullyLoaded = commentsContainerElem?.childNodes?.length > 0;

if(isFullyLoaded) {
clearInterval(waitForElemInterval);

main(commentsContainerElem);
}
}, 250);

0 comments on commit 876a56a

Please sign in to comment.