Last active
December 15, 2023 20:33
-
-
Save Tyhjakuori/b83e16eac3cf6c1c6afd84f914a678c0 to your computer and use it in GitHub Desktop.
Hide reddit articles kbin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hide reddit articles kbin | |
// @version 0.1 | |
// @description Hide articles mentioning reddit on kbin | |
// @author Tyhjakuori | |
// @match https://kbin.social/* | |
// @match https://fedia.io/* | |
// @match https://karab.in/* | |
// @match https://www.kbin.cafe/* | |
// @grant none | |
// @updateURL https://gist.github.com/Tyhjakuori/b83e16eac3cf6c1c6afd84f914a678c0/raw | |
// ==/UserScript== | |
"use strict"; | |
const redditArticles = document.querySelectorAll("article"); | |
let totalPosts = 0; | |
const redditWord = ["Reddit", "reddit"]; | |
const hideRedditArticles = () => { | |
if (redditArticles.length === totalPosts) return; | |
totalPosts = redditArticles.length; | |
let wordGex = new RegExp(redditWord.join("|")); | |
Array.from(redditArticles).forEach((article) => { | |
if (wordGex.test(article.textContent.trim())) { | |
console.log("Found reddit post"); | |
article.style.display = "none"; | |
} | |
}); | |
}; | |
hideRedditArticles(); | |
const observer = new MutationObserver(resetTimer); | |
let timer = setTimeout(action, 3000, observer); | |
observer.observe(document, { | |
childList: true, | |
subtree: true, | |
characterData: true, | |
attributes: true, | |
}); | |
// reset timer every time something changes | |
function resetTimer(changes, observer) { | |
clearTimeout(timer); | |
timer = setTimeout(action, 3000, observer); | |
} | |
function action(observer) { | |
observer.disconnect(); | |
hideRedditArticles(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment