Updating search engine selectors and styling

pull/227/head
Kevin Payravi 2023-07-22 23:57:04 -05:00
parent d00a5bdaba
commit 4b5c267f00
1 changed files with 21 additions and 10 deletions

View File

@ -13,7 +13,7 @@ Object.prototype.set = function (prop, value) {
this[prop] = value; this[prop] = value;
} }
// Create an observer to watch for mutations // Function to create an observer to watch for mutations on search pages
function addLocationObserver(callback) { function addLocationObserver(callback) {
const config = { const config = {
attributes: false, attributes: false,
@ -157,7 +157,7 @@ function displayRedirectBanner(url, id, destination, storage) {
bannerDisableLink.id = 'indie-wiki-banner-disable'; bannerDisableLink.id = 'indie-wiki-banner-disable';
bannerDisableLink.classList.add('indie-wiki-banner-link'); bannerDisableLink.classList.add('indie-wiki-banner-link');
bannerDisableLink.classList.add('indie-wiki-banner-link-small'); bannerDisableLink.classList.add('indie-wiki-banner-link-small');
bannerDisableLink.innerText = '✕ Disable banner for this wiki' bannerDisableLink.innerText = '✕ Disable banner for this wiki';
bannerControls.appendChild(bannerDisableLink); bannerControls.appendChild(bannerDisableLink);
bannerDisableLink.onclick = function (e) { bannerDisableLink.onclick = function (e) {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) { chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
@ -198,7 +198,7 @@ function displayRedirectBanner(url, id, destination, storage) {
var bannerText = document.createElement('span'); var bannerText = document.createElement('span');
bannerText.classList.add('indie-wiki-banner-big-text'); bannerText.classList.add('indie-wiki-banner-big-text');
banner.appendChild(bannerText); banner.appendChild(bannerText);
bannerText.textContent = 'There is an independent wiki covering this topic!' bannerText.textContent = 'There is an independent wiki covering this topic!';
var bannerWikiLink = document.createElement('a'); var bannerWikiLink = document.createElement('a');
bannerWikiLink.classList.add('indie-wiki-banner-link'); bannerWikiLink.classList.add('indie-wiki-banner-link');
bannerText.appendChild(bannerWikiLink); bannerText.appendChild(bannerWikiLink);
@ -270,10 +270,13 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
} }
if (searchFilterSetting === 'true') { if (searchFilterSetting === 'true') {
let cssQuery = ''; let cssQuery = '';
let color = '';
let fontSize = '';
switch (searchEngine) { switch (searchEngine) {
case 'google': case 'google':
if (searchResult.closest('div[data-hveid]')) { if (searchResult.closest('div[data-hveid] > div')) {
cssQuery = 'div[data-hveid]'; cssQuery = 'div[data-hveid] > div';
fontSize = '14px';
} }
break; break;
case 'bing': case 'bing':
@ -282,8 +285,9 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
} }
break; break;
case 'duckduckgo': case 'duckduckgo':
if (searchResult.closest('div.nrn-react-div')) { if (searchResult.closest('li[data-layout], div.web-result')) {
cssQuery = 'div.nrn-react-div'; cssQuery = 'li[data-layout], div.web-result';
color = 'var(--theme-col-txt-snippet)';
} }
break; break;
case 'brave': case 'brave':
@ -295,9 +299,16 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
} }
if (cssQuery) { if (cssQuery) {
let searchListing = document.createElement('div'); let searchListing = document.createElement('div');
if (color) {
searchListing.style.color = color;
}
if (fontSize) {
searchListing.style.fontSize = fontSize;
}
searchListing.style.fontStyle = 'italic'; searchListing.style.fontStyle = 'italic';
searchListing.style.color = 'var(--search-text-03)'; searchListing.style.padding = '.5em';
let searchListingLink = document.createElement('a'); let searchListingLink = document.createElement('a');
searchListingLink.style.textDecoration = 'underline';
searchListingLink.href = 'https://' + site.destination_base_url; searchListingLink.href = 'https://' + site.destination_base_url;
searchListingLink.textContent = site.destination; searchListingLink.textContent = site.destination;
searchListingPretext = document.createTextNode('A search result from ' + site.origin + ' has been removed by Indie Wiki Buddy. Look for results from '); searchListingPretext = document.createTextNode('A search result from ' + site.origin + ' has been removed by Indie Wiki Buddy. Look for results from ');
@ -415,12 +426,12 @@ function main(mutations = null, observer = null) {
if (currentURL.hostname.includes('www.google.')) { if (currentURL.hostname.includes('www.google.')) {
// Check if doing a Google search: // Check if doing a Google search:
function filterGoogle() { function filterGoogle() {
let searchResults = document.querySelectorAll("div[lang] a[href*='fandom.com'], div[lang] a[href*='fextralife.com']"); 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); filterSearchResults(searchResults, 'google', storage);
} }
addLocationObserver(main); addLocationObserver(main);
filterGoogle(); filterGoogle();
} else if (currentURL.hostname.includes('duckduckgo.com') && currentURL.search.includes('q=')) { } else if (currentURL.hostname.includes('duckduckgo.com') && (currentURL.search.includes('q=') || currentURL.pathname.includes('html'))) {
// Check if doing a Duck Duck Go search: // Check if doing a Duck Duck Go search:
function filterDuckDuckGo() { function filterDuckDuckGo() {
let searchResults = document.querySelectorAll("h2>a[href*='fandom.com'], h2>a[href*='fextralife.com']"); let searchResults = document.querySelectorAll("h2>a[href*='fandom.com'], h2>a[href*='fextralife.com']");