Bluesky Search External Link Filter

Hides Bluesky Search posts containing external links.

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