Adding option to hide hidden search results banner

breezewiki-header-control
Kevin Payravi 2023-12-13 03:32:24 -06:00
parent 217eccc7d8
commit b6c8a9559d
5 changed files with 73 additions and 3 deletions

View File

@ -280,9 +280,9 @@ function replaceSearchResults(searchResultContainer, site, link) {
return 0;
}
function hideSearchResults(searchResultContainer, searchEngine, site) {
function hideSearchResults(searchResultContainer, searchEngine, site, showBanner = 'on') {
// Insert search result removal notice
if (!filteredWikis.includes(site.lang + ' ' + site.origin_group)) {
if (showBanner === 'on' && !filteredWikis.includes(site.lang + ' ' + site.origin_group)) {
filteredWikis.push(site.lang + ' ' + site.origin_group);
let elementId = stringToId(site.lang + '-' + site.origin_group);
@ -494,7 +494,7 @@ function filterSearchResults(searchResults, searchEngine, storage) {
if (searchResultContainer) {
if (searchFilterSetting === 'hide') {
countFiltered += hideSearchResults(searchResultContainer, searchEngine, site);
countFiltered += hideSearchResults(searchResultContainer, searchEngine, site, storage['hiddenResultsBanner']);
} else {
countFiltered += replaceSearchResults(searchResultContainer, site, link);
}

View File

@ -350,6 +350,14 @@
redirections
</label>
</div>
<div class="settingToggle">
<label>
<input id="hiddenResultsBannerCheckbox" type="checkbox" />
<span id="hiddenResultsBannerIcon" aria-hidden="true"></span>
On search engines, show banner when
Fandom/Fextralife results have been hidden
</label>
</div>
<div class="settingToggle">
<label>
<input id="crossLanguageCheckbox" type="checkbox" />

View File

@ -234,6 +234,21 @@ function setNotifications(setting, storeSetting = true) {
}
}
// Set search results hidden banner setting
function setHiddenResultsBanner(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'hiddenResultsBanner': setting });
}
const hiddenResultsBannerIcon = document.getElementById('hiddenResultsBannerIcon');
if (setting === 'on') {
document.getElementById('hiddenResultsBannerCheckbox').checked = true;
hiddenResultsBannerIcon.innerText = '🔔';
} else {
document.getElementById('hiddenResultsBannerCheckbox').checked = false;
hiddenResultsBannerIcon.innerText = '🔕';
}
}
// Set cross-language setting
function setCrossLanguage(setting, storeSetting = true) {
if (storeSetting) {
@ -393,6 +408,9 @@ document.addEventListener('DOMContentLoaded', function () {
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
setNotifications(item.notifications, false);
});
chrome.storage.sync.get({ 'hiddenResultsBanner': 'on' }, function (item) {
setHiddenResultsBanner(item.hiddenResultsBanner, false);
});
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
setCrossLanguage(item.crossLanguage, false);
});
@ -427,6 +445,15 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
});
document.getElementById('hiddenResultsBannerCheckbox').addEventListener('change', function () {
chrome.storage.sync.get({ 'hiddenResultsBanner': 'on' }, function (item) {
if (item.hiddenResultsBanner === 'on') {
setHiddenResultsBanner('off');
} else {
setHiddenResultsBanner('on');
}
});
});
document.getElementById('crossLanguageCheckbox').addEventListener('change', function () {
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
if (item.crossLanguage === 'on') {

View File

@ -555,6 +555,14 @@
redirections
</label>
</div>
<div class="settingToggle">
<label>
<input id="hiddenResultsBannerCheckbox" type="checkbox" />
<span id="hiddenResultsBannerIcon" aria-hidden="true"></span>
On search engines, show banner when
Fandom/Fextralife results have been hidden
</label>
</div>
<div class="settingToggle">
<label>
<input id="crossLanguageCheckbox" type="checkbox" />

View File

@ -536,6 +536,21 @@ function setNotifications(setting, storeSetting = true) {
}
}
// Set search results hidden banner setting
function setHiddenResultsBanner(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'hiddenResultsBanner': setting });
}
const hiddenResultsBannerIcon = document.getElementById('hiddenResultsBannerIcon');
if (setting === 'on') {
document.getElementById('hiddenResultsBannerCheckbox').checked = true;
hiddenResultsBannerIcon.innerText = '🔔';
} else {
document.getElementById('hiddenResultsBannerCheckbox').checked = false;
hiddenResultsBannerIcon.innerText = '🔕';
}
}
// Set cross-language setting
function setCrossLanguage(setting, storeSetting = true) {
if (storeSetting) {
@ -785,6 +800,9 @@ document.addEventListener('DOMContentLoaded', function () {
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
setNotifications(item.notifications, false);
});
chrome.storage.sync.get({ 'hiddenResultsBanner': 'on' }, function (item) {
setHiddenResultsBanner(item.hiddenResultsBanner, false);
});
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
setCrossLanguage(item.crossLanguage, false);
});
@ -819,6 +837,15 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
});
document.getElementById('hiddenResultsBannerCheckbox').addEventListener('change', function () {
chrome.storage.sync.get({ 'hiddenResultsBanner': 'on' }, function (item) {
if (item.hiddenResultsBanner === 'on') {
setHiddenResultsBanner('off');
} else {
setHiddenResultsBanner('on');
}
});
});
document.getElementById('crossLanguageCheckbox').addEventListener('change', function () {
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
if (item.crossLanguage === 'on') {