Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
amethystnetwork-dev
GitHub Repository: amethystnetwork-dev/Incognito
Path: blob/main/static/script/search.js
918 views
1
/**
2
* Incognito
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
19
/**
20
* List of search engines
21
* @type {import("./search.d.ts").SearchProviders}
22
*/
23
export const searchProviders = {
24
google: {
25
mapQuery: (query) => `http://google.com/complete/search?q=${query}&client=${(["Chrome", "Firefox", "Safari"].filter(c => navigator.userAgent.includes(c))[0] || "Chrome").toLowerCase()}`,
26
parseResponse: (res) => JSON.parse(res)[1],
27
frontend: 'https://google.com/search?q=%s'
28
},
29
ddg: {
30
mapQuery: (query) => `https://duckduckgo.com/ac/?q=${encodeURIComponent(query)}`,
31
parseResponse: (res) => JSON.parse(res).map(ac => ac.phrase),
32
frontend: 'https://duckduckgo.com/?q=%s'
33
},
34
bing: {
35
mapQuery: (query) => `https://www.bing.com/AS/Suggestions?qry=${encodeURIComponent(query)}&cvid=%01&bareServer=`,
36
parseResponse: (res) => ([...res.matchAll(/<span class="sa_tm_text">(.*?)<\/span>/g)]).map(phrase => phrase[1].replace(/<strong>|<\/strong>/g, '')),
37
frontend: 'https://bing.com/search?q=%s'
38
},
39
brave: {
40
mapQuery: (query) => `https://search.brave.com/api/suggest?q=${encodeURIComponent(query)}`,
41
parseResponse: (res) => JSON.parse(res)[1],
42
frontend: 'https://search.brave.com/search?q=%s'
43
},
44
startpage: {
45
mapQuery: (query) => `https://www.startpage.com/suggestions?q=${encodeURIComponent(query)}&segment=omnibox`,
46
parseResponse: (res) => JSON.parse(res).suggestions.map(ac => ac.text),
47
frontend: 'https://www.startpage.com/sp/search?query=%s'
48
},
49
ecosia: {
50
mapQuery: (query) => `https://ac.ecosia.org/?q=${encodeURIComponent(query)}`,
51
parseResponse: (res) => JSON.parse(res).suggestions
52
}
53
};
54