Reddit Regex Comment Upvoter | JavaScript

May 17th, 2021 02:47:10 AM

//Upvotes comments according to a regex pattern. I tried it out on //Known bugs: //If a comment was already upvoted, it gets downvoted //For some reason, it has around a 50-70% success rate. The case insensitive bit works, but I think some of the query selector stuff gets changed. Still, 50% is good let comments = document.getElementsByClassName("_3tw__eCCe7j-epNCKGXUKk"); //Comment class let commentsToUpvote = []; const regexToMatch = /wtf/gi; for(let comment of comments){ let text = comment.querySelector("._1qeIAgB0cPwnLhDF9XSiJM"); //Comment content class if(text == undefined){ continue; } text = text.textContent; if(regexToMatch.test(text)){ console.log(text); commentsToUpvote.push(comment); } } function upvote(comment){ console.log(comment.querySelector(".icon-upvote")); //Just showing you what it's doing comment.querySelector(".icon-upvote").click(); } function slowRecurse(){ let comment = commentsToUpvote.pop(); //It's gonna go bottom to top but whatever if(comment != undefined){ upvote(comment); setTimeout(slowRecurse,500); } } slowRecurse();

Featured Posts