瀏覽代碼

Merge branch 'remove_trackers_plugin' of https://github.com/Cqoicebordel/searx into Cqoicebordel-remove_trackers_plugin

Conflicts:
	searx/plugins/__init__.py
Adam Tauber 9 年之前
父節點
當前提交
6424a7702d
共有 2 個檔案被更改,包括 47 行新增1 行删除
  1. 3
    1
      searx/plugins/__init__.py
  2. 44
    0
      searx/plugins/tracker_url_remover.py

+ 3
- 1
searx/plugins/__init__.py 查看文件

@@ -21,7 +21,8 @@ logger = logger.getChild('plugins')
21 21
 
22 22
 from searx.plugins import (https_rewrite,
23 23
                            self_info,
24
-                           search_on_category_select)
24
+                           search_on_category_select,
25
+                           tracker_url_remover)
25 26
 
26 27
 required_attrs = (('name', str),
27 28
                   ('description', str),
@@ -73,3 +74,4 @@ plugins = PluginStore()
73 74
 plugins.register(https_rewrite)
74 75
 plugins.register(self_info)
75 76
 plugins.register(search_on_category_select)
77
+plugins.register(tracker_url_remover)

+ 44
- 0
searx/plugins/tracker_url_remover.py 查看文件

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