Advertisement
Guest User

Block Lemmy Instances adapted to old.lemmy.world

a guest
Jul 24th, 2023
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Block lemmy instances
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.4.2.1
  5. // @description  Remove posts and comments from specified instances.
  6. // @author       RyanHx
  7. // @match        https://lemmy.world/*
  8. // @match        https://old.lemmy.world/*
  9. // @grant        none
  10. // @license      MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     'use strict';
  15.     const target = document.querySelector("#app.lemmy-site, body > main");
  16.     if (!target) return;
  17.  
  18.     const config = { attributes: false, childList: true, subtree: true };
  19.     const callback = (mutationList, observer) => {
  20.         const blockedInstances = ["lemmynsfw.com"];
  21.         for (const instance of blockedInstances) {
  22.             const selector = `div.post a[href$="${instance}"], div.post-listing a[title$="${instance}"], li.comment a[title$="${instance}"]`;
  23.             let link = document.querySelector(selector);
  24.             while (link) {
  25.                 const post = link.closest("div.post, div.post-listing, li.comment");
  26.                 const divider = post.nextElementSibling;
  27.                 console.log(`Removing ${post}`);
  28.                 post.remove();
  29.                 if (divider?.nodeName === "HR") {
  30.                     divider.remove();
  31.                 }
  32.                 link = document.querySelector(selector);
  33.             }
  34.         }
  35.     }
  36.     const observer = new MutationObserver(callback);
  37.     observer.observe(target, config);
  38.     callback();
  39. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement