|
@@ -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
|