From dff009d2ffbfb60b18ce69f82a475bba7bee5ba2 Mon Sep 17 00:00:00 2001 From: Kevin Payravi Date: Sun, 18 Feb 2024 00:41:06 -0600 Subject: [PATCH] Implementing search filtering on Yandex --- README.md | 2 +- manifest-chromium.json | 1 + manifest-firefox.json | 1 + pages/guide/index.html | 2 +- scripts/common-functions.js | 7 +++--- scripts/content-search-filtering.js | 35 +++++++++++++++++++++++++---- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dfbe555..af01b3d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Large, corporate-run wiki farms have enabled hundreds of great wikis and communi When visiting a wiki on a large corporate wiki farm such as Fandom, Indie Wiki Buddy will notify and/or automatically redirect you if a quality, independent alternative is available. You can customize your experience per-wiki. -In addition, search results in Google, Bing, DuckDuckGo, Yahoo, Brave Search, Ecosia, Startpage, and Qwant can also be filtered, replacing non-independent wikis with text inviting you to visit the independent counterpart. +In addition, search results in Google, Bing, DuckDuckGo, Yahoo, Brave Search, Ecosia, Startpage, Qwant, and Yandex can also be filtered, replacing non-independent wikis with text inviting you to visit the independent counterpart. Indie Wiki Buddy also supports [BreezeWiki](https://breezewiki.com/), a service that renders Fandom wikis without ads or bloat. This helps give you a more enjoyable reading experience on Fandom when an independent wiki isn't available. diff --git a/manifest-chromium.json b/manifest-chromium.json index 5e65c07..ea062f3 100644 --- a/manifest-chromium.json +++ b/manifest-chromium.json @@ -62,6 +62,7 @@ "https://*.duckduckgo.com/*", "https://*.ecosia.org/*", "https://*.qwant.com/*", + "https://*.yandex.com/*", "https://*.startpage.com/*", "https://*.search.yahoo.com/*", "https://www.google.com/search*", diff --git a/manifest-firefox.json b/manifest-firefox.json index caa1f3b..9797cf8 100644 --- a/manifest-firefox.json +++ b/manifest-firefox.json @@ -119,6 +119,7 @@ "https://*.duckduckgo.com/*", "https://*.ecosia.org/*", "https://*.qwant.com/*", + "https://*.yandex.com/*", "https://*.startpage.com/*", "https://*.search.yahoo.com/*", "https://www.google.com/search*", diff --git a/pages/guide/index.html b/pages/guide/index.html index 6b2b336..c7f3d54 100644 --- a/pages/guide/index.html +++ b/pages/guide/index.html @@ -101,7 +101,7 @@

When you visit a wiki on a large, corporate-run wiki host, this extension can notify or automatically redirect you to quality independent wikis when they're available. - Search results in Google, Bing, DuckDuckGo, Yahoo, Brave Search, Ecosia, Startpage, and Qwant can also be filtered, + Search results in Google, Bing, DuckDuckGo, Yahoo, Brave Search, Ecosia, Startpage, Qwant, and Yandex can also be filtered, replacing non-independent wikis with links to independent counterpart (or hiding them completely).

We currently redirect from Fandom and Fextralife wikis to independent counterparts. diff --git a/scripts/common-functions.js b/scripts/common-functions.js index 8985bba..a6c4598 100644 --- a/scripts/common-functions.js +++ b/scripts/common-functions.js @@ -113,9 +113,10 @@ async function commonFunctionFindMatchingSite(site, crossLanguageSetting) { if (crossLanguageSetting === 'on') { matchingSites = sites.filter(el => site.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url)); } else { - matchingSites = sites.filter(el => - site.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path) - || site.replace(/.*https?:\/\//, '') === el.origin_base_url + matchingSites = sites.filter(el => { + return site.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path) + || site.replace(/.*https?:\/\//, '').replace(/\/$/, '') === el.origin_base_url + } ); } if (matchingSites.length > 0) { diff --git a/scripts/content-search-filtering.js b/scripts/content-search-filtering.js index 093fb22..360d32c 100644 --- a/scripts/content-search-filtering.js +++ b/scripts/content-search-filtering.js @@ -18,14 +18,14 @@ function base64Decode(text) { // Function to create an observer to watch for mutations on search pages // This is used for search engines that paginate via JavaScript, // or overwrite their results and remove IWB's elements -function addLocationObserver(callback) { +function addDOMChangeObserver(callback) { const config = { attributes: false, childList: true, subtree: true } - const observer = new MutationObserver(callback); - observer.observe(document.body, config); + const domObserver = new MutationObserver(callback); + domObserver.observe(document.body, config); } function insertCSS() { @@ -322,6 +322,10 @@ function hideSearchResults(searchResultContainer, searchEngine, site, showBanner case 'startpage': document.querySelector('#main').prepend(searchRemovalNotice); break; + case 'yandex': + var searchResultsContainer = document.querySelector('#search-result') || document.querySelector('.main__content .content'); + searchResultsContainer?.prepend(searchRemovalNotice); + break; case 'yahoo': if (document.querySelector('#web > ol')) { var li = document.createElement('li'); @@ -475,6 +479,9 @@ async function filterSearchResults(searchResults, searchEngine, storage) { case 'startpage': searchResultContainer = searchResult.closest('div.w-gl__result'); break; + case 'yandex': + searchResultContainer = searchResult.closest('.serp-item'); + break; case 'yahoo': searchResultContainer = searchResult.closest('#web > ol > li div.itm .exp, #web > ol > li div.algo, #web > ol > li, section.algo'); break; @@ -497,7 +504,7 @@ async function filterSearchResults(searchResults, searchEngine, storage) { }; // Add location observer to check for additional mutations - addLocationObserver(main); + addDOMChangeObserver(main); // If any results were filtered, update search filter count if (countFiltered > 0) { @@ -666,6 +673,26 @@ function main(mutations = null, observer = null) { } }, { once: true }); } + } else if (currentURL.hostname.includes('yandex.com')) { + // Function to filter search results in Yandex + function filterYandex() { + let searchResults = Array.from(document.querySelectorAll('.serp-item a.link, .serp-item a.Link')).filter(el => + el.href?.includes('.fandom.com') || + el.href?.includes('.wiki.fextralife.com') || + el.href?.includes('.neoseeker.com/wiki/')); + filterSearchResults(searchResults, 'yandex', storage); + } + + // Wait for document to be interactive/complete: + if (['interactive', 'complete'].includes(document.readyState)) { + filterYandex(); + } else { + document.addEventListener('readystatechange', e => { + if (['interactive', 'complete'].includes(document.readyState)) { + filterYandex(); + } + }, { once: true }); + } } else if (currentURL.hostname.includes('yahoo.com')) { // Function to filter search results in Yahoo function filterYahoo() {