Mobile search engine filtering improvements
parent
5ee56c5231
commit
ae70730683
|
@ -12,6 +12,8 @@ Object.prototype.set = function (prop, value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to create an observer to watch for mutations on search pages
|
// 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 addLocationObserver(callback) {
|
||||||
const config = {
|
const config = {
|
||||||
attributes: false,
|
attributes: false,
|
||||||
|
@ -190,7 +192,6 @@ function escapeRegex(string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceSearchResults(searchResultContainer, site, link) {
|
function replaceSearchResults(searchResultContainer, site, link) {
|
||||||
let countFiltered = 0;
|
|
||||||
// Build new URL:
|
// Build new URL:
|
||||||
let article = link.split(site['origin_content_path'])[1]?.split('#')[0].split('?')[0].split('&')[0];
|
let article = link.split(site['origin_content_path'])[1]?.split('#')[0].split('?')[0].split('&')[0];
|
||||||
let newURL = '';
|
let newURL = '';
|
||||||
|
@ -214,6 +215,7 @@ function replaceSearchResults(searchResultContainer, site, link) {
|
||||||
searchResultContainer.classList.add('iwb-detected');
|
searchResultContainer.classList.add('iwb-detected');
|
||||||
searchResultContainer.classList.add('iwb-disavow');
|
searchResultContainer.classList.add('iwb-disavow');
|
||||||
}
|
}
|
||||||
|
// Using aside to avoid conflicts with website CSS and listeners:
|
||||||
let indieContainer = document.createElement('aside');
|
let indieContainer = document.createElement('aside');
|
||||||
indieContainer.classList.add('iwb-new-link-container');
|
indieContainer.classList.add('iwb-new-link-container');
|
||||||
let indieResultLink = document.createElement('a');
|
let indieResultLink = document.createElement('a');
|
||||||
|
@ -260,13 +262,13 @@ function replaceSearchResults(searchResultContainer, site, link) {
|
||||||
indieContainer.appendChild(indieResultLink);
|
indieContainer.appendChild(indieResultLink);
|
||||||
indieContainer.appendChild(resultControls);
|
indieContainer.appendChild(resultControls);
|
||||||
searchResultContainer.prepend(indieContainer);
|
searchResultContainer.prepend(indieContainer);
|
||||||
countFiltered++;
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
return countFiltered;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSearchResults(searchResultContainer, searchEngine, site) {
|
function hideSearchResults(searchResultContainer, searchEngine, site) {
|
||||||
let countFiltered = 0;
|
|
||||||
// Insert search result removal notice
|
// Insert search result removal notice
|
||||||
if (!filteredWikis.includes(site.lang + ' ' + site.origin_group)) {
|
if (!filteredWikis.includes(site.lang + ' ' + site.origin_group)) {
|
||||||
filteredWikis.push(site.lang + ' ' + site.origin_group);
|
filteredWikis.push(site.lang + ' ' + site.origin_group);
|
||||||
|
@ -274,6 +276,7 @@ function hideSearchResults(searchResultContainer, searchEngine, site) {
|
||||||
let elementId = stringToId(site.lang + '-' + site.origin_group);
|
let elementId = stringToId(site.lang + '-' + site.origin_group);
|
||||||
hiddenWikisRevealed[elementId] = false;
|
hiddenWikisRevealed[elementId] = false;
|
||||||
|
|
||||||
|
// Using aside to avoid conflicts with website CSS and listeners:
|
||||||
let searchRemovalNotice = document.createElement('aside');
|
let searchRemovalNotice = document.createElement('aside');
|
||||||
searchRemovalNotice.id = 'iwb-notice-' + elementId;
|
searchRemovalNotice.id = 'iwb-notice-' + elementId;
|
||||||
searchRemovalNotice.classList.add('iwb-notice');
|
searchRemovalNotice.classList.add('iwb-notice');
|
||||||
|
@ -370,13 +373,14 @@ function hideSearchResults(searchResultContainer, searchEngine, site) {
|
||||||
let elementId = stringToId(site.lang + '-' + site.origin_group);
|
let elementId = stringToId(site.lang + '-' + site.origin_group);
|
||||||
searchResultContainer.classList.add('iwb-search-result-' + elementId);
|
searchResultContainer.classList.add('iwb-search-result-' + elementId);
|
||||||
searchResultContainer.classList.add('iwb-hide');
|
searchResultContainer.classList.add('iwb-hide');
|
||||||
countFiltered++;
|
searchResultContainer.classList.add('iwb-detected');
|
||||||
if (hiddenWikisRevealed[elementId]) {
|
if (hiddenWikisRevealed[elementId]) {
|
||||||
searchResultContainer.classList.add('iwb-show');
|
searchResultContainer.classList.add('iwb-show');
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return countFiltered;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterSearchResults(searchResults, searchEngine, storage) {
|
function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
|
@ -386,6 +390,8 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
|
|
||||||
for (let searchResult of searchResults) {
|
for (let searchResult of searchResults) {
|
||||||
try {
|
try {
|
||||||
|
// Check that result isn't within another result
|
||||||
|
if (!searchResult.closest('.iwb-detected')) {
|
||||||
let searchResultLink = '';
|
let searchResultLink = '';
|
||||||
if (searchEngine === 'bing') {
|
if (searchEngine === 'bing') {
|
||||||
searchResultLink = searchResult.innerHTML.replaceAll('<strong>', '').replaceAll('</strong>', '');
|
searchResultLink = searchResult.innerHTML.replaceAll('<strong>', '').replaceAll('</strong>', '');
|
||||||
|
@ -403,9 +409,9 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
|
|
||||||
// Check if site is in our list of wikis:
|
// Check if site is in our list of wikis:
|
||||||
if (crossLanguageSetting === 'on') {
|
if (crossLanguageSetting === 'on') {
|
||||||
matchingSites = sites.filter(el => link.replace(/^https?:\/\//, '').startsWith(el.origin_base_url));
|
matchingSites = sites.filter(el => link.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url));
|
||||||
} else {
|
} else {
|
||||||
matchingSites = sites.filter(el => link.replace(/^https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path));
|
matchingSites = sites.filter(el => link.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path));
|
||||||
}
|
}
|
||||||
if (matchingSites.length > 0) {
|
if (matchingSites.length > 0) {
|
||||||
// Select match with longest base URL
|
// Select match with longest base URL
|
||||||
|
@ -486,6 +492,7 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue