Created
January 7, 2024 19:45
-
-
Save driversti/e8f8d73a72e0c8a8db019a1dd6ae4ce5 to your computer and use it in GitHub Desktop.
Filter out posts you don't like
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 eRepublik Post Filter | |
// @version 1.1 | |
// @description FIlter out post you don't like specifying keywords (banned words) | |
// @author driversti https://www.erepublik.com/en/citizen/profile/4690052 | |
// @match https://www.erepublik.com/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js | |
// @run-at document-end | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=erepublik.com | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const bannedWords = [ | |
"wordle","Congratulations, you entered the Top 100","*♥♥*" | |
]; // Add the words you want to filter out. | |
function filterPosts() { | |
$(".postContainer").each(function () { | |
if ($(this).hasClass('autoPost')) { | |
$(this).remove(); // Remove the auto post from the DOM | |
} else { | |
let postContent = $(this).find(".contentMessage").text().toLowerCase(); // get the post content and make it lower case | |
for (let word of bannedWords) { | |
if (postContent.includes(word.toLowerCase())) { | |
$(this).remove(); // Remove the post from the DOM if it includes any banned word | |
break; | |
} | |
} | |
} | |
}); | |
} | |
function setPostFilter() { | |
filterPosts(); // Initial filtering | |
let observer = new MutationObserver(filterPosts); | |
// configuration of the observer: | |
let config = {childList: true, subtree: true}; | |
// pass in the target node, as well as the observer options | |
let targetNode = document.querySelector(".postsWrapper"); | |
if (targetNode) { | |
observer.observe(targetNode, config); | |
} else { | |
console.log("Could not find target node for MutationObserver"); | |
} | |
} | |
$(window).on("load", function () { | |
// wait for the ".postsWrapper" element to appear | |
new MutationObserver(function(mutations, observer) { | |
if (document.querySelector(".postsWrapper")) { | |
setPostFilter(); | |
observer.disconnect(); // stop observing when the element has been found | |
} | |
}).observe(document.body, {childList: true, subtree: true}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment