Bluesky Search External Link Filter

Hides Bluesky Search posts containing external links.

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