// ==UserScript== // @name Mastodon Search External Link Filter // @description Hides Mastodon Search posts with external links // @match https://mastodon.social/search?* // @version 0.0.1.20250502155419 // @namespace https://greasyfork.org/users/1435046 // @downloadURL none // ==/UserScript== (function () { // 1) Grab every article in the search results function getPosts() { return document.querySelectorAll('.explore__search-results article'); } // 2) External if href doesn’t include our instance hostname function isExternalLink(a) { return a.href && !a.href.includes(location.hostname); } // 3) Hide any article containing at least one external link function hidePostsWithExternalLinks() { getPosts().forEach(article => { const links = article.querySelectorAll('a[href]'); if (Array.from(links).some(isExternalLink)) { article.style.display = 'none'; } }); } // 4) Watch for new results (infinite scroll) function observeSearchResults() { const container = document.querySelector('.explore__search-results'); if (!container) return; new MutationObserver(hidePostsWithExternalLinks) .observe(container, { childList: true, subtree: true }); hidePostsWithExternalLinks(); } new MutationObserver(observeSearchResults) .observe(document.body, { childList: true, subtree: true }); observeSearchResults(); })();