Bluesky Search External Link Filter

Hides Bluesky Search posts containing external links.

当前为 2025-02-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bluesky Search External Link Filter
  3. // @namespace https://bsky.app/
  4. // @version 1.0
  5. // @description Hides Bluesky Search posts containing external links.
  6. // @match https://bsky.app/search*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. function getElementsByXPath(xpath, context = document) {
  12. let nodes = document.evaluate(xpath, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  13. return Array.from({ length: nodes.snapshotLength }, (_, i) => nodes.snapshotItem(i));
  14. }
  15.  
  16. function isExternalLink(link) {
  17. return link && !link.href.includes("bsky.app");
  18. }
  19.  
  20. function checkAndHidePosts() {
  21. getElementsByXPath("//div[@id='root']/div/div/div/div/main/div/div/div/div/div/div[2]/div[3]/div/div/div/div/div[2]/div/div")
  22. .forEach(post => {
  23. if ([...post.getElementsByTagName("a")].some(isExternalLink)) {
  24. if (post.parentElement) post.style.display = "none"; // Hide instead of removing
  25. }
  26. });
  27. }
  28.  
  29. function observeContainer() {
  30. let container = document.querySelector("main div div div div div div:nth-child(3)");
  31. if (container) {
  32. new MutationObserver(checkAndHidePosts).observe(container, { childList: true, subtree: true });
  33. checkAndHidePosts();
  34. }
  35. }
  36.  
  37. new MutationObserver(observeContainer).observe(document.body, { childList: true, subtree: true });
  38. observeContainer();
  39. })();