Adding per-wiki search engine settings / Revamping settings UI

pull/311/head
Kevin Payravi 2023-11-02 03:12:35 -05:00
parent 29d6909679
commit 32c9ea5f1b
14 changed files with 893 additions and 728 deletions

View File

@ -36,6 +36,33 @@ chrome.runtime.onInstalled.addListener(function (detail) {
if (detail.reason === 'update') {
chrome.tabs.create({ url: 'https://getindie.wiki/changelog/?updated=true' });
}
// Temporary function for 3.0 migration
// On update, set new default action settings:
if (detail.reason === 'update') {
chrome.storage.sync.get({ 'defaultWikiAction': null }, function (item) {
if (!item.defaultWikiAction) {
chrome.storage.sync.get({ 'defaultActionSettings': {} }, function (item) {
if (item.defaultActionSettings['EN']) {
chrome.storage.sync.set({ 'defaultWikiAction': item.defaultActionSettings['EN'] });
}
});
}
});
chrome.storage.sync.get({ 'defaultSearchAction': null }, function (item) {
if (!item.defaultSearchAction) {
chrome.storage.sync.get({ 'defaultSearchFilterSettings': {} }, function (item) {
if (item.defaultSearchFilterSettings['EN']) {
if (item.defaultSearchFilterSettings['EN'] === 'true') {
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
} else if (item.defaultSearchFilterSettings['EN'] === 'false') {
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
}
}
});
}
});
}
});
if (chrome.declarativeNetRequest) {
@ -300,8 +327,8 @@ async function main(eventInfo) {
let siteSetting = '';
if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) {
siteSetting = settings[id].action;
} else if (storage.defaultActionSettings && storage.defaultActionSettings[site.language]) {
siteSetting = storage.defaultActionSettings[site.language];
} else if (storage.defaultWikiAction) {
siteSetting = storage.defaultWikiAction;
} else {
siteSetting = 'alert';
}

View File

@ -266,15 +266,15 @@ function hideSearchResults(searchResultContainer, searchEngine, site) {
searchRemovalNotice.appendChild(disableFilterButton);
disableFilterButton.onclick = function (e) {
if (e.target.textContent.includes('Stop')) {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
response.siteSettings.get(site.id).set('searchFilter', 'false');
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
response.searchEngineSettings.get(site.id).set('action', 'disabled');
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
e.target.textContent = 'Re-enable filtering for ' + site.origin_group;
})
} else {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
response.siteSettings.get(site.id).set('searchFilter', 'true');
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
response.searchEngineSettings.get(site.id).set('action', 'hide');
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
e.target.textContent = 'Stop filtering ' + site.origin_group + ' in future searches';
})
}
@ -387,17 +387,17 @@ function filterSearchResults(searchResults, searchEngine, storage) {
let site = matchingSites.find(site => site.origin_base_url === closestMatch);
if (site) {
// Get user's settings for the wiki
let settings = storage.siteSettings || {};
let settings = storage.searchEngineSettings || {};
let id = site['id'];
let searchFilterSetting = '';
if (settings.hasOwnProperty(id) && settings[id].searchFilter) {
searchFilterSetting = settings[id].searchFilter;
} else if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings[site.language]) {
searchFilterSetting = storage.defaultSearchFilterSettings[site.language];
if (settings.hasOwnProperty(id) && settings[id].action) {
searchFilterSetting = settings[id].action;
} else if (storage.defaultSearchAction) {
searchFilterSetting = storage.defaultSearchAction;
} else {
searchFilterSetting = 'true';
searchFilterSetting = 'replace';
}
if (searchFilterSetting === 'true') {
if (searchFilterSetting !== 'disabled') {
// Output stylesheet if not already done
if (filteredWikis.length === 0) {
// Wait for head to be available
@ -419,7 +419,6 @@ function filterSearchResults(searchResults, searchEngine, storage) {
}
}
let cssQuery = '';
let searchResultContainer = null;
switch (searchEngine) {
case 'google':
@ -447,7 +446,7 @@ function filterSearchResults(searchResults, searchEngine, storage) {
}
if (searchResultContainer) {
if (storage.searchSetting === 'hide') {
if (searchFilterSetting === 'hide') {
countFiltered += hideSearchResults(searchResultContainer, searchEngine, site);
} else {
countFiltered += redirectSearchResults(searchResultContainer, site, link);
@ -477,7 +476,7 @@ function main(mutations = null, observer = null) {
// Check if extension is on:
if ((storage.power ?? 'on') === 'on') {
// Determine which search engine we're on
if ((storage.searchSetting ?? 'replace') !== 'nothing') {
if ((storage.action ?? 'replace') !== 'nothing') {
if (currentURL.hostname.includes('www.google.')) {
// Function to filter search results in Google
function filterGoogle() {

View File

@ -111,40 +111,13 @@
</p>
<h2>Global settings help</h2>
<p>
There are four global settings options:
There are three global settings options:
</p>
<ul>
<li>
<b>Extension is on/off</b>
<b>🔋 Extension is on/off</b>
<br />
This allows you to enable/disable all Indie Wiki Buddy functionality at the click of a button.
</li>
<br />
<li>
<b>🔎 Search engine options</b>
<br />
Indie Wiki Buddy provides two ways to filter results from
Google, Bing, DuckDuckGo, Yahoo, Brave Search, Ecosia, and Startpage.
<br />
<br />
When "disable non-indie wikis & add link to indie counterparts" is selected,
tracked Fandom and Fextralife wikis that appear in search engine results
will be disabled, and a button will be inserted above that attempts to
link you to the same article on the respective indie wiki.
<br />
<br />
When "hide non-indie wikis that have indie counterparts" is selected,
the results are completely hidden. A notice will be inserted at the top of the search page
letting you know that results were hidden, and you will have the option to temporarily
re-reveal the results or disable search engine filtering for that particular wiki.
<br />
<br />
If you don't want a particular Fandom or Fextralife wiki to be filtered from search results,
you can disable search engine filtering per-wiki on the full settings page.
<br />
<br />
Note that image results are not filtered;
we don't want users to miss out on images they might not find elsewhere!
Enable/disable all Indie Wiki Buddy functionality at the click of a button.
</li>
<br />
<li>
@ -160,7 +133,7 @@
</li>
<br />
<li>
<b>🌬️ Use BreezeWiki on Fandom</b>
<b>🌬️ Use BreezeWiki alternative frontend on Fandom</b>
<br />
This option will render Fandom wikis through <a href="https://breezewiki.com/">BreezeWiki</a>, an external service that removes clutter, simplifies the page, and removes ads.
Occasionally, BreezeWiki or one of its mirrors may go down; when this happens, you can simply switch to another working instance. This is off by default.
@ -171,10 +144,13 @@
In the individual settings section, you can configure your settings per-wiki.
<br />
<br />
The first dropdown lets you switch between lists of wikis in different languages.
The "Default settings for future wikis" options let you set the default behavior for wikis added to Indie Wiki Buddy in the future.
<br />
<br />
Below that is a list of all supported wikis (listed as "non-indie wiki » indie wiki"). You can select what happens whenever you visit each listed non-indie wiki.
Below that is a list of all supported wikis. You can select what happens whenever you visit each listed non-indie wiki.
</p>
<p>
The first set of radio buttons controls what happens when you visit the listed non-indie wikis.
</p>
<ul class="no-markers">
<li>
@ -191,21 +167,29 @@
<b>Alert</b>: Have a display banner at the top notifying you that an independent wiki is available.
This will appear on both Fandom and BreezeWiki pages.
</li>
</ul>
<p>
The second set of radio buttons controls what happens to the non-indie wiki on Google, Bing, DuckDuckGo, and other search engines.
</p>
<ul class="no-markers">
<li>
<img src="./images/toggle-search-filter.png" alt="" width="15">
<b>Search filtering</b>: Replace search results in Google, Bing, DuckDuckGo, and other search engines
with text inviting you to visit the independent wiki.
Oftentimes, the non-independent wiki should appear in that same search.
<img src="./images/toggle-disabled.png" alt="" width="15">
<b>Disable</b>: Search engine results are not affected.
</li>
<li>
<img src="./images/toggle-hide.png" alt="" width="15">
<b>Hide</b>: Results are hidden in search engines.
A banner will be shown near the top of the page to inform you, and allow you to re-reveal the hidden results.
</li>
<li>
<img src="./images/toggle-replace.png" alt="" width="15">
<b>Replace</b>: The original non-indie result is disabled, and a button is injected above to take you to the indepedent wiki.
</li>
</ul>
<p>
By default, all wikis will be set to alert with search filtering enabled.
By default, all wikis will be set to alert, with search engine replacement enabled.
You can quickly change the settings for all wikis in the current language view by using the control
buttons above the list of wikis. For example, if you want to be automatically redirect for all wikis,
click "Set all to redirect to indie wikis".
<br /><br />
Once you click on one of these "select all" buttons, that settings
will become the new default for any wikis that are added to the extension in the future.
buttons above the list of wikis.
</p>
<h2>Have questions or feedback?</h2>
<p>

BIN
images/lock-closed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

BIN
images/lock-opened.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 456 B

BIN
images/toggle-hide.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

BIN
images/toggle-replace.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

View File

@ -103,6 +103,9 @@
cursor: pointer;
background-color: #fff;
border-radius: 20px;
width: 30px;
height: 30px;
text-align: center;
}
#power > input {
height: 0;
@ -112,8 +115,9 @@
appearance: none;
}
#power img {
width: 30px;
vertical-align: middle;
position: relative;
top: 50%;
transform: translateY(-50%);
}
/* CONTENT */
@ -170,38 +174,19 @@
<div id="power">
<input id="powerCheckbox" type="checkbox" />
<label for="powerCheckbox">
<img id="powerImage" src="" alt="" width="30" />
<img id="powerImage" src="" alt="" width="20" />
</label>
</div>
<h1>Indie Wiki Buddy</h1>
</div>
<div id="content">
<div class="options">
<div class="settingToggleContainer">
<div id="searchFilteringReplace" class="settingToggle">
<label for="searchFilteringReplaceRadio">
<input id="searchFilteringReplaceRadio" type="radio" name="searchSetting" value="replace" />
<span id="searchFilteringReplaceText">🔎 In search engines, disable non-indie wikis & add link to indie counterparts</span>
</label>
</div>
<div id="searchFilteringHide" class="settingToggle">
<label for="searchFilteringHideRadio">
<input id="searchFilteringHideRadio" type="radio" name="searchSetting" value="hide" />
<span id="searchFilteringHideText">🔎 In search engines, hide non-indie wikis that have indie counterparts</span>
</label>
</div>
<div id="searchFilteringNothing" class="settingToggle">
<label for="searchFilteringNothingRadio">
<input id="searchFilteringNothingRadio" type="radio" name="searchSetting" value="nothing" />
<span id="searchFilteringNothingText">🔎 Do nothing on search engines</span>
</label>
</div>
</div>
<div class="settingToggleContainer">
<div id="notifications" class="settingToggle">
<input id="notificationsCheckbox" type="checkbox" />
<label for="notificationsCheckbox">
<span id="notificationsText">🔔 Desktop notifications when redirected to an indie wiki or BreezeWiki</span>
<span id="notificationsText"><span id="notificationsIcon" aria-hidden="true"></span>
Desktop notifications for redirections</span>
</label>
</div>
</div>
@ -271,9 +256,8 @@
<div id="notificationBannerContainer">
<span id="notificationBannerChromeBug">
Chromium users: Due to a <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=1271154" target="_blank">browser bug</a>,
this extension may stop working after an update. If this happens, try restarting your browser,
turning the extension off and on via your browser's extension settings (chrome://extensions/),
and/or reinstalling the extension.
this extension may stop working after an update. If this happens, try turning the extension off
and on via your browser's extension settings (chrome://extensions/).
<a id="chromeBugHideLink" href="#">Hide this message</a>
</span>
<span id="notificationBannerOpera">

View File

@ -137,24 +137,14 @@ function setNotifications(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'notifications': setting });
}
const notificationsIcon = document.getElementById('notificationsIcon');
if (setting === 'on') {
document.getElementById('notificationsCheckbox').checked = true;
notificationsIcon.innerText = '🔔';
} else {
document.getElementById('notificationsCheckbox').checked = false;
}
}
// Set search filter setting
function setSearchSetting(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'searchSetting': setting });
}
if (setting === 'hide') {
document.getElementById('searchFilteringHideRadio').checked = true;
} else if (setting === 'nothing') {
document.getElementById('searchFilteringNothingRadio').checked = true;
} else {
document.getElementById('searchFilteringReplaceRadio').checked = true;
notificationsIcon.innerText = '🔕';
}
}
@ -297,15 +287,7 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
});
document.getElementById('searchFilteringReplaceRadio').addEventListener('change', function () {
setSearchSetting('replace');
});
document.getElementById('searchFilteringHideRadio').addEventListener('change', function () {
setSearchSetting('hide');
});
document.getElementById('searchFilteringNothingRadio').addEventListener('change', function () {
setSearchSetting('nothing');
});
document.getElementById('breezewikiCheckbox').addEventListener('change', function () {
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
if (item.breezewiki === 'on') {

File diff suppressed because it is too large Load Diff

View File

@ -13,15 +13,16 @@ Object.prototype.set = function(prop, value) {
// Clear wiki toggles
// Used when switching languages
function resetOptions() {
var toggleContainer = document.getElementById('toggles');
const toggleContainer = document.getElementById('toggles');
toggleContainer.textContent = "";
// Clone "select all" buttons to reset listeners
document.getElementById('setAllDisabled').cloneNode(true);
document.getElementById('setAllRedirect').cloneNode(true);
document.getElementById('setAllAlert').cloneNode(true);
document.getElementById('setAllDisabled').cloneNode(true);
document.getElementById('setAllSearchFilter').cloneNode(true);
document.getElementById('setNoneSearchFilter').cloneNode(true);
document.getElementById('setAllSearchEngineDisabled').cloneNode(true);
document.getElementById('setAllSearchEngineHide').cloneNode(true);
document.getElementById('setAllSearchEngineReplace').cloneNode(true);
}
// Get wiki data from data folder
@ -145,12 +146,16 @@ async function loadBreezeWikiOptions() {
async function loadOptions(lang) {
sites = await getData();
// Sort sites alphabetically by destination
sites.sort((a, b) => a.destination.localeCompare(b.destination));
chrome.storage.local.get(function (localStorage) {
chrome.storage.sync.get(function (syncStorage) {
const storage = {...syncStorage, ...localStorage};
let siteSettings = storage.siteSettings || {};
let defaultActionSettings = storage.defaultActionSettings || {};
let defaultSearchFilterSettings = storage.defaultSearchFilterSettings || {};
let searchEngineSettings = storage.searchEngineSettings || {};
let defaultWikiAction = storage.defaultWikiAction || null;
let defaultSearchAction = storage.defaultSearchAction || null;
// Load BreezeWiki options:
chrome.storage.sync.get(['breezewiki'], function (item) {
@ -159,54 +164,93 @@ async function loadOptions(lang) {
}
});
// Load defaults for newly added wikis:
chrome.storage.sync.get(['defaultWikiAction'], function (item) {
if (item.defaultWikiAction === 'disabled') {
document.options.defaultWikiAction.value = 'disabled';
} else if (item.defaultWikiAction === 'redirect') {
document.options.defaultWikiAction.value = 'redirect';
} else {
document.options.defaultWikiAction.value = 'alert';
}
});
chrome.storage.sync.get(['defaultSearchAction'], function (item) {
if (item.defaultSearchAction === 'disabled') {
document.options.defaultSearchAction.value = 'disabled';
} else if (item.defaultSearchAction === 'hide') {
document.options.defaultSearchAction.value = 'hide';
} else {
document.options.defaultSearchAction.value = 'replace';
}
});
// Populate individual wiki settings:
var toggleContainer = document.getElementById('toggles');
const toggleContainer = document.getElementById('toggles');
for (var i = 0; i < sites.length; i++) {
if (sites[i].language === lang) {
if ((lang === 'ALL') || (sites[i].language === lang)) {
var key = sites[i].id;
// Create radio for disabled:
// Create radio for disabling action on wiki:
let labelDisabled = document.createElement("label");
let inputDisabled = document.createElement("input");
inputDisabled.classList = 'toggleDisable';
inputDisabled.type = "radio";
inputDisabled.name = key;
inputDisabled.title = 'Disable actions for ' + sites[i].origins_label;
inputDisabled.id = key + '-redirect';
inputDisabled.lang = lang;
inputDisabled.name = key + '-wiki-action';
inputDisabled.title = 'Do nothing for ' + sites[i].origins_label + ' on search engines';
inputDisabled.lang = sites[i].language;
inputDisabled.setAttribute('data-wiki-key', key);
// Create radio for redirect:
// Create radio for redirecting wiki:
let labelRedirect = document.createElement("label");
let inputRedirect = document.createElement("input");
inputRedirect.classList = 'toggleRedirect';
inputRedirect.type = "radio";
inputRedirect.name = key;
inputRedirect.title = 'Automatically redirect from ' + sites[i].origins_label + ' to ' + sites[i].destination;
inputRedirect.id = key + '-redirect';
inputRedirect.lang = lang;
inputRedirect.name = key + '-wiki-action';
inputRedirect.title = 'Automatically redirect ' + sites[i].origins_label + ' to ' + sites[i].destination;
inputRedirect.lang = sites[i].language;
inputRedirect.setAttribute('data-wiki-key', key);
// Create radio for alert:
// Create radio for inserting banner on wiki:
let labelAlert = document.createElement("label");
let inputAlert = document.createElement("input");
inputAlert.classList = 'toggleAlert';
inputAlert.type = "radio";
inputAlert.name = key;
inputAlert.title = 'Notify with banner when visiting ' + sites[i].origins_label;
inputAlert.id = key + '-alert';
inputAlert.lang = lang;
inputAlert.name = key + '-wiki-action';
inputAlert.title = 'Show banner on ' + sites[i].origins_label + ' linking to ' + sites[i].destination;
inputAlert.lang = sites[i].language;
inputAlert.setAttribute('data-wiki-key', key);
// Create radio for disabling action on search engines:
let labelSearchEngineDisabled = document.createElement("label");
let inputSearchEngineDisabled = document.createElement("input");
inputSearchEngineDisabled.classList = 'toggleSearchEngineDisabled';
inputSearchEngineDisabled.type = "radio";
inputSearchEngineDisabled.name = key + '-search-engine-action';
inputSearchEngineDisabled.title = 'Do nothing for ' + sites[i].origins_label;
inputSearchEngineDisabled.lang = sites[i].language;
inputSearchEngineDisabled.setAttribute('data-wiki-key', key);
// Create checkbox for search filtering:
let labelFilter = document.createElement("label");
let inputFilter = document.createElement("input");
inputFilter.classList = 'toggleFilter';
inputFilter.type = 'checkbox';
inputFilter.name = key;
inputFilter.title = 'Filter ' + sites[i].origins_label + ' from Google, Bing, DuckDuckGo, & other search engines';
inputFilter.id = key + '-filter';
inputFilter.lang = lang;
// Create radio for hiding results on search engines:
let labelSearchEngineHide = document.createElement("label");
let inputSearchEngineHide = document.createElement("input");
inputSearchEngineHide.classList = 'toggleSearchEngineHide';
inputSearchEngineHide.type = "radio";
inputSearchEngineHide.name = key + '-search-engine-action';
inputSearchEngineHide.title = 'Hide ' + sites[i].origins_label + ' from search engine results';
inputSearchEngineHide.lang = sites[i].language;
inputSearchEngineHide.setAttribute('data-wiki-key', key);
// Check radio button based on user's settings
// Will default to alert or the last "select all" setting the user chose
// Create radio for replacing results on search engines:
let labelSearchEngineReplace = document.createElement("label");
let inputSearchEngineReplace = document.createElement("input");
inputSearchEngineReplace.classList = 'toggleSearchEngineReplace';
inputSearchEngineReplace.type = "radio";
inputSearchEngineReplace.name = key + '-search-engine-action';
inputSearchEngineReplace.title = 'Replace ' + sites[i].origins_label + ' search engine results with ' + sites[i].destination;
inputSearchEngineReplace.lang = sites[i].language;
inputSearchEngineReplace.setAttribute('data-wiki-key', key);
// Check radio buttons based on user's settings
if (siteSettings[key] && siteSettings[key].action) {
if (siteSettings[key].action === 'disabled') {
inputDisabled.checked = true;
@ -216,7 +260,7 @@ async function loadOptions(lang) {
inputAlert.checked = true;
}
} else {
let actionSetting = defaultActionSettings[lang];
let actionSetting = defaultWikiAction;
if (actionSetting) {
if (actionSetting === 'disabled') {
inputDisabled.checked = true;
@ -230,102 +274,134 @@ async function loadOptions(lang) {
}
}
// Check search filter checkbox based on user's settings (default filter):
if (siteSettings[key] && siteSettings[key].searchFilter) {
if (siteSettings[key].searchFilter === 'false') {
inputFilter.checked = false;
if (searchEngineSettings[key] && searchEngineSettings[key].action) {
if (searchEngineSettings[key].action === 'disabled') {
inputSearchEngineDisabled.checked = true;
} else if (searchEngineSettings[key].action === 'replace') {
inputSearchEngineReplace.checked = true;
} else {
inputFilter.checked = true;
inputSearchEngineHide.checked = true;
}
} else {
let searchFilterSetting = defaultSearchFilterSettings[lang];
if (searchFilterSetting && searchFilterSetting === 'false') {
inputFilter.checked = false;
let actionSetting = defaultSearchAction;
if (actionSetting) {
if (actionSetting === 'true' || actionSetting === 'replace') {
inputSearchEngineReplace.checked = true;
} else if (actionSetting === 'false' || actionSetting === 'disabled') {
inputSearchEngineDisabled.checked = true;
} else {
inputSearchEngineHide.checked = true;
}
} else {
inputFilter.checked = true;
inputSearchEngineReplace.checked = true;
}
}
// Add listeners for when user clicks control:
inputRedirect.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
var key = input.target.name;
var key = input.target.getAttribute('data-wiki-key');
response.siteSettings.get(key).set('action', 'redirect');
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
});
});
inputAlert.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
var key = input.target.name;
var key = input.target.getAttribute('data-wiki-key');
response.siteSettings.get(key).set('action', 'alert');
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
});
});
inputDisabled.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
var key = input.target.name;
var key = input.target.getAttribute('data-wiki-key');
response.siteSettings.get(key).set('action', 'disabled');
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
});
});
inputFilter.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
var key = input.target.name;
if (input.target.checked === true) {
response.siteSettings.get(key).set('searchFilter', 'true');
} else {
response.siteSettings.get(key).set('searchFilter', 'false');
}
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
inputSearchEngineDisabled.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
var key = input.target.getAttribute('data-wiki-key');
response.searchEngineSettings.get(key).set('action', 'disabled');
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
});
});
inputSearchEngineHide.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
var key = input.target.getAttribute('data-wiki-key');
response.searchEngineSettings.get(key).set('action', 'hide');
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
});
});
inputSearchEngineReplace.addEventListener('click', function (input) {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
var key = input.target.getAttribute('data-wiki-key');
response.searchEngineSettings.get(key).set('action', 'replace');
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
});
});
// Output disable radio button:
// Output wiki disable radio button:
let inputDisabledText = document.createElement('span');
inputDisabledText.classList.add('visuallyHidden');
inputDisabledText.textContent = 'Disable action for ' + sites[i].origins_label;
labelDisabled.appendChild(inputDisabled);
labelDisabled.appendChild(inputDisabledText);
// Output redirect radio button:
// Output wiki redirect radio button:
let inputRedirectText = document.createElement('span');
inputRedirectText.classList.add('visuallyHidden');
inputRedirectText.textContent = 'Automatically redirect ' + sites[i].origins_label;
inputRedirectText.textContent = 'Automatically redirect ' + sites[i].origins_label + ' to ' + sites[i].destination;
labelRedirect.appendChild(inputRedirect);
labelRedirect.appendChild(inputRedirectText);
// Output alert radio button:
// Output wiki alert radio button:
let inputAlertText = document.createElement('span');
inputAlertText.classList.add('visuallyHidden');
inputAlertText.textContent = 'Automatically alert for' + sites[i].origins_label;
inputAlertText.textContent = 'Show a banner on ' + sites[i].origins_label + ' linking to ' + sites[i].destination;
labelAlert.appendChild(inputAlert);
labelAlert.appendChild(inputAlertText);
// Output search filter checkbox:
let inputFilterText = document.createElement('span');
inputFilterText.classList.add('visuallyHidden');
inputFilterText.textContent = 'Filter ' + sites[i].origins_label + ' from search engine results';
labelFilter.appendChild(inputFilter);
labelFilter.appendChild(inputFilterText);
// Output search engine disable radio button:
let inputSearchEngineDisabledText = document.createElement('span');
inputSearchEngineDisabledText.classList.add('visuallyHidden');
inputSearchEngineDisabledText.textContent = 'Do nothing for ' + sites[i].origins_label + ' on search engines';
labelSearchEngineDisabled.appendChild(inputSearchEngineDisabled);
labelSearchEngineDisabled.appendChild(inputSearchEngineDisabledText);
// Output search engine hide radio button:
let inputSearchEngineHideText = document.createElement('span');
inputSearchEngineHideText.classList.add('visuallyHidden');
inputSearchEngineHideText.textContent = 'Hide ' + sites[i].origins_label + ' from search engines';
labelSearchEngineHide.appendChild(inputSearchEngineHide);
labelSearchEngineHide.appendChild(inputSearchEngineHideText);
// Output search engine replace radio button:
let inputSearchEngineReplaceText = document.createElement('span');
inputSearchEngineReplaceText.classList.add('visuallyHidden');
inputSearchEngineReplaceText.textContent = 'Replace ' + sites[i].origins_label + ' search engine results with ' + sites[i].destination;
labelSearchEngineReplace.appendChild(inputSearchEngineReplace);
labelSearchEngineReplace.appendChild(inputSearchEngineReplaceText);
// Output wiki info:
let wikiInfo = document.createElement('span');
let iconLink = document.createElement("a");
iconLink.href = 'https://' + sites[i].destination_base_url + sites[i].destination_content_path;
iconLink.title = 'Visit ' + sites[i].destination;
iconLink.target = '_blank';
let wikiLink = document.createElement("a");
wikiLink.href = 'https://' + sites[i].destination_base_url + sites[i].destination_content_path;
wikiLink.title = 'Visit ' + sites[i].destination;
wikiLink.target = '_blank';
let icon = document.createElement("img");
icon.src = 'favicons/' + lang.toLowerCase() + '/' + sites[i].destination_icon;
icon.src = 'favicons/' + sites[i].language.toLowerCase() + '/' + sites[i].destination_icon;
icon.alt = 'Visit ' + sites[i].destination;
iconLink.appendChild(icon);
let destinationLink = document.createElement("a");
destinationLink.title = sites[i].destination;
destinationLink.href = 'https://' + sites[i].destination_base_url + sites[i].destination_content_path;
destinationLink.target = '_blank';
destinationLink.append(document.createTextNode(sites[i].destination));
wikiInfo.appendChild(iconLink);
wikiInfo.appendChild(document.createTextNode(sites[i].origins_label + ' » '));
wikiInfo.appendChild(destinationLink);
wikiLink.appendChild(icon);
wikiLink.appendChild(document.createTextNode(sites[i].destination));
wikiInfo.appendChild(wikiLink);
wikiInfo.appendChild(document.createTextNode(' (from ' + sites[i].origins_label + ')'));
if (lang === 'ALL') {
const languageSpan = document.createElement('span');
languageSpan.classList.add('text-sm');
languageSpan.innerText = ' [' + sites[i].language + '] ';
wikiInfo.appendChild(languageSpan);
}
let siteContainer = document.createElement("div");
// Output inputs container:
@ -333,7 +409,9 @@ async function loadOptions(lang) {
inputsContainer.appendChild(labelDisabled);
inputsContainer.appendChild(labelRedirect);
inputsContainer.appendChild(labelAlert);
inputsContainer.appendChild(labelFilter);
inputsContainer.appendChild(labelSearchEngineDisabled);
inputsContainer.appendChild(labelSearchEngineHide);
inputsContainer.appendChild(labelSearchEngineReplace);
inputsContainer.classList = 'inputsContainer';
siteContainer.appendChild(wikiInfo);
siteContainer.appendChild(inputsContainer);
@ -342,64 +420,64 @@ async function loadOptions(lang) {
}
// Add "select all" button event listeners:
var setAllRedirect = document.getElementById('setAllRedirect');
const setAllRedirect = document.getElementById('setAllRedirect');
setAllRedirect.addEventListener('click', function () {
var toggles = document.querySelectorAll('#toggles input.toggleRedirect');
const toggles = document.querySelectorAll('#toggles input.toggleRedirect');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
siteSettings.get(toggles[i].name).set('action', 'redirect');
siteSettings.get(toggles[i].getAttribute('data-wiki-key')).set('action', 'redirect');
}
chrome.storage.sync.set({ 'siteSettings': siteSettings });
defaultActionSettings[toggles[0].lang] = 'redirect';
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
});
var setAllAlert = document.getElementById('setAllAlert');
const setAllAlert = document.getElementById('setAllAlert');
setAllAlert.addEventListener('click', function () {
var toggles = document.querySelectorAll('#toggles input.toggleAlert');
const toggles = document.querySelectorAll('#toggles input.toggleAlert');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
siteSettings.get(toggles[i].name).set('action', 'alert');
siteSettings.get(toggles[i].getAttribute('data-wiki-key')).set('action', 'alert');
}
chrome.storage.sync.set({ 'siteSettings': siteSettings });
defaultActionSettings[toggles[0].lang] = 'alert';
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
});
var setAllDisabled = document.getElementById('setAllDisabled');
const setAllDisabled = document.getElementById('setAllDisabled');
setAllDisabled.addEventListener('click', function () {
var toggles = document.querySelectorAll('#toggles input.toggleDisable');
const toggles = document.querySelectorAll('#toggles input.toggleDisable');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
siteSettings.get(toggles[i].name).set('action', 'disabled');
siteSettings.get(toggles[i].getAttribute('data-wiki-key')).set('action', 'disabled');
}
chrome.storage.sync.set({ 'siteSettings': siteSettings });
defaultActionSettings[toggles[0].lang] = 'disabled';
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
});
var setAllSearchFilter = document.getElementById('setAllSearchFilter');
setAllSearchFilter.addEventListener('click', function () {
var toggles = document.querySelectorAll('#toggles input.toggleFilter');
const setAllSearchEngineDisabled = document.getElementById('setAllSearchEngineDisabled');
setAllSearchEngineDisabled.addEventListener('click', function () {
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineDisabled');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
siteSettings.get(toggles[i].name).set('searchFilter', 'true');
searchEngineSettings.get(toggles[i].getAttribute('data-wiki-key')).set('action', 'disabled');
}
chrome.storage.sync.set({ 'siteSettings': siteSettings });
defaultSearchFilterSettings[toggles[0].lang] = 'true';
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
});
var setNoneSearchFilter = document.getElementById('setNoneSearchFilter');
setNoneSearchFilter.addEventListener('click', function () {
var toggles = document.querySelectorAll('#toggles input.toggleFilter');
const setAllSearchEngineHide = document.getElementById('setAllSearchEngineHide');
setAllSearchEngineHide.addEventListener('click', function () {
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineHide');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = false;
siteSettings.get(toggles[i].name).set('searchFilter', 'false');
toggles[i].checked = true;
searchEngineSettings.get(toggles[i].getAttribute('data-wiki-key')).set('action', 'hide');
}
chrome.storage.sync.set({ 'siteSettings': siteSettings });
defaultSearchFilterSettings[toggles[0].lang] = 'false';
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
});
const setAllSearchEngineReplace = document.getElementById('setAllSearchEngineReplace');
setAllSearchEngineReplace.addEventListener('click', function () {
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineReplace');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
searchEngineSettings.get(toggles[i].getAttribute('data-wiki-key')).set('action', 'replace');
}
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
});
});
});
@ -410,14 +488,15 @@ function setPower(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.local.set({ 'power': setting });
}
var powerImage = document.getElementById('powerImage');
powerImage.src = 'images/power-' + setting + '.png';
var powerText = document.getElementById('powerText');
const powerText = document.getElementById('powerText');
powerText.textContent = 'Extension is ' + setting;
const powerIcon = document.getElementById('powerIcon');
if (setting === 'on') {
document.getElementById('powerCheckbox').checked = true;
powerIcon.innerText = '🔋';
} else {
document.getElementById('powerCheckbox').checked = false;
powerIcon.innerText = '🪫';
}
chrome.runtime.sendMessage({
@ -431,24 +510,13 @@ function setNotifications(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'notifications': setting });
}
const notificationsIcon = document.getElementById('notificationsIcon');
if (setting === 'on') {
document.getElementById('notificationsCheckbox').checked = true;
notificationsIcon.innerText = '🔔';
} else {
document.getElementById('notificationsCheckbox').checked = false;
}
}
// Set search filter setting
function setSearchSetting(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'searchSetting': setting });
}
if (setting === 'hide') {
document.getElementById('searchFilteringHideRadio').checked = true;
} else if (setting === 'nothing') {
document.getElementById('searchFilteringNothingRadio').checked = true;
} else {
document.getElementById('searchFilteringReplaceRadio').checked = true;
notificationsIcon.innerText = '🔕';
}
}
@ -457,7 +525,7 @@ function setBreezeWiki(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'breezewiki': setting });
}
var breezewikiHost = document.getElementById('breezewikiHost');
const breezewikiHost = document.getElementById('breezewikiHost');
if (setting === 'on') {
document.getElementById('breezewikiCheckbox').checked = true;
} else {
@ -514,7 +582,7 @@ function setBreezeWiki(setting, storeSetting = true) {
}
// Main function that runs on-load
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', function () {
// If newly installed, show initial install guide
if (new URLSearchParams(window.location.search).get('newinstall')) {
document.getElementById('firstInstallInfo').style.display = 'block';
@ -590,7 +658,7 @@ document.addEventListener('DOMContentLoaded', function () {
loadOptions(item.lang);
});
// Add event listener for language select
var langSelect = document.getElementById("langSelect");
const langSelect = document.getElementById("langSelect");
langSelect.addEventListener('change', function () {
chrome.storage.sync.set({ 'lang': langSelect.value });
resetOptions();
@ -604,14 +672,14 @@ document.addEventListener('DOMContentLoaded', function () {
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
setNotifications(item.notifications, false);
});
chrome.storage.sync.get({ 'searchSetting': 'replace' }, function (item) {
setSearchSetting(item.searchSetting, false);
});
// chrome.storage.sync.get({ 'searchSetting': 'replace' }, function (item) {
// setSearchSetting(item.searchSetting, false);
// });
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
setBreezeWiki(item.breezewiki, false);
});
// Add event listeners for setting toggles
// Add event listeners for general setting toggles
document.getElementById('powerCheckbox').addEventListener('change', function () {
chrome.storage.local.get({ 'power': 'on' }, function (item) {
if (item.power === 'on') {
@ -630,15 +698,8 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
});
document.getElementById('searchFilteringReplaceRadio').addEventListener('change', function () {
setSearchSetting('replace');
});
document.getElementById('searchFilteringHideRadio').addEventListener('change', function () {
setSearchSetting('hide');
});
document.getElementById('searchFilteringNothingRadio').addEventListener('change', function () {
setSearchSetting('nothing');
});
// Add event listeners for BreezeWiki settings
document.getElementById('breezewikiCheckbox').addEventListener('change', function () {
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
if (item.breezewiki === 'on') {
@ -649,11 +710,23 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
});
var breezewikiHostSelect = document.getElementById("breezewikiHostSelect");
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
breezewikiHostSelect.addEventListener('change', function () {
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
});
// Add event listeners for default action selections
document.querySelectorAll('[name="defaultWikiAction"]').forEach((el) => {
el.addEventListener('change', function () {
chrome.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
});
});
document.querySelectorAll('[name="defaultSearchAction"]').forEach((el) => {
el.addEventListener('change', function () {
chrome.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
});
});
// Get and display stat counts
chrome.storage.sync.get({ 'countAlerts': 0 }, function (item) {
var key = Object.keys(item)[0];