Block lemmy instances

Remove posts and comments from specified instances.

  1. // ==UserScript==
  2. // @name Block lemmy instances
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4.3
  5. // @description Remove posts and comments from specified instances.
  6. // @author RyanHx
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. const target = document.querySelector("#app.lemmy-site");
  15. const config = { attributes: false, childList: true, subtree: true };
  16. const callback = (mutationList, observer) => {
  17. const blockedInstances = ["example.ml", "anotherexample.world"]; // EDIT THIS LINE
  18. for (const instance of blockedInstances) {
  19. const selector = `div.post-listing a[title$="@${instance}"], li.comment a.person-listing[title$="@${instance}"]`;
  20. let link = document.querySelector(selector);
  21. while (link) {
  22. const post = link.closest("div.post-listing, li.comment");
  23. const divider = post.nextElementSibling;
  24. console.log(`Removing ${instance} post.`);
  25. post.remove();
  26. if (divider?.nodeName === "HR") {
  27. divider.remove();
  28. }
  29. link = document.querySelector(selector);
  30. }
  31. }
  32. }
  33. const observer = new MutationObserver(callback);
  34. if (target) {
  35. observer.observe(target, config);
  36. callback();
  37. }
  38. })();