Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecosia support [#7] #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ var urls = {
swisscows: "https://swisscows.com/api/suggestion/suggest?query=",
ask: "https://amg-ss.ask.com/query?q=",
brave: "https://search.brave.com/api/suggest?q=",
// see: https://forum.vivaldi.net/topic/16991/guide-search-suggestion-url
ecosia: "https://ac.ecosia.org/autocomplete?q=", // Ecosia API endpoint
wikipedia: "https://en.wikipedia.org/w/api.php?action=opensearch&search=",
finn: "https://www.finn.no/search/autocomplete/xhr?responseType=json&searchKey=SEARCH_ID_BAP_ALL&term=",
// TODO #7
//you: "https://you.com/api/ac?q=", // #7: cloudflare
}

module.exports = class Suggest {
Expand Down Expand Up @@ -70,6 +76,26 @@ module.exports = class Suggest {
return op.data[1];
}

static async ecosia(q) {
var op = await axios(urls.ecosia + q);
return op.data.suggestions;
}

static async wikipedia(q) {
var op = await axios(urls.wikipedia + q);
return op.data[1]; // [3] has the links
}

static async finn(q) {
var op = await axios(urls.finn + q);
return op.data.map(x=>x.suggest);
}

//static async you(q) {
// var op = await axios(urls.you + q, options);
// return op.data[1] // FIXME needs cloudflare circumvention
//}

static async all(q) {
var all = [
...await Suggest.google(q),
Expand All @@ -81,8 +107,12 @@ module.exports = class Suggest {
...await Suggest.dogpile(q),
...await Suggest.swisscows(q),
...await Suggest.ask(q),
...await Suggest.brave(q)
...await Suggest.brave(q),
...await Suggest.ecosia(q),
...await Suggest.wikipedia(q),
...await Suggest.finn(q),
//...await Suggest.you(q),
];
return [...new Set(all)];
}
}
}
Loading