Skip to content

Commit

Permalink
Added Ecosia search engine integration (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninluc authored Jul 24, 2024
1 parent dfa101c commit 5c74064
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Logseq Copilot is a Chrome extension that allows you to access your Logseq using

## Features

- 🔍 Show Logseq content when you search on popular search engines via your keywords. Now support Google, Bing, Baidu, Yandex, DuckDuckGo, SearX.
- 🔍 Show Logseq content when you search on popular search engines via your keywords. Now support Google, Bing, Ecosia, Baidu, Yandex, DuckDuckGo, SearX.

## Support
<p align="center">
Expand Down
3 changes: 2 additions & 1 deletion src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import mountQuickCapture from './QuickCapture';
import searchEngines, {
Baidu,
Bing,
Ecosia,
DuckDuckGo,
Google,
SearX,
Expand All @@ -24,7 +25,7 @@ const mount = async (container: Element, query: string) => {
};

async function run(
searchEngine: Google | Bing | DuckDuckGo | Yandex | SearX | Baidu,
searchEngine: Google | Bing | Ecosia | DuckDuckGo | Yandex | SearX | Baidu,
) {
console.debug('Logseq copliot', window.location.hostname);

Expand Down
22 changes: 22 additions & 0 deletions src/pages/content/searchingEngines/searchingEngines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ export class Google extends SearchingEngine {
}
}

export class Ecosia extends SearchingEngine {
isMatch(): boolean {
const match = window.location.hostname.match(/ecosia\.org$/g);
return !!match;
}

getQuery(): string | null {
const searchURL = new URL(window.location.href);
const query = searchURL.searchParams.get('q');
return query;
}

gotElement(): Element {
const container = document.createElement('article');
const asideElement = document.querySelector('.sidebar .web__sidebar');
asideElement!.insertBefore(container, asideElement!.firstChild);

return container;
}
}

export class Bing extends SearchingEngine {
isMatch(): boolean {
const match = window.location.hostname.match(/bing(\.com)?(\.\w{2})?$/g);
Expand Down Expand Up @@ -232,6 +253,7 @@ export class Startpage extends SearchingEngine {

const searchEngins = [
new Google(),
new Ecosia(),
new Bing(),
new DuckDuckGo(),
new Yandex(),
Expand Down

0 comments on commit 5c74064

Please sign in to comment.