Skip to content

Added initial support for Ecosia #606

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

Open
wants to merge 4 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
11,562 changes: 11,562 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

101 changes: 50 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
{
"name": "web-search-navigator",
"description": "Keyboard shortcuts for Google™ search.",
"repository": "https://github.com/infokiller/web-search-navigator",
"author": "https://github.com/infokiller",
"contributors": [
{
"name": "infokiller"
"version": "1.0.0",
"name": "web-search-navigator",
"description": "Keyboard shortcuts for Google™ search.",
"repository": "https://github.com/infokiller/web-search-navigator",
"author": "https://github.com/infokiller",
"contributors": [
{
"name": "infokiller"
},
{
"name": "Michal Novák",
"url": "https://www.weborama.cz/"
}
],
"license": "MIT",
"scripts": {
"build": "gulp",
"eslint": "eslint $(git ls-files '*.js' ':(exclude)vendor')",
"prettier-markdown-check": "prettier --check $(git ls-files '*.md')",
"prettier-markdown-format": "prettier --write $(git ls-files '*.md')",
"stylelint": "stylelint src/*.css",
"shellcheck": "shellcheck tools/*.sh",
"shfmt-check": "shfmt -i 2 -sr -ci -d tools",
"shfmt-format": "shfmt -i 2 -sr -ci -w tools",
"check": "yarn run eslint && yarn run stylelint && yarn run shellcheck && yarn run prettier-markdown-check"
},
{
"name": "Michal Novák",
"url": "https://www.weborama.cz/"
"dependencies": {
"mousetrap": "^1.6.5",
"webextension-polyfill": "^0.12.0"
},
"devDependencies": {
"eslint": "^9.4.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-json": "^4.0.0",
"gulp": "^5.0.0",
"gulp-if": "^3.0.0",
"gulp-terser": "^2.1.0",
"markdownlint-cli": "^0.41.0",
"minimist": "^1.2.8",
"prettier": "3.2.5",
"prettier-eslint-cli": "^8.0.1",
"set-value": "^4.1.0",
"shellcheck": "^2.2.0",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
"web-ext": "^7.11.0"
},
"resolutions": {
"bl": "^1.2.3",
"node-forge": "^0.10.0"
}
],
"license": "MIT",
"scripts": {
"build": "gulp",
"eslint": "eslint $(git ls-files '*.js' ':(exclude)vendor')",
"prettier-markdown-check": "prettier --check $(git ls-files '*.md')",
"prettier-markdown-format": "prettier --write $(git ls-files '*.md')",
"stylelint": "stylelint src/*.css",
"shellcheck": "shellcheck tools/*.sh",
"shfmt-check": "shfmt -i 2 -sr -ci -d tools",
"shfmt-format": "shfmt -i 2 -sr -ci -w tools",
"check": "yarn run eslint && yarn run stylelint && yarn run shellcheck && yarn run prettier-markdown-check"
},
"dependencies": {
"mousetrap": "^1.6.5",
"webextension-polyfill": "^0.12.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^9.3.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-json": "^4.0.0",
"gulp": "^5.0.0",
"gulp-if": "^3.0.0",
"gulp-terser": "^2.1.0",
"markdownlint-cli": "^0.41.0",
"minimist": "^1.2.8",
"prettier": "3.2.5",
"prettier-eslint-cli": "^8.0.1",
"set-value": "^4.1.0",
"shellcheck": "^2.2.0",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
"web-ext": "^7.11.0"
},
"resolutions": {
"bl": "^1.2.3",
"node-forge": "^0.10.0"
}
}
}
5 changes: 3 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Web Search Navigator",
"version": "0.5.2",
"version": "0.5.3",
"description": "Keyboard shortcuts for Google search, YouTube, Startpage, Brave Search, Google Scholar, Github, Gitlab, and Amazon.",
"author": "Web Search Navigator",
"icons": {
Expand Down Expand Up @@ -451,6 +451,7 @@
"https://scholar.google.tt/*",
"https://scholar.google.vg/*",
"https://scholar.google.vu/*",
"https://scholar.google.ws/*"
"https://scholar.google.ws/*",
"https://www.ecosia.org/*"
]
}
4 changes: 4 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ html[dark], [dark] {
outline: var(--result-outline) !important;
}

.wsn-ecosia-focused-link {
outline: 2px solid var(--color-link-primary) !important;
}

.wsn-google-focused-memex-result {
border: var(--result-outline) !important;
box-sizing: border-box;
Expand Down
5 changes: 5 additions & 0 deletions src/options_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ <h2>EXPERIMENTAL: Alternative search engines</h2>
<input type="checkbox" id="github"> Enable on Github
</label>
</div>
<div class="option">
<label for="github">
<input type="checkbox" id="ecosia"> Enable on Ecosia
</label>
</div>
<div class="option">
<label for="gitlab">
<input type="checkbox" id="gitlab"> Enable on Gitlab
Expand Down
9 changes: 9 additions & 0 deletions src/options_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const OPTIONAL_PERMISSIONS_URLS = {
'amazon': generateURLPatterns('https://www.amazon', AMAZON_DOMAINS, '/*'),
'gitlab': ['https://gitlab.com/*'],
'custom-gitlab': ['https://*/*'],
'ecosia': ['https://www.ecosia.org/*']
};

const KEYBINDING_TO_DIV = {
Expand Down Expand Up @@ -156,6 +157,10 @@ class OptionsPageManager {
customGitlab.addEventListener('change', () => {
setSearchEnginePermission_(customGitlab);
});
const ecosia = document.getElementById('ecosia');
ecosia.addEventListener('change', () => {
setSearchEnginePermission_(ecosia);
});
// NOTE: this.saveOptions and this.resetToDefaults cannot be passed directly
// or otherwise `this` won't be bound to the object.
document.getElementById('save').addEventListener('click', () => {
Expand Down Expand Up @@ -268,6 +273,10 @@ class OptionsPageManager {
github.checked = OPTIONAL_PERMISSIONS_URLS['github'].every((url) => {
return permissions.origins.includes(url);
});
const ecosia = document.getElementById('ecosia');
ecosia.checked = OPTIONAL_PERMISSIONS_URLS['ecosia'].every((url) => {
return permissions.origins.includes(url);
});
const gitlab = document.getElementById('gitlab');
gitlab.checked = OPTIONAL_PERMISSIONS_URLS['gitlab'].every((url) => {
return permissions.origins.includes(url);
Expand Down
68 changes: 68 additions & 0 deletions src/search_engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,73 @@ class CustomGitlab extends Gitlab {
}
}


class Ecosia {
constructor(options) {
this.options = options;
}
get urlPattern() {
return /^https:\/\/(www\.)?ecosia\.org/;;
}
get searchBoxSelector() {
return 'input[name="q"][type="search"]';
}

onChangedResults(callback) {
const container = document.querySelector('main');
if (!container) {
return;
}

let lastURL = window.location.search;
const observer = new MutationObserver(
(mutationsList, observer) => {
if (lastURL !== window.location.search) {
lastURL = window.location.search;
callback(true);
}
},
);

observer.observe(container, {
attributes: false,
childList: true,
subtree: false,
});
}

getSearchResults() {
const includedElements = [
{
nodes: document.querySelectorAll('a.result__link.link--color-result'),
highlightClass: 'wsn-ecosia-focused-link',
highlightedElementSelector: (n) => n,
containerSelector: (n) => n.parentElement.parentElement,
}
];
return getSortedSearchResults(includedElements, []);
}

get previousPageButton() {
const previousPageElement = document.querySelector('a[data-test-id="back-button"]');
if (previousPageElement !== null) {
return previousPageElement;
}

return null;
}

get nextPageButton() {
const previousPageElement = document.querySelector('a[data-test-id="next-button"]');
if (previousPageElement !== null) {
return previousPageElement;
}

return null;
}
}


// Get search engine object matching the current url
/* eslint-disable-next-line no-unused-vars */
const getSearchEngine = (options) => {
Expand All @@ -1554,6 +1621,7 @@ const getSearchEngine = (options) => {
new Amazon(options),
new Github(options),
new Gitlab(options),
new Ecosia(options),
new CustomGitlab(options),
];
// Switch over all compatible search engines
Expand Down
Loading