2023-07-25 06:17:46 +00:00
|
|
|
const currentURL = new URL(document.location);
|
2023-08-04 05:50:12 +00:00
|
|
|
let filteredWikis = [];
|
2023-08-07 06:43:23 +00:00
|
|
|
let hiddenWikisRevealed = {};
|
2023-07-25 06:17:46 +00:00
|
|
|
|
|
|
|
// Create object prototypes for getting and setting attributes:
|
|
|
|
Object.prototype.get = function (prop) {
|
|
|
|
this[prop] = this[prop] || {};
|
|
|
|
return this[prop];
|
|
|
|
};
|
|
|
|
Object.prototype.set = function (prop, value) {
|
|
|
|
this[prop] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to create an observer to watch for mutations on search pages
|
|
|
|
function addLocationObserver(callback) {
|
|
|
|
const config = {
|
|
|
|
attributes: false,
|
|
|
|
childList: true,
|
|
|
|
subtree: true
|
|
|
|
}
|
|
|
|
const observer = new MutationObserver(callback);
|
|
|
|
observer.observe(document.body, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load website data:
|
|
|
|
async function getData() {
|
|
|
|
const LANGS = ["DE", "EN", "ES", "FR", "IT", "PL", "TOK"];
|
|
|
|
let sites = [];
|
|
|
|
let promises = [];
|
|
|
|
for (let i = 0; i < LANGS.length; i++) {
|
|
|
|
promises.push(fetch(chrome.runtime.getURL('data/sites' + LANGS[i] + '.json'))
|
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then(function (jsonData) {
|
|
|
|
jsonData.forEach((site) => {
|
|
|
|
site.origins.forEach((origin) => {
|
|
|
|
sites.push({
|
|
|
|
"id": site.id,
|
|
|
|
"origin": origin.origin,
|
2023-08-04 05:50:12 +00:00
|
|
|
"origin_group": site.origins_label,
|
2023-07-25 06:17:46 +00:00
|
|
|
"origin_base_url": origin.origin_base_url,
|
|
|
|
"origin_content_path": origin.origin_content_path,
|
|
|
|
"destination": site.destination,
|
|
|
|
"destination_base_url": site.destination_base_url,
|
|
|
|
"destination_content_path": site.destination_content_path,
|
|
|
|
"destination_content_prefix": (site.destination_content_prefix ? site.destination_content_prefix : ""),
|
|
|
|
"destination_platform": site.destination_platform,
|
|
|
|
"destination_icon": site.destination_icon,
|
|
|
|
"lang": LANGS[i]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
await Promise.all(promises);
|
2023-08-04 05:50:12 +00:00
|
|
|
|
2023-07-25 06:17:46 +00:00
|
|
|
return sites;
|
|
|
|
}
|
|
|
|
|
2023-08-04 05:50:12 +00:00
|
|
|
function insertCSS() {
|
|
|
|
// Output CSS
|
|
|
|
styleString = `
|
|
|
|
.iwb-notice {
|
2023-08-07 06:43:23 +00:00
|
|
|
display: block !important;
|
2023-08-04 05:50:12 +00:00
|
|
|
margin: .5em .5em 1em .5em !important;
|
|
|
|
padding: .5em .5em .5em 1em !important;
|
|
|
|
border-left: 3px solid #FFCC33 !important;
|
|
|
|
font-size: 14px !important;
|
|
|
|
color: white !important;
|
|
|
|
mix-blend-mode: difference !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.iwb-notice a {
|
|
|
|
text-decoration: underline !important;
|
|
|
|
color: white !important;
|
|
|
|
mix-blend-mode: difference !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.iwb-notice button {
|
|
|
|
cursor: pointer !important;
|
2023-08-07 06:43:23 +00:00
|
|
|
display: inline-block !important;
|
2023-08-04 05:50:12 +00:00
|
|
|
padding: 2px 8px !important;
|
2023-08-07 06:43:23 +00:00
|
|
|
margin: 8px 8px 0 0 !important;
|
2023-08-04 05:50:12 +00:00
|
|
|
background-color: transparent !important;
|
2023-08-07 06:43:23 +00:00
|
|
|
border: 1px solid !important;
|
2023-08-04 05:50:12 +00:00
|
|
|
border-radius: 5px !important;
|
2023-08-07 06:43:23 +00:00
|
|
|
font-size: 11px !important;
|
2023-08-04 05:50:12 +00:00
|
|
|
color: white !important;
|
|
|
|
mix-blend-mode: difference !important;
|
2023-08-07 06:43:23 +00:00
|
|
|
text-align: left !important;
|
|
|
|
}
|
|
|
|
.iwb-notice button+a {
|
|
|
|
display: inline-block;
|
|
|
|
font-size: 12px !important;
|
|
|
|
margin: 8px 0 0 0 !important;
|
|
|
|
white-space: nowrap !important;
|
2023-08-04 05:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.iwb-hide {
|
|
|
|
display: none !important;
|
|
|
|
}
|
|
|
|
.iwb-show {
|
|
|
|
display: block !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.iwb-notice button:hover {
|
|
|
|
outline: 1px solid !important;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
style = document.createElement('style');
|
|
|
|
style.textContent = styleString;
|
|
|
|
document.head.append(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to convert strings to consistent IDs
|
|
|
|
// Used to convert wiki names to element IDs
|
|
|
|
function stringToId(string) {
|
|
|
|
return string.replaceAll(' ', '-').replaceAll("'", '').toLowerCase();
|
|
|
|
}
|
|
|
|
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterSearchResults(searchResults, searchEngine, storage) {
|
|
|
|
getData().then(sites => {
|
2023-08-04 05:50:12 +00:00
|
|
|
let countFiltered = 0;
|
|
|
|
|
2023-07-25 06:17:46 +00:00
|
|
|
searchResults.forEach(searchResult => {
|
|
|
|
let searchResultLink = '';
|
|
|
|
try {
|
|
|
|
if (searchEngine === 'bing') {
|
|
|
|
searchResultLink = searchResult.innerHTML.replaceAll('<strong>', '').replaceAll('</strong>', '');
|
|
|
|
} else {
|
|
|
|
searchResultLink = searchResult.closest('a[href]').href;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Indie Wiki Buddy failed to properly parse search results with error: ' + e);
|
|
|
|
}
|
|
|
|
// Check if site is in our list of wikis:
|
2023-07-26 17:53:16 +00:00
|
|
|
let matchingSites = sites.filter(el =>
|
|
|
|
String(searchResultLink).replace(/(.*)https?(:\/\/|%3A%2F%2F)/, '').startsWith(el.origin_base_url)
|
|
|
|
);
|
2023-07-25 06:17:46 +00:00
|
|
|
if (matchingSites.length > 0) {
|
|
|
|
// Select match with longest base URL
|
|
|
|
let closestMatch = "";
|
|
|
|
matchingSites.forEach(site => {
|
|
|
|
if (site.origin_base_url.length > closestMatch.length) {
|
|
|
|
closestMatch = site.origin_base_url;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let site = matchingSites.find(site => site.origin_base_url === closestMatch);
|
|
|
|
if (site) {
|
|
|
|
// Get user's settings for the wiki
|
|
|
|
let settings = storage.siteSettings || {};
|
|
|
|
let id = site['id'];
|
|
|
|
let searchFilterSetting = '';
|
|
|
|
if (settings.hasOwnProperty(id) && settings[id].searchFilter) {
|
|
|
|
searchFilterSetting = settings[id].searchFilter;
|
|
|
|
} else if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings[site.language]) {
|
|
|
|
searchFilterSetting = storage.defaultSearchFilterSettings[site.language];
|
|
|
|
} else {
|
|
|
|
searchFilterSetting = 'true';
|
|
|
|
}
|
|
|
|
if (searchFilterSetting === 'true') {
|
2023-08-04 05:50:12 +00:00
|
|
|
// Output stylesheet if not already done
|
|
|
|
if (filteredWikis.length === 0) {
|
|
|
|
// Wait for head to be available
|
|
|
|
const headElement = document.querySelector('head');
|
|
|
|
if (headElement) {
|
|
|
|
insertCSS();
|
|
|
|
} else {
|
|
|
|
const docObserver = new MutationObserver(function (mutations, mutationInstance) {
|
|
|
|
const headElement = document.querySelector('head');
|
|
|
|
if (headElement) {
|
|
|
|
insertCSS();
|
|
|
|
mutationInstance.disconnect();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
docObserver.observe(document, {
|
|
|
|
childList: true,
|
|
|
|
subtree: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert search result removal notice
|
|
|
|
if (!filteredWikis.includes(site.origin_group)) {
|
|
|
|
filteredWikis.push(site.origin_group);
|
2023-08-07 06:43:23 +00:00
|
|
|
hiddenWikisRevealed[stringToId(site.origin)] = false;
|
|
|
|
|
2023-08-04 05:50:12 +00:00
|
|
|
let searchRemovalNotice = document.createElement('aside');
|
|
|
|
searchRemovalNotice.id = 'iwb-notice-' + stringToId(site.origin);
|
|
|
|
searchRemovalNotice.classList.add('iwb-notice');
|
|
|
|
let searchRemovalNoticeLink = document.createElement('a');
|
|
|
|
searchRemovalNoticeLink.href = 'https://' + site.destination_base_url;
|
|
|
|
searchRemovalNoticeLink.textContent = site.destination;
|
2023-08-07 06:43:23 +00:00
|
|
|
searchRemovalNoticePretext = document.createTextNode('Indie Wiki Buddy has filtered out results from ' + site.origin_group + '. Look for results from ');
|
2023-08-04 05:50:12 +00:00
|
|
|
searchRemovalNoticePosttext = document.createTextNode(' instead!');
|
|
|
|
linebreak = document.createElement("br");
|
|
|
|
searchRemovalNotice.appendChild(searchRemovalNoticePretext);
|
|
|
|
searchRemovalNotice.appendChild(searchRemovalNoticeLink);
|
|
|
|
searchRemovalNotice.appendChild(searchRemovalNoticePosttext);
|
|
|
|
searchRemovalNotice.appendChild(linebreak);
|
|
|
|
|
|
|
|
// Output "show results" button
|
2023-08-07 06:43:23 +00:00
|
|
|
let showResultsButton = document.createElement('button');
|
2023-08-04 05:50:12 +00:00
|
|
|
showResultsButton.classList.add('iwb-show-results-button');
|
|
|
|
showResultsButton.setAttribute('data-group', 'iwb-search-result-' + stringToId(site.origin));
|
2023-08-07 06:43:23 +00:00
|
|
|
showResultsButton.textContent = 'Show filtered results';
|
2023-08-04 05:50:12 +00:00
|
|
|
searchRemovalNotice.appendChild(showResultsButton);
|
|
|
|
showResultsButton.onclick = function (e) {
|
2023-08-07 06:43:23 +00:00
|
|
|
if(e.target.textContent.includes('Show')) {
|
|
|
|
e.target.textContent = 'Re-hide filtered results';
|
|
|
|
hiddenWikisRevealed[stringToId(site.origin)] = true;
|
|
|
|
const selector = e.currentTarget.dataset.group;
|
|
|
|
document.querySelectorAll('.' + selector).forEach(el => {
|
|
|
|
el.classList.add('iwb-show');
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
e.target.textContent = 'Show filtered results';
|
|
|
|
hiddenWikisRevealed[stringToId(site.origin)] = false;
|
|
|
|
const selector = e.currentTarget.dataset.group;
|
|
|
|
document.querySelectorAll('.' + selector).forEach(el => {
|
|
|
|
el.classList.remove('iwb-show');
|
|
|
|
})
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output "disable filtering" button
|
2023-08-07 06:43:23 +00:00
|
|
|
let disableFilterButton = document.createElement('button');
|
2023-08-04 05:50:12 +00:00
|
|
|
disableFilterButton.classList.add('iwb-disable-filtering-button');
|
2023-08-07 06:43:23 +00:00
|
|
|
disableFilterButton.textContent = 'Stop filtering ' + site.origin_group + ' in future searches';
|
2023-08-04 05:50:12 +00:00
|
|
|
disableFilterButton.style.border = '1px solid';
|
|
|
|
searchRemovalNotice.appendChild(disableFilterButton);
|
|
|
|
disableFilterButton.onclick = function (e) {
|
2023-08-07 06:43:23 +00:00
|
|
|
if (e.target.textContent.includes('Stop')) {
|
|
|
|
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
|
|
|
response.siteSettings.get(site.id).set('searchFilter', 'false');
|
|
|
|
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
|
|
|
e.target.textContent = 'Re-enable filtering for ' + site.origin_group;
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
|
|
|
response.siteSettings.get(site.id).set('searchFilter', 'true');
|
|
|
|
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
|
|
|
e.target.textContent = 'Stop filtering ' + site.origin_group + ' in future searches';
|
|
|
|
})
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (searchEngine) {
|
|
|
|
case 'google':
|
|
|
|
if (document.querySelector('#search')) {
|
|
|
|
document.querySelector('#search').prepend(searchRemovalNotice);
|
|
|
|
} else if (document.querySelector('#topstuff')) {
|
|
|
|
document.querySelector('#topstuff').prepend(searchRemovalNotice);
|
|
|
|
} else if (document.querySelector('#main')) {
|
|
|
|
let el = document.querySelector('#main');
|
|
|
|
el.insertBefore(searchRemovalNotice, el.querySelector('div [data-hveid]').parentElement);
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'bing':
|
|
|
|
let li = document.createElement('li');
|
|
|
|
li.appendChild(searchRemovalNotice);
|
|
|
|
document.querySelector('#b_results').prepend(li);
|
|
|
|
break;
|
|
|
|
case 'duckduckgo':
|
|
|
|
if (document.getElementById('web_content_wrapper')) {
|
|
|
|
let li = document.createElement('li');
|
|
|
|
li.appendChild(searchRemovalNotice);
|
|
|
|
document.querySelector('#web_content_wrapper ol').prepend(li);
|
|
|
|
} else {
|
|
|
|
document.getElementById('links').prepend(searchRemovalNotice);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'brave':
|
|
|
|
document.querySelector('#results').prepend(searchRemovalNotice);
|
|
|
|
break;
|
|
|
|
case 'ecosia':
|
|
|
|
document.querySelector('body').prepend(searchRemovalNotice);
|
|
|
|
break;
|
|
|
|
case 'startpage':
|
|
|
|
document.querySelector('#main').prepend(searchRemovalNotice);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 06:17:46 +00:00
|
|
|
let cssQuery = '';
|
2023-08-04 05:50:12 +00:00
|
|
|
let searchResultContainer = null;
|
2023-07-25 06:17:46 +00:00
|
|
|
switch (searchEngine) {
|
|
|
|
case 'google':
|
|
|
|
if (searchResult.closest('div[data-hveid]')) {
|
|
|
|
cssQuery = 'div[data-hveid]';
|
2023-08-04 05:50:12 +00:00
|
|
|
searchResultContainer = searchResult.closest(cssQuery).parentElement;
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'bing':
|
|
|
|
if (searchResult.closest('li.b_algo')) {
|
|
|
|
cssQuery = 'li.b_algo';
|
2023-08-04 05:50:12 +00:00
|
|
|
searchResultContainer = searchResult.closest(cssQuery);
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'duckduckgo':
|
|
|
|
if (searchResult.closest('li[data-layout], div.web-result')) {
|
|
|
|
cssQuery = 'li[data-layout], div.web-result';
|
2023-08-04 05:50:12 +00:00
|
|
|
searchResultContainer = searchResult.closest(cssQuery);
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'brave':
|
|
|
|
if (searchResult.closest('div.snippet')) {
|
|
|
|
cssQuery = 'div.snippet';
|
2023-08-04 05:50:12 +00:00
|
|
|
searchResultContainer = searchResult.closest(cssQuery);
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'ecosia':
|
2023-08-04 05:50:12 +00:00
|
|
|
if (searchResult.closest('div.mainline__result-wrapper')) {
|
|
|
|
cssQuery = 'div.mainline__result-wrapper';
|
|
|
|
searchResultContainer = searchResult.closest(cssQuery);
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'startpage':
|
2023-08-04 05:50:12 +00:00
|
|
|
if (searchResult.closest('div.w-gl__result')) {
|
|
|
|
cssQuery = 'div.w-gl__result';
|
|
|
|
searchResultContainer = searchResult.closest(cssQuery);
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
|
2023-08-07 06:43:23 +00:00
|
|
|
if(!Array.from(searchResultContainer.classList).includes('iwb-hide')) {
|
|
|
|
searchResultContainer.classList.add('iwb-search-result-' + stringToId(site.origin));
|
|
|
|
searchResultContainer.classList.add('iwb-hide');
|
|
|
|
console.log(searchResultContainer);
|
|
|
|
console.log('weeee');
|
|
|
|
countFiltered++;
|
|
|
|
if (hiddenWikisRevealed[stringToId(site.origin)]) {
|
|
|
|
searchResultContainer.classList.add('iwb-show');
|
|
|
|
}
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-08-04 05:50:12 +00:00
|
|
|
addLocationObserver(main);
|
2023-07-25 06:17:46 +00:00
|
|
|
if (countFiltered > 0) {
|
|
|
|
chrome.storage.sync.set({ 'countSearchFilters': (storage.countSearchFilters ?? 0) + countFiltered });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function main(mutations = null, observer = null) {
|
|
|
|
if (observer) {
|
|
|
|
observer.disconnect();
|
|
|
|
}
|
|
|
|
chrome.storage.local.get(function (localStorage) {
|
|
|
|
chrome.storage.sync.get(function (syncStorage) {
|
|
|
|
const storage = { ...syncStorage, ...localStorage };
|
|
|
|
// Check if extension is on:
|
|
|
|
if ((storage.power ?? 'on') === 'on') {
|
|
|
|
// Determine which search engine we're on
|
|
|
|
if ((storage.searchFilter ?? 'on') === 'on') {
|
|
|
|
if (currentURL.hostname.includes('www.google.')) {
|
2023-07-25 08:47:22 +00:00
|
|
|
// Function to filter search results in Google
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterGoogle() {
|
|
|
|
let searchResults = document.querySelectorAll("div[data-hveid] a[href*='fandom.com']:first-of-type, div[data-hveid] a[href*='fextralife.com']:first-of-type");
|
|
|
|
filterSearchResults(searchResults, 'google', storage);
|
|
|
|
}
|
2023-07-25 08:47:22 +00:00
|
|
|
|
|
|
|
// Wait for document to be interactive/complete:
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
|
|
|
filterGoogle();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('readystatechange', e => {
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
|
|
|
filterGoogle();
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}, { once: true });
|
2023-07-25 08:47:22 +00:00
|
|
|
}
|
2023-07-25 06:17:46 +00:00
|
|
|
} else if (currentURL.hostname.includes('duckduckgo.com') && (currentURL.search.includes('q=') || currentURL.pathname.includes('html'))) {
|
2023-07-25 08:47:22 +00:00
|
|
|
// Function to filter search results in DuckDuckGo
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterDuckDuckGo() {
|
|
|
|
let searchResults = document.querySelectorAll("h2>a[href*='fandom.com'], h2>a[href*='fextralife.com']");
|
|
|
|
filterSearchResults(searchResults, 'duckduckgo', storage);
|
|
|
|
}
|
2023-07-25 08:47:22 +00:00
|
|
|
|
|
|
|
// Wait for document to be interactive/complete:
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterDuckDuckGo();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('readystatechange', e => {
|
2023-07-25 08:47:22 +00:00
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterDuckDuckGo();
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}, { once: true });
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
} else if (currentURL.hostname.includes('www.bing.com')) {
|
2023-07-25 08:47:22 +00:00
|
|
|
// Function to filter search results in Bing
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterBing() {
|
|
|
|
let searchResults = Array.from(document.querySelectorAll(".b_attribution>cite")).filter(el => el.innerHTML.includes('fandom.com') || el.innerHTML.includes('fextralife.com'));
|
|
|
|
filterSearchResults(searchResults, 'bing', storage);
|
|
|
|
}
|
2023-07-25 08:47:22 +00:00
|
|
|
|
|
|
|
// Wait for document to be interactive/complete:
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterBing();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('readystatechange', e => {
|
2023-07-25 08:47:22 +00:00
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterBing();
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}, { once: true });
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
} else if (currentURL.hostname.includes('search.brave.com')) {
|
2023-07-25 08:47:22 +00:00
|
|
|
// Function to filter search results in Brave
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterBrave() {
|
|
|
|
let searchResults = Array.from(document.querySelectorAll(".result-header")).filter(el => el.innerHTML.includes('fandom.com') || el.innerHTML.includes('fextralife.com'));
|
|
|
|
filterSearchResults(searchResults, 'brave', storage);
|
|
|
|
}
|
2023-07-25 08:47:22 +00:00
|
|
|
|
|
|
|
// Wait for document to be interactive/complete:
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterBrave();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('readystatechange', e => {
|
2023-07-25 08:47:22 +00:00
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterBrave();
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}, { once: true });
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
} else if (currentURL.hostname.includes('ecosia.org')) {
|
2023-07-25 08:47:22 +00:00
|
|
|
// Function to filter search results in Ecosia
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterEcosia() {
|
2023-08-04 05:50:12 +00:00
|
|
|
let searchResults = Array.from(document.querySelectorAll("section.mainline .result__title a.result__link")).filter(el => el.href.includes('fandom.com') || el.href.includes('fextralife.com'));
|
2023-07-25 06:17:46 +00:00
|
|
|
filterSearchResults(searchResults, 'ecosia', storage);
|
|
|
|
}
|
2023-07-25 08:47:22 +00:00
|
|
|
|
|
|
|
// Wait for document to be interactive/complete:
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterEcosia();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('readystatechange', e => {
|
2023-07-25 08:47:22 +00:00
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterEcosia();
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}, { once: true });
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
} else if (currentURL.hostname.includes('startpage.com')) {
|
2023-07-25 08:47:22 +00:00
|
|
|
// Function to filter search results in Startpage
|
2023-07-25 06:17:46 +00:00
|
|
|
function filterStartpage() {
|
|
|
|
let searchResults = Array.from(document.querySelectorAll("a.result-link")).filter(el => el.href.includes('fandom.com') || el.href.includes('fextralife.com'));
|
|
|
|
filterSearchResults(searchResults, 'startpage', storage);
|
|
|
|
}
|
2023-07-25 08:47:22 +00:00
|
|
|
|
|
|
|
// Wait for document to be interactive/complete:
|
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterStartpage();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('readystatechange', e => {
|
2023-07-25 08:47:22 +00:00
|
|
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
2023-07-25 06:17:46 +00:00
|
|
|
filterStartpage();
|
|
|
|
}
|
2023-08-04 05:50:12 +00:00
|
|
|
}, { once: true });
|
2023-07-25 06:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|