Adding support for Ecosia search filtering

pull/227/head
Kevin Payravi 2023-07-23 00:55:29 -05:00
parent 4b5c267f00
commit 02668d47b1
3 changed files with 34 additions and 8 deletions

View File

@ -1,4 +1,4 @@
const searchEngineRegex = /www\.google\.|duckduckgo\.com|www\.bing\.com|search\.brave\.com/; const searchEngineRegex = /www\.google\.|duckduckgo\.com|www\.bing\.com|search\.brave\.com|ecosia\.org/;
const fandomRegex = /\.fandom\.com$/; const fandomRegex = /\.fandom\.com$/;
const fextraRegex = /\.fextralife\.com$/; const fextraRegex = /\.fextralife\.com$/;
const breezeWikiRegex = /breezewiki\.com$|breeze\.hostux\.net$|bw\.projectsegfau\.lt$|antifandom\.com$|breezewiki\.pussthecat\.org$|bw\.vern\.cc$|breezewiki\.esmailelbob\.xyz$|bw\.artemislena\.eu$|bw\.hamstro\.dev$|nerd\.whatever\.social$|breeze\.nohost\.network$/; const breezeWikiRegex = /breezewiki\.com$|breeze\.hostux\.net$|bw\.projectsegfau\.lt$|antifandom\.com$|breezewiki\.pussthecat\.org$|bw\.vern\.cc$|breezewiki\.esmailelbob\.xyz$|bw\.artemislena\.eu$|bw\.hamstro\.dev$|nerd\.whatever\.social$|breeze\.nohost\.network$/;
@ -231,16 +231,16 @@ function displayRedirectBanner(url, id, destination, storage) {
} }
} }
function filterSearchResults(fandomSearchResults, searchEngine, storage) { function filterSearchResults(searchResults, searchEngine, storage) {
getData().then(sites => { getData().then(sites => {
countFiltered = 0; countFiltered = 0;
fandomSearchResults.forEach(searchResult => { searchResults.forEach(searchResult => {
let searchResultLink = ''; let searchResultLink = '';
try { try {
if (searchEngine === 'bing') { if (searchEngine === 'bing') {
searchResultLink = searchResult.innerHTML.replaceAll('<strong>', '').replaceAll('</strong>', ''); searchResultLink = searchResult.innerHTML.replaceAll('<strong>', '').replaceAll('</strong>', '');
} else { } else {
searchResultLink = searchResult.closest('[href]').href; searchResultLink = searchResult.closest('a[href]').href;
} }
} catch (e) { } catch (e) {
console.log('Indie Wiki Buddy failed to properly parse search results with error: ' + e); console.log('Indie Wiki Buddy failed to properly parse search results with error: ' + e);
@ -295,6 +295,11 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
cssQuery = 'div.snippet'; cssQuery = 'div.snippet';
} }
break; break;
case 'ecosia':
if (searchResult.closest('div.result__body')) {
cssQuery = 'div.result__body';
}
break;
default: default:
} }
if (cssQuery) { if (cssQuery) {
@ -485,6 +490,24 @@ function main(mutations = null, observer = null) {
} }
}); });
} }
} else if (currentURL.hostname.includes('ecosia.org')) {
// Check if doing an Ecosia search:
function filterEcosia() {
let searchResults = Array.from(document.querySelectorAll("a.result__link")).filter(el => el.href.includes('fandom.com') || el.href.includes('fextralife.com'));
filterSearchResults(searchResults, 'ecosia', storage);
}
// Need to wait for document to be ready
if (document.readyState === 'complete') {
addLocationObserver(main);
filterEcosia();
} else {
document.addEventListener('readystatechange', e => {
if (document.readyState === 'complete') {
addLocationObserver(main);
filterEcosia();
}
});
}
} }
} }
} }

View File

@ -68,9 +68,10 @@
"https://bw.hamstro.dev/*", "https://bw.hamstro.dev/*",
"https://nerd.whatever.social/*", "https://nerd.whatever.social/*",
"https://breeze.nohost.network/*", "https://breeze.nohost.network/*",
"https://*.duckduckgo.com/*",
"https://*.bing.com/search*", "https://*.bing.com/search*",
"https://search.brave.com/search*", "https://search.brave.com/search*",
"https://*.duckduckgo.com/*",
"https://*.ecosia.org/*",
"https://www.google.com/search*", "https://www.google.com/search*",
"https://www.google.ad/search*", "https://www.google.ad/search*",
"https://www.google.ae/search*", "https://www.google.ae/search*",

View File

@ -50,9 +50,10 @@
"https://bw.hamstro.dev/*", "https://bw.hamstro.dev/*",
"https://nerd.whatever.social/*", "https://nerd.whatever.social/*",
"https://breeze.nohost.network/*", "https://breeze.nohost.network/*",
"https://*.duckduckgo.com/*", "https://*.bing.com/*",
"https://www.bing.com/*",
"https://search.brave.com/*", "https://search.brave.com/*",
"https://*.duckduckgo.com/*",
"https://*.ecosia.org/*",
"https://www.google.com/*", "https://www.google.com/*",
"https://www.google.ad/*", "https://www.google.ad/*",
"https://www.google.ae/*", "https://www.google.ae/*",
@ -265,9 +266,10 @@
"https://bw.hamstro.dev/*", "https://bw.hamstro.dev/*",
"https://nerd.whatever.social/*", "https://nerd.whatever.social/*",
"https://breeze.nohost.network/*", "https://breeze.nohost.network/*",
"https://*.duckduckgo.com/*",
"https://*.bing.com/search*", "https://*.bing.com/search*",
"https://search.brave.com/search*", "https://search.brave.com/search*",
"https://*.duckduckgo.com/*",
"https://*.ecosia.org/*",
"https://www.google.com/search*", "https://www.google.com/search*",
"https://www.google.ad/search*", "https://www.google.ad/search*",
"https://www.google.ae/search*", "https://www.google.ae/search*",