on master help sign in
Merge branch 'Cqoicebordel-remove_trackers_plugin'
f210709Adam Tauber
searx/plugins/__init__.py+3−1
@@ -21,7 +21,8 @@ logger = logger.getChild('plugins')
21
21
22from searx.plugins import (https_rewrite,
22from searx.plugins import (https_rewrite,
23 self_info,
23 self_info,
24− search_on_category_select)
24+ search_on_category_select,
25+ tracker_url_remover)
25
26
26required_attrs = (('name', str),
27required_attrs = (('name', str),
27 ('description', str),
28 ('description', str),
@@ -73,3 +74,4 @@ plugins = PluginStore()
73plugins.register(https_rewrite)
74plugins.register(https_rewrite)
74plugins.register(self_info)
75plugins.register(self_info)
75plugins.register(search_on_category_select)
76plugins.register(search_on_category_select)
77+plugins.register(tracker_url_remover)
searx/plugins/tracker_url_remover.pynew file+44
@@ -0,0 +1,44 @@
1+'''
2+searx is free software: you can redistribute it and/or modify
3+it under the terms of the GNU Affero General Public License as published by
4+the Free Software Foundation, either version 3 of the License, or
5+(at your option) any later version.
6+
7+searx is distributed in the hope that it will be useful,
8+but WITHOUT ANY WARRANTY; without even the implied warranty of
9+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+GNU Affero General Public License for more details.
11+
12+You should have received a copy of the GNU Affero General Public License
13+along with searx. If not, see < http://www.gnu.org/licenses/ >.
14+
15+(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
16+'''
17+
18+from flask.ext.babel import gettext
19+import re
20+from urlparse import urlunparse
21+
22+regexes = {re.compile(r'utm_[^&]+&?'),
23+ re.compile(r'(wkey|wemail)[^&]+&?'),
24+ re.compile(r'&$')}
25+
26+name = gettext('Tracker URL remover')
27+description = gettext('Remove trackers arguments from the returned URL')
28+default_on = True
29+
30+
31+def on_result(request, ctx):
32+ query = ctx['result']['parsed_url'].query
33+
34+ if query == "":
35+ return True
36+
37+ for reg in regexes:
38+ query = reg.sub('', query)
39+
40+ if query != ctx['result']['parsed_url'].query:
41+ ctx['result']['parsed_url'] = ctx['result']['parsed_url']._replace(query=query)
42+ ctx['result']['url'] = urlunparse(ctx['result']['parsed_url'])
43+
44+ return True