|
@@ -0,0 +1,36 @@
|
|
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
|
+from flask.ext.babel import gettext
|
|
18
|
+import re
|
|
19
|
+name = "Self User Agent"
|
|
20
|
+description = gettext('Display your own User Agent if the query expression contains "user agent" or "user-agent"')
|
|
21
|
+default_on = True
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+# User Agent query regex
|
|
25
|
+p = re.compile('user[ -]agent', re.IGNORECASE)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+# attach callback to the post search hook
|
|
29
|
+# request: flask request object
|
|
30
|
+# ctx: the whole local context of the pre search hook
|
|
31
|
+def post_search(request, ctx):
|
|
32
|
+ if p.match(ctx['search'].query):
|
|
33
|
+ ua = request.user_agent
|
|
34
|
+ ctx['search'].answers.clear()
|
|
35
|
+ ctx['search'].answers.add(ua)
|
|
36
|
+ return True
|