parent
01f4a66ab7
commit
f8e482001a
|
@ -81,6 +81,7 @@ async function getData() {
|
|||
promises.push(fetch(chrome.runtime.getURL('data/sites' + LANGS[i] + '.json'))
|
||||
.then((resp) => resp.json())
|
||||
.then(function (jsonData) {
|
||||
jsonData.forEach((site) => site.language = LANGS[i]);
|
||||
sites = sites.concat(jsonData);
|
||||
}));
|
||||
}
|
||||
|
@ -132,8 +133,8 @@ async function main(eventInfo, eventName) {
|
|||
let siteSetting = '';
|
||||
if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) {
|
||||
siteSetting = settings[id].action;
|
||||
} else if (storage.defaultActionSetting) {
|
||||
siteSetting = storage.defaultActionSetting;
|
||||
} else if (storage.defaultActionSettings && storage.defaultActionSettings[site.language]) {
|
||||
siteSetting = storage.defaultActionSettings[site.language];
|
||||
} else {
|
||||
siteSetting = 'alert';
|
||||
}
|
||||
|
|
13
content.js
13
content.js
|
@ -32,6 +32,7 @@ async function getData() {
|
|||
promises.push(fetch(chrome.runtime.getURL('data/sites' + LANGS[i] + '.json'))
|
||||
.then((resp) => resp.json())
|
||||
.then(function (jsonData) {
|
||||
jsonData.forEach((site) => site.language = LANGS[i]);
|
||||
sites = sites.concat(jsonData);
|
||||
}));
|
||||
}
|
||||
|
@ -128,8 +129,8 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
|
|||
let searchFilterSetting = '';
|
||||
if (settings.hasOwnProperty(id) && settings[id].searchFilter) {
|
||||
searchFilterSetting = settings[id].searchFilter;
|
||||
} else if (storage.defaultSearchFilterSetting) {
|
||||
searchFilterSetting = storage.defaultSearchFilterSetting;
|
||||
} else if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings[site.language]) {
|
||||
searchFilterSetting = storage.defaultSearchFilterSettings[site.language];
|
||||
} else {
|
||||
searchFilterSetting = 'true';
|
||||
}
|
||||
|
@ -171,7 +172,9 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
|
|||
}
|
||||
}
|
||||
});
|
||||
chrome.storage.sync.set({ 'countSearchFilters': (storage.countSearchFilters ?? 0) + countFiltered });
|
||||
if (countFiltered > 0) {
|
||||
chrome.storage.sync.set({ 'countSearchFilters': (storage.countSearchFilters ?? 0) + countFiltered });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -221,8 +224,8 @@ function main(mutations = null, observer = null) {
|
|||
let siteSetting = '';
|
||||
if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) {
|
||||
siteSetting = settings[id].action;
|
||||
} else if (storage.defaultActionSetting) {
|
||||
siteSetting = storage.defaultActionSetting;
|
||||
} else if (storage.defaultActionSettings && storage.defaultActionSettings[site.language]) {
|
||||
siteSetting = storage.defaultActionSettings[site.language];
|
||||
} else {
|
||||
siteSetting = 'alert';
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Indie Wiki Buddy",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "Helping you discover quality independent wikis through alerts, redirects, and search filtering",
|
||||
"permissions": [
|
||||
"storage",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Indie Wiki Buddy",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "Helping you discover quality independent wikis through alerts, redirects, and search filtering",
|
||||
"permissions": [
|
||||
"storage",
|
||||
|
|
83
popup.js
83
popup.js
|
@ -44,8 +44,10 @@ async function getData() {
|
|||
async function loadOptions(lang) {
|
||||
sites = await getData();
|
||||
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
let siteSettings = response.siteSettings;
|
||||
chrome.storage.sync.get(function (storage) {
|
||||
let siteSettings = storage.siteSettings || {};
|
||||
let defaultActionSettings = storage.defaultActionSettings || {};
|
||||
let defaultSearchFilterSettings = storage.defaultSearchFilterSettings || {};
|
||||
|
||||
// Load BreezeWiki options:
|
||||
chrome.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost'], function (item) {
|
||||
|
@ -120,6 +122,7 @@ async function loadOptions(lang) {
|
|||
inputDisabled.name = key;
|
||||
inputDisabled.title = 'Disable actions for ' + sites[i].origin;
|
||||
inputDisabled.id = key + '-redirect';
|
||||
inputDisabled.lang = lang;
|
||||
|
||||
// Create radio for redirect:
|
||||
let labelRedirect = document.createElement("label");
|
||||
|
@ -129,6 +132,7 @@ async function loadOptions(lang) {
|
|||
inputRedirect.name = key;
|
||||
inputRedirect.title = 'Automatically redirect from ' + sites[i].origin + ' to ' + sites[i].destination;
|
||||
inputRedirect.id = key + '-redirect';
|
||||
inputRedirect.lang = lang;
|
||||
|
||||
// Create radio for alert:
|
||||
let labelAlert = document.createElement("label");
|
||||
|
@ -138,6 +142,7 @@ async function loadOptions(lang) {
|
|||
inputAlert.name = key;
|
||||
inputAlert.title = 'Notify with banner when visiting ' + sites[i].origin;
|
||||
inputAlert.id = key + '-alert';
|
||||
inputAlert.lang = lang;
|
||||
|
||||
// Create checkbox for search filtering:
|
||||
let labelFilter = document.createElement("label");
|
||||
|
@ -147,40 +152,47 @@ async function loadOptions(lang) {
|
|||
inputFilter.name = key;
|
||||
inputFilter.title = 'Filter from search results on Google, Bing, and DuckDuckGo';
|
||||
inputFilter.id = key + '-filter';
|
||||
inputFilter.lang = lang;
|
||||
|
||||
// Check radio button based on user's settings
|
||||
// Will default to alert or the last "select all" setting the user chose
|
||||
if (siteSettings[key] && siteSettings[key].action === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (siteSettings[key] && siteSettings[key].action === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else if (siteSettings[key] && siteSettings[key].action === 'alert') {
|
||||
inputAlert.checked = true;
|
||||
if (siteSettings[key] && siteSettings[key].action) {
|
||||
if (siteSettings[key].action === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (siteSettings[key].action === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
} else {
|
||||
chrome.storage.sync.get({ 'defaultActionSetting': 'alert' }, function (response) {
|
||||
if (response.defaultActionSetting === 'disabled') {
|
||||
let actionSetting = defaultActionSettings[lang];
|
||||
if (actionSetting) {
|
||||
if (actionSetting === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (response.defaultActionSetting === 'redirect') {
|
||||
} else if (actionSetting === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check search filter checkbox based on user's settings (default filter):
|
||||
if (siteSettings[key] && siteSettings[key].searchFilter === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else if (siteSettings[key] && siteSettings[key].searchFilter === 'true') {
|
||||
inputFilter.checked = true;
|
||||
if (siteSettings[key] && siteSettings[key].searchFilter) {
|
||||
if (siteSettings[key].searchFilter === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
inputFilter.checked = true;
|
||||
}
|
||||
} else {
|
||||
chrome.storage.sync.get({ 'defaultSearchFilterSetting': 'true' }, function (response) {
|
||||
if (response.defaultSearchFilterSetting === 'true') {
|
||||
inputFilter.checked = true;
|
||||
} else {
|
||||
inputFilter.checked = false;
|
||||
}
|
||||
});
|
||||
let searchFilterSetting = defaultSearchFilterSettings[lang];
|
||||
if (searchFilterSetting && searchFilterSetting === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
inputFilter.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Add listeners for when user clicks control:
|
||||
|
@ -199,19 +211,19 @@ async function loadOptions(lang) {
|
|||
});
|
||||
});
|
||||
inputDisabled.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }[key], function (response) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'disabled');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputFilter.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }[key], function (response) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
if (response.siteSettings[key].searchFilter === 'true') {
|
||||
response.siteSettings.get(key).set('searchFilter', 'false');
|
||||
} else {
|
||||
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 });
|
||||
});
|
||||
|
@ -280,7 +292,8 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('action', 'redirect');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultActionSetting': 'redirect' });
|
||||
defaultActionSettings[toggles[0].lang] = 'redirect';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllAlert = document.getElementById('setAllAlert');
|
||||
|
@ -291,7 +304,8 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('action', 'alert');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultActionSetting': 'alert' });
|
||||
defaultActionSettings[toggles[0].lang] = 'alert';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllDisabled = document.getElementById('setAllDisabled');
|
||||
|
@ -302,7 +316,8 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('action', 'disabled');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultActionSetting': 'disabled' });
|
||||
defaultActionSettings[toggles[0].lang] = 'disabled';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllSearchFilter = document.getElementById('setAllSearchFilter');
|
||||
|
@ -313,7 +328,8 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('searchFilter', 'true');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSetting': 'true' });
|
||||
defaultSearchFilterSettings[toggles[0].lang] = 'true';
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
|
||||
});
|
||||
|
||||
var setNoneSearchFilter = document.getElementById('setNoneSearchFilter');
|
||||
|
@ -324,7 +340,8 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('searchFilter', 'false');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSetting': 'false' });
|
||||
defaultSearchFilterSettings[toggles[0].lang] = 'false';
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue