Improving search filter syntax, styling, and text
parent
83c54a421d
commit
451bb15446
|
@ -1,6 +1,6 @@
|
||||||
const currentURL = new URL(document.location);
|
const currentURL = new URL(document.location);
|
||||||
let filteredWikis = [];
|
let filteredWikis = [];
|
||||||
let hiddenWikisRevealed = false;
|
let hiddenWikisRevealed = {};
|
||||||
|
|
||||||
// Create object prototypes for getting and setting attributes:
|
// Create object prototypes for getting and setting attributes:
|
||||||
Object.prototype.get = function (prop) {
|
Object.prototype.get = function (prop) {
|
||||||
|
@ -60,7 +60,7 @@ function insertCSS() {
|
||||||
// Output CSS
|
// Output CSS
|
||||||
styleString = `
|
styleString = `
|
||||||
.iwb-notice {
|
.iwb-notice {
|
||||||
display: block;
|
display: block !important;
|
||||||
margin: .5em .5em 1em .5em !important;
|
margin: .5em .5em 1em .5em !important;
|
||||||
padding: .5em .5em .5em 1em !important;
|
padding: .5em .5em .5em 1em !important;
|
||||||
border-left: 3px solid #FFCC33 !important;
|
border-left: 3px solid #FFCC33 !important;
|
||||||
|
@ -77,14 +77,22 @@ function insertCSS() {
|
||||||
|
|
||||||
.iwb-notice button {
|
.iwb-notice button {
|
||||||
cursor: pointer !important;
|
cursor: pointer !important;
|
||||||
display: inline-block;
|
display: inline-block !important;
|
||||||
padding: 2px 8px !important;
|
padding: 2px 8px !important;
|
||||||
margin: .75em .5em 0 0 !important;
|
margin: 8px 8px 0 0 !important;
|
||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
|
border: 1px solid !important;
|
||||||
border-radius: 5px !important;
|
border-radius: 5px !important;
|
||||||
font-size: 12px !important;
|
font-size: 11px !important;
|
||||||
color: white !important;
|
color: white !important;
|
||||||
mix-blend-mode: difference !important;
|
mix-blend-mode: difference !important;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
.iwb-hide {
|
.iwb-hide {
|
||||||
|
@ -174,13 +182,15 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
// Insert search result removal notice
|
// Insert search result removal notice
|
||||||
if (!filteredWikis.includes(site.origin_group)) {
|
if (!filteredWikis.includes(site.origin_group)) {
|
||||||
filteredWikis.push(site.origin_group);
|
filteredWikis.push(site.origin_group);
|
||||||
|
hiddenWikisRevealed[stringToId(site.origin)] = false;
|
||||||
|
|
||||||
let searchRemovalNotice = document.createElement('aside');
|
let searchRemovalNotice = document.createElement('aside');
|
||||||
searchRemovalNotice.id = 'iwb-notice-' + stringToId(site.origin);
|
searchRemovalNotice.id = 'iwb-notice-' + stringToId(site.origin);
|
||||||
searchRemovalNotice.classList.add('iwb-notice');
|
searchRemovalNotice.classList.add('iwb-notice');
|
||||||
let searchRemovalNoticeLink = document.createElement('a');
|
let searchRemovalNoticeLink = document.createElement('a');
|
||||||
searchRemovalNoticeLink.href = 'https://' + site.destination_base_url;
|
searchRemovalNoticeLink.href = 'https://' + site.destination_base_url;
|
||||||
searchRemovalNoticeLink.textContent = site.destination;
|
searchRemovalNoticeLink.textContent = site.destination;
|
||||||
searchRemovalNoticePretext = document.createTextNode('Indie Wiki Buddy has removed results from ' + site.origin_group + '. Look for results from ');
|
searchRemovalNoticePretext = document.createTextNode('Indie Wiki Buddy has filtered out results from ' + site.origin_group + '. Look for results from ');
|
||||||
searchRemovalNoticePosttext = document.createTextNode(' instead!');
|
searchRemovalNoticePosttext = document.createTextNode(' instead!');
|
||||||
linebreak = document.createElement("br");
|
linebreak = document.createElement("br");
|
||||||
searchRemovalNotice.appendChild(searchRemovalNoticePretext);
|
searchRemovalNotice.appendChild(searchRemovalNoticePretext);
|
||||||
|
@ -189,71 +199,69 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
searchRemovalNotice.appendChild(linebreak);
|
searchRemovalNotice.appendChild(linebreak);
|
||||||
|
|
||||||
// Output "show results" button
|
// Output "show results" button
|
||||||
var showResultsButton = document.createElement('button');
|
let showResultsButton = document.createElement('button');
|
||||||
showResultsButton.classList.add('iwb-show-results-button');
|
showResultsButton.classList.add('iwb-show-results-button');
|
||||||
showResultsButton.setAttribute('data-group', 'iwb-search-result-' + stringToId(site.origin));
|
showResultsButton.setAttribute('data-group', 'iwb-search-result-' + stringToId(site.origin));
|
||||||
showResultsButton.innerText = 'Reveal filtered results';
|
showResultsButton.textContent = 'Show filtered results';
|
||||||
showResultsButton.style.border = '1px solid';
|
|
||||||
searchRemovalNotice.appendChild(showResultsButton);
|
searchRemovalNotice.appendChild(showResultsButton);
|
||||||
showResultsButton.onclick = function (e) {
|
showResultsButton.onclick = function (e) {
|
||||||
hiddenWikisRevealed = true;
|
if(e.target.textContent.includes('Show')) {
|
||||||
const selector = e.currentTarget.dataset.group;
|
e.target.textContent = 'Re-hide filtered results';
|
||||||
document.querySelectorAll('.' + selector).forEach(el => {
|
hiddenWikisRevealed[stringToId(site.origin)] = true;
|
||||||
el.classList.add('iwb-show');
|
const selector = e.currentTarget.dataset.group;
|
||||||
e.target.style.display = 'none';
|
document.querySelectorAll('.' + selector).forEach(el => {
|
||||||
e.target.parentNode.querySelector('.iwb-hide-results-button').style.display = 'inline-block';
|
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');
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output "re-hide results" button
|
// Output "change settings" link
|
||||||
var hideResultsButton = document.createElement('button');
|
// let changeSettingsLink = document.createElement('a');
|
||||||
hideResultsButton.classList.add('iwb-hide-results-button');
|
// changeSettingsLink.href = chrome.extension.getURL('settings.html');
|
||||||
hideResultsButton.setAttribute('data-group', 'iwb-search-result-' + stringToId(site.origin));
|
// changeSettingsLink.target = '_blank';
|
||||||
hideResultsButton.innerText = 'Re-hide filtered results';
|
// changeSettingsLink.textContent = 'Change settings';
|
||||||
hideResultsButton.style.border = '1px solid';
|
// searchRemovalNotice.appendChild(changeSettingsLink);
|
||||||
hideResultsButton.style.display = 'none';
|
|
||||||
searchRemovalNotice.appendChild(hideResultsButton);
|
|
||||||
hideResultsButton.onclick = function (e) {
|
|
||||||
hiddenWikisRevealed = false;
|
|
||||||
const selector = e.currentTarget.dataset.group;
|
|
||||||
document.querySelectorAll('.' + selector).forEach(el => {
|
|
||||||
el.classList.remove('iwb-show');
|
|
||||||
e.target.style.display = 'none';
|
|
||||||
e.target.parentNode.querySelector('.iwb-show-results-button').style.display = 'inline-block';
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output "disable filtering" button
|
// Output "disable filtering" button
|
||||||
var disableFilterButton = document.createElement('button');
|
let disableFilterButton = document.createElement('button');
|
||||||
disableFilterButton.classList.add('iwb-disable-filtering-button');
|
disableFilterButton.classList.add('iwb-disable-filtering-button');
|
||||||
disableFilterButton.innerText = 'Disable search engine filtering for this wiki';
|
disableFilterButton.textContent = 'Stop filtering ' + site.origin_group + ' in future searches';
|
||||||
disableFilterButton.style.border = '1px solid';
|
disableFilterButton.style.border = '1px solid';
|
||||||
searchRemovalNotice.appendChild(disableFilterButton);
|
searchRemovalNotice.appendChild(disableFilterButton);
|
||||||
disableFilterButton.onclick = function (e) {
|
disableFilterButton.onclick = function (e) {
|
||||||
console.log(site);
|
if (e.target.textContent.includes('Stop')) {
|
||||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||||
response.siteSettings.get(site.id).set('searchFilter', 'false');
|
response.siteSettings.get(site.id).set('searchFilter', 'false');
|
||||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||||
e.target.style.display = 'none';
|
e.target.textContent = 'Re-enable filtering for ' + site.origin_group;
|
||||||
e.target.parentNode.querySelector('.iwb-enable-filtering-button').style.display = 'inline-block';
|
document.getElementById('iwb-reload-link-' + stringToId(site.origin)).classList.remove('iwb-hide');
|
||||||
});
|
})
|
||||||
|
} 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';
|
||||||
|
document.getElementById('iwb-reload-link-' + stringToId(site.origin)).classList.add('iwb-hide');
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output "enable filtering" button
|
// Output refresh link
|
||||||
var enableFilterButton = document.createElement('button');
|
let reloadLink = document.createElement('a');
|
||||||
enableFilterButton.classList.add('iwb-enable-filtering-button');
|
reloadLink.id = 'iwb-reload-link-' + stringToId(site.origin);
|
||||||
enableFilterButton.innerText = 'Search filtering disabled (click to undo)';
|
reloadLink.href = "#";
|
||||||
enableFilterButton.style.border = '1px solid';
|
reloadLink.textContent = 'Reload page';
|
||||||
enableFilterButton.style.display = 'none';
|
reloadLink.classList.add('iwb-hide');
|
||||||
searchRemovalNotice.appendChild(enableFilterButton);
|
searchRemovalNotice.appendChild(reloadLink);
|
||||||
enableFilterButton.onclick = function (e) {
|
reloadLink.onclick = function (e) {
|
||||||
console.log(site);
|
window.location.reload();
|
||||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
|
||||||
response.siteSettings.get(site.id).set('searchFilter', 'true');
|
|
||||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
|
||||||
e.target.style.display = 'none';
|
|
||||||
e.target.parentNode.querySelector('.iwb-disable-filtering-button').style.display = 'inline-block';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (searchEngine) {
|
switch (searchEngine) {
|
||||||
|
@ -293,7 +301,6 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
countFiltered++;
|
|
||||||
|
|
||||||
let cssQuery = '';
|
let cssQuery = '';
|
||||||
let searchResultContainer = null;
|
let searchResultContainer = null;
|
||||||
|
@ -337,10 +344,15 @@ function filterSearchResults(searchResults, searchEngine, storage) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
searchResult.closest(cssQuery).classList.add('iwb-search-result-' + stringToId(site.origin));
|
if(!Array.from(searchResultContainer.classList).includes('iwb-hide')) {
|
||||||
searchResult.closest(cssQuery).classList.add('iwb-hide');
|
searchResultContainer.classList.add('iwb-search-result-' + stringToId(site.origin));
|
||||||
if (hiddenWikisRevealed) {
|
searchResultContainer.classList.add('iwb-hide');
|
||||||
searchResult.closest(cssQuery).classList.add('iwb-show');
|
console.log(searchResultContainer);
|
||||||
|
console.log('weeee');
|
||||||
|
countFiltered++;
|
||||||
|
if (hiddenWikisRevealed[stringToId(site.origin)]) {
|
||||||
|
searchResultContainer.classList.add('iwb-show');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue