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.3
  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", "anotherexample.world"];
  18. for (const instance of blockedInstances) {
  19. let post = document.querySelector(`div.post-listing a[title$="${instance}"], div.comment a[title$="${instance}"]`);
  20. while (post) {
  21. const divider = post.nextElementSibling;
  22. post.closest("div.post-listing, div.comment").remove();
  23. if (divider?.nodeName === "HR") {
  24. divider.remove();
  25. }
  26. post = document.querySelector(`div.post-listing a[title$="${instance}"], div.comment a[title$="${instance}"]`);
  27. }
  28. }
  29. }
  30. const observer = new MutationObserver(callback);
  31. observer.observe(target, config);
  32. })();