Block lemmy instances

Remove posts and comments from specified instances.

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

  1. // ==UserScript==
  2. // @name Block lemmy instances
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Remove posts and comments from specified instances.
  6. // @author RyanHx
  7. // @match https://vlemmy.net/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. const target = document.getElementById("app");
  15. const config = { attributes: false, childList: true, subtree: true };
  16. const callback = (mutationList, observer) => {
  17. const blockedInstances = ["example.ml","lemmy.world"];
  18. const infoLinks = document.querySelectorAll("a[title]");
  19. for (const linkElem of infoLinks) {
  20. if (blockedInstances.some((i) => linkElem.getAttribute("title").endsWith(i))) {
  21. const post = linkElem.closest("div.post-listing, div.comment");
  22. if (post) {
  23. const divider = post.nextElementSibling;
  24. post.remove();
  25. console.log("Removed post.");
  26. if(divider?.nodeName === "HR"){
  27. divider.remove();
  28. }
  29. break;
  30. }
  31. }
  32. }
  33. }
  34. const observer = new MutationObserver(callback);
  35. observer.observe(target, config);
  36. })();