Last active
April 2, 2026 01:36
-
-
Save proegssilb/c26b3db2b74ebad8ddbd6e1f0bcfc573 to your computer and use it in GitHub Desktop.
A quick-and-dirty mass domain blocker plugin for searxng
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from urllib import request | |
| from urllib.parse import urlparse | |
| from flask_babel import gettext as _ | |
| from searx.plugins import Plugin, PluginInfo | |
| block_lists = [ | |
| 'https://raw.githubusercontent.com/NotaInutilis/Super-SEO-Spam-Suppressor/refs/heads/main/hosts.txt', | |
| 'https://raw.githubusercontent.com/laylavish/uBlockOrigin-HUGE-AI-Blocklist/refs/heads/main/noai_hosts.txt', | |
| ] | |
| def load_block_lists(): | |
| rv = set() | |
| for link in block_lists: | |
| with request.urlopen(link) as data: | |
| for line in data: | |
| line = line.decode().strip() | |
| if line and not line.startswith('#'): | |
| parts = line.split(' ') | |
| if len(parts) == 2: | |
| host = parts[1] | |
| rv.add(host) | |
| if not host.startswith('www.'): | |
| rv.add('www.' + host) | |
| return rv | |
| def mk_url_filter(blocklist): | |
| def url_filter(result, field_name, url_src) -> bool | str: | |
| hostname = urlparse(url_src).hostname | |
| if not hostname: | |
| return True | |
| return hostname not in blocklist | |
| return url_filter | |
| class MyPlugin(Plugin): | |
| id = "xr_domain_block" | |
| def __init__(self, plg_cfg): | |
| super().__init__(plg_cfg) | |
| self.info = PluginInfo(id=self.id, name=_("Simple Domain Blocker"), description=_("PoC of a mass domain blocker")) | |
| self.blocklist = load_block_lists() | |
| self.url_filter = mk_url_filter(self.blocklist) | |
| def on_result(self, request, search, result) -> bool: | |
| result.filter_urls(self.url_filter) | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment