happy cakeday is stupid and doesn't add anything to discussion at all, this script hide those comment and succeeding replies (for some post it doesn't work)
当前为
// ==UserScript==
// @name Reddit removes "happy cakeday" comment
// @namespace https://github.com/GitEin11
// @version 1.0
// @description happy cakeday is stupid and doesn't add anything to discussion at all, this script hide those comment and succeeding replies (for some post it doesn't work)
// @author ein
// @match https://www.reddit.com/*
// @grant none
// @license MIT
// @run-at document-idle
// ==/UserScript==
// Define the keywords to match
const keywords = ["cakeday", "cake day", "happy cake", "and my axe"];
function containsKeyword(str) {
str = str.toLowerCase();
for (let keyword of keywords) {
if (str.includes(keyword)) {
return true;
}
}
return false;
}
function processComments() {
let elements = document.querySelectorAll("._1qeIAgB0cPwnLhDF9XSiJM, ._7T4UafM1PdBGycd5na9nF");
for (let element of elements) {
let html = element.innerHTML;
if (containsKeyword(html)) {
let grandparent = element.closest("._3sf33-9rVAO_v4y0pIW_CH").parentElement.parentElement.parentElement;
let grandchild = grandparent.querySelector("._3sf33-9rVAO_v4y0pIW_CH");
let paddingLeft = parseInt(window.getComputedStyle(grandchild).paddingLeft);
let newgrandparent = grandparent.nextElementSibling;
grandparent.style.display = "none";
while (newgrandparent) {
let newgrandchild = newgrandparent.querySelector("._3sf33-9rVAO_v4y0pIW_CH");
let newPaddingLeft = parseInt(window.getComputedStyle(newgrandchild).paddingLeft);
if (newPaddingLeft > paddingLeft) {
newgrandparent.style.display = "none";
}
else {
break;
}
newgrandparent = newgrandparent.nextElementSibling;
}
}
}
}
processComments()
document.addEventListener("DOMNodeInserted", processComments);