Block lemmy instances

Remove posts and comments from specified instances.

当前为 2023-06-23 提交的版本,查看 最新版本

// ==UserScript==
// @name         Block lemmy instances
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Remove posts and comments from specified instances.
// @author       RyanHx
// @match        https://vlemmy.net/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const target = document.getElementById("app");
    const config = { attributes: false, childList: true, subtree: true };
    const callback = (mutationList, observer) => {
        const blockedInstances = ["example.ml","anotherexample.world"];
        const getLinks = () => {
            const newLinks = [];
            for (const instance of blockedInstances) {
                newLinks.push(...document.querySelectorAll(`div.post-listing a[title$="${instance}"], div.comment a[title$="${instance}"]`));
            }
            return newLinks;
        }
        let links = getLinks();
        while (links.length > 0) {
            const post = links.shift().closest("div.post-listing, div.comment");
            const divider = post.nextElementSibling;
            post.remove();
            console.log("Removed post.");
            if (divider?.nodeName === "HR") {
                divider.remove();
            }
            links = getLinks();
        }
    }
    const observer = new MutationObserver(callback);
    observer.observe(target, config);
})();