2023-04-12 05:01:06 +00:00
|
|
|
const LANGS = ["DE", "EN", "ES", "FR", "IT", "PL", "TOK"];
|
|
|
|
var sites = [];
|
|
|
|
|
|
|
|
// Create object prototypes for getting and setting attributes:
|
2023-11-04 07:54:41 +00:00
|
|
|
Object.prototype.get = function (prop) {
|
2023-04-12 05:01:06 +00:00
|
|
|
this[prop] = this[prop] || {};
|
|
|
|
return this[prop];
|
|
|
|
};
|
2023-11-04 07:54:41 +00:00
|
|
|
Object.prototype.set = function (prop, value) {
|
2023-04-12 05:01:06 +00:00
|
|
|
this[prop] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear wiki toggles
|
|
|
|
// Used when switching languages
|
|
|
|
function resetOptions() {
|
2023-11-02 08:12:35 +00:00
|
|
|
const toggleContainer = document.getElementById('toggles');
|
2023-04-12 05:01:06 +00:00
|
|
|
toggleContainer.textContent = "";
|
|
|
|
|
|
|
|
// Clone "select all" buttons to reset listeners
|
2023-11-02 08:12:35 +00:00
|
|
|
document.getElementById('setAllDisabled').cloneNode(true);
|
2023-04-12 05:01:06 +00:00
|
|
|
document.getElementById('setAllRedirect').cloneNode(true);
|
|
|
|
document.getElementById('setAllAlert').cloneNode(true);
|
2023-11-02 08:12:35 +00:00
|
|
|
document.getElementById('setAllSearchEngineDisabled').cloneNode(true);
|
|
|
|
document.getElementById('setAllSearchEngineHide').cloneNode(true);
|
|
|
|
document.getElementById('setAllSearchEngineReplace').cloneNode(true);
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get wiki data from data folder
|
|
|
|
async function getData() {
|
2023-11-05 10:21:33 +00:00
|
|
|
let sites = [];
|
2023-04-12 05:01:06 +00:00
|
|
|
let promises = [];
|
|
|
|
for (let i = 0; i < LANGS.length; i++) {
|
|
|
|
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);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
await Promise.all(promises);
|
|
|
|
return sites;
|
|
|
|
}
|
|
|
|
|
2023-06-28 06:29:50 +00:00
|
|
|
// Populate BreezeWiki dropdown when enabled
|
|
|
|
async function loadBreezeWikiOptions() {
|
|
|
|
// Load BreezeWiki options:
|
|
|
|
chrome.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost'], function (item) {
|
|
|
|
let hostOptions = item.breezewikiHostOptions;
|
|
|
|
let hostFetchTimestamp = item.breezewikiHostFetchTimestamp;
|
|
|
|
let host = item.breezewikiHost;
|
|
|
|
// Fetch and cache list of BreezeWiki hosts if first time,
|
|
|
|
// or if it has been 24 hrs since last refresh
|
|
|
|
if (!host || !hostOptions || !hostFetchTimestamp || (Date.now() - 86400000 > hostFetchTimestamp)) {
|
|
|
|
fetch('https://bw.getindie.wiki/instances.json')
|
|
|
|
.then((response) => {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json();
|
|
|
|
}
|
|
|
|
throw new Error('Indie Wiki Buddy failed to get BreezeWiki data.');
|
|
|
|
}).then((breezewikiHosts) => {
|
|
|
|
breezewikiHosts = breezewikiHosts.filter(host =>
|
|
|
|
chrome.runtime.getManifest().version.localeCompare(host.iwb_version,
|
2023-11-04 07:54:41 +00:00
|
|
|
undefined,
|
2023-06-28 06:29:50 +00:00
|
|
|
{ numeric: true, sensitivity: 'base' }
|
|
|
|
) >= 0
|
|
|
|
);
|
|
|
|
// If host isn't set, or currently selected host is no longer available, select random host:
|
|
|
|
if (!host || !breezewikiHosts.some(item => item.instance === host)) {
|
|
|
|
// Check if BreezeWiki's main site is available
|
|
|
|
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
|
|
|
|
if (breezewikiMain.length > 0) {
|
|
|
|
host = breezewikiMain[0].instance;
|
|
|
|
} else {
|
|
|
|
// If BreezeWiki.com is not available, set to a random mirror
|
|
|
|
try {
|
|
|
|
host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
2023-06-28 06:29:50 +00:00
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
2023-04-28 05:17:29 +00:00
|
|
|
// Populate dropdown selection of hosts
|
|
|
|
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
2023-06-29 07:24:05 +00:00
|
|
|
while (breezewikiHostSelect.firstChild) {
|
|
|
|
// Remove any existing options
|
|
|
|
breezewikiHostSelect.removeChild(breezewikiHostSelect.lastChild);
|
|
|
|
}
|
2023-06-28 06:29:50 +00:00
|
|
|
for (var i = 0; i < breezewikiHosts.length; i++) {
|
2023-04-28 05:17:29 +00:00
|
|
|
let option = document.createElement('option');
|
2023-06-28 06:29:50 +00:00
|
|
|
option.value = breezewikiHosts[i].instance;
|
2023-08-07 06:44:21 +00:00
|
|
|
let textContent = breezewikiHosts[i].instance.replace('https://', '');
|
2023-11-04 07:54:41 +00:00
|
|
|
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
2023-04-28 05:17:29 +00:00
|
|
|
if (numberOfPeriods > 1) {
|
2023-08-07 06:44:21 +00:00
|
|
|
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-08-07 06:44:21 +00:00
|
|
|
option.textContent = textContent;
|
2023-04-28 05:17:29 +00:00
|
|
|
breezewikiHostSelect.appendChild(option);
|
|
|
|
if (option.value === host) {
|
|
|
|
breezewikiHostSelect.value = host;
|
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
2023-04-28 05:17:29 +00:00
|
|
|
// Store BreezeWiki host details
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': host });
|
2023-06-28 06:29:50 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
|
|
|
}).catch((e) => {
|
|
|
|
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
|
|
|
|
|
|
|
|
// If fetch fails and no host is set, default to breezewiki.com:
|
|
|
|
if (!host) {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
|
2023-06-28 06:29:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// If currently selected host is no longer available, select random host:
|
|
|
|
if (!hostOptions.some(item => item.instance === host)) {
|
|
|
|
host = hostOptions[Math.floor(Math.random() * hostOptions.length)].instance;
|
|
|
|
}
|
|
|
|
// Populate dropdown selection of hosts
|
|
|
|
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
2023-06-29 07:24:05 +00:00
|
|
|
while (breezewikiHostSelect.firstChild) {
|
|
|
|
// Remove any existing options
|
|
|
|
breezewikiHostSelect.removeChild(breezewikiHostSelect.lastChild);
|
|
|
|
}
|
2023-06-28 06:29:50 +00:00
|
|
|
for (var i = 0; i < hostOptions.length; i++) {
|
|
|
|
let option = document.createElement('option');
|
|
|
|
option.value = hostOptions[i].instance;
|
2023-08-07 06:44:21 +00:00
|
|
|
let textContent = hostOptions[i].instance.replace('https://', '');
|
2023-11-04 07:54:41 +00:00
|
|
|
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
2023-06-28 06:29:50 +00:00
|
|
|
if (numberOfPeriods > 1) {
|
2023-08-07 06:44:21 +00:00
|
|
|
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
2023-06-28 06:29:50 +00:00
|
|
|
}
|
2023-08-07 06:44:21 +00:00
|
|
|
option.textContent = textContent;
|
2023-06-28 06:29:50 +00:00
|
|
|
breezewikiHostSelect.appendChild(option);
|
|
|
|
if (option.value === host) {
|
|
|
|
breezewikiHostSelect.value = host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Store BreezeWiki host details
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': host });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate popup settings and toggles
|
|
|
|
async function loadOptions(lang) {
|
|
|
|
sites = await getData();
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Sort sites alphabetically by destination
|
2023-11-05 07:00:22 +00:00
|
|
|
sites.sort((a, b) => {
|
|
|
|
a = a.destination.toLowerCase().replace(' ', '');
|
|
|
|
b = b.destination.toLowerCase().replace(' ', '');
|
|
|
|
return a < b ? -1 : (a > b ? 1 : 0);
|
|
|
|
});
|
2023-11-02 08:12:35 +00:00
|
|
|
|
2023-06-28 06:29:50 +00:00
|
|
|
chrome.storage.local.get(function (localStorage) {
|
|
|
|
chrome.storage.sync.get(function (syncStorage) {
|
2023-11-04 07:54:41 +00:00
|
|
|
const storage = { ...syncStorage, ...localStorage };
|
|
|
|
let wikiSettings = storage.wikiSettings || {};
|
2023-11-02 08:12:35 +00:00
|
|
|
let searchEngineSettings = storage.searchEngineSettings || {};
|
|
|
|
let defaultWikiAction = storage.defaultWikiAction || null;
|
|
|
|
let defaultSearchAction = storage.defaultSearchAction || null;
|
2023-06-28 06:29:50 +00:00
|
|
|
|
|
|
|
// Load BreezeWiki options:
|
|
|
|
chrome.storage.sync.get(['breezewiki'], function (item) {
|
|
|
|
if (item.breezewiki === 'on') {
|
|
|
|
loadBreezeWikiOptions();
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// 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';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-28 05:17:29 +00:00
|
|
|
// Populate individual wiki settings:
|
2023-11-02 08:12:35 +00:00
|
|
|
const toggleContainer = document.getElementById('toggles');
|
2023-04-28 05:17:29 +00:00
|
|
|
for (var i = 0; i < sites.length; i++) {
|
2023-11-02 08:12:35 +00:00
|
|
|
if ((lang === 'ALL') || (sites[i].language === lang)) {
|
2023-04-28 05:17:29 +00:00
|
|
|
var key = sites[i].id;
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Create radio for disabling action on wiki:
|
2023-04-28 05:17:29 +00:00
|
|
|
let labelDisabled = document.createElement("label");
|
|
|
|
let inputDisabled = document.createElement("input");
|
|
|
|
inputDisabled.classList = 'toggleDisable';
|
|
|
|
inputDisabled.type = "radio";
|
2023-11-02 08:12:35 +00:00
|
|
|
inputDisabled.name = key + '-wiki-action';
|
2023-11-04 07:54:41 +00:00
|
|
|
inputDisabled.title = 'Do nothing for ' + sites[i].origins_label + ' on search engines';
|
2023-11-02 08:12:35 +00:00
|
|
|
inputDisabled.lang = sites[i].language;
|
|
|
|
inputDisabled.setAttribute('data-wiki-key', key);
|
2023-04-28 05:17:29 +00:00
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Create radio for inserting banner on wiki:
|
2023-04-28 05:17:29 +00:00
|
|
|
let labelAlert = document.createElement("label");
|
|
|
|
let inputAlert = document.createElement("input");
|
|
|
|
inputAlert.classList = 'toggleAlert';
|
|
|
|
inputAlert.type = "radio";
|
2023-11-02 08:12:35 +00:00
|
|
|
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);
|
2023-11-03 09:20:45 +00:00
|
|
|
|
|
|
|
// Create radio for redirecting wiki:
|
|
|
|
let labelRedirect = document.createElement("label");
|
|
|
|
let inputRedirect = document.createElement("input");
|
|
|
|
inputRedirect.classList = 'toggleRedirect';
|
|
|
|
inputRedirect.type = "radio";
|
|
|
|
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);
|
2023-11-04 07:54:41 +00:00
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// 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 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);
|
|
|
|
|
2023-11-03 09:20:45 +00:00
|
|
|
// 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;
|
2023-11-04 07:54:41 +00:00
|
|
|
inputSearchEngineHide.setAttribute('data-wiki-key', key);
|
2023-11-03 09:20:45 +00:00
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Check radio buttons based on user's settings
|
2023-11-04 07:54:41 +00:00
|
|
|
if (wikiSettings[key]) {
|
|
|
|
if (wikiSettings[key] === 'disabled') {
|
2023-04-12 05:01:06 +00:00
|
|
|
inputDisabled.checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
} else if (wikiSettings[key] === 'redirect') {
|
2023-04-12 05:01:06 +00:00
|
|
|
inputRedirect.checked = true;
|
|
|
|
} else {
|
|
|
|
inputAlert.checked = true;
|
|
|
|
}
|
|
|
|
} else {
|
2023-11-02 08:12:35 +00:00
|
|
|
let actionSetting = defaultWikiAction;
|
2023-04-28 05:17:29 +00:00
|
|
|
if (actionSetting) {
|
|
|
|
if (actionSetting === 'disabled') {
|
|
|
|
inputDisabled.checked = true;
|
|
|
|
} else if (actionSetting === 'redirect') {
|
|
|
|
inputRedirect.checked = true;
|
|
|
|
} else {
|
|
|
|
inputAlert.checked = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputAlert.checked = true;
|
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2023-11-04 07:54:41 +00:00
|
|
|
if (searchEngineSettings[key]) {
|
|
|
|
if (searchEngineSettings[key] === 'disabled') {
|
2023-11-02 08:12:35 +00:00
|
|
|
inputSearchEngineDisabled.checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
} else if (searchEngineSettings[key] === 'replace') {
|
2023-11-02 08:12:35 +00:00
|
|
|
inputSearchEngineReplace.checked = true;
|
2023-04-28 05:17:29 +00:00
|
|
|
} else {
|
2023-11-02 08:12:35 +00:00
|
|
|
inputSearchEngineHide.checked = true;
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
} else {
|
2023-11-02 08:12:35 +00:00
|
|
|
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;
|
|
|
|
}
|
2023-04-28 05:17:29 +00:00
|
|
|
} else {
|
2023-11-02 08:12:35 +00:00
|
|
|
inputSearchEngineReplace.checked = true;
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 05:17:29 +00:00
|
|
|
// Add listeners for when user clicks control:
|
2023-11-03 09:20:45 +00:00
|
|
|
inputDisabled.addEventListener('click', function (input) {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.get({ 'wikiSettings': {} }, function (response) {
|
2023-11-02 08:12:35 +00:00
|
|
|
var key = input.target.getAttribute('data-wiki-key');
|
2023-11-04 07:54:41 +00:00
|
|
|
response.wikiSettings.set(key, 'disabled');
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': response.wikiSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
2023-04-28 05:17:29 +00:00
|
|
|
inputAlert.addEventListener('click', function (input) {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.get({ 'wikiSettings': {} }, function (response) {
|
2023-11-02 08:12:35 +00:00
|
|
|
var key = input.target.getAttribute('data-wiki-key');
|
2023-11-04 07:54:41 +00:00
|
|
|
response.wikiSettings.set(key, 'alert');
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': response.wikiSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
2023-11-03 09:20:45 +00:00
|
|
|
inputRedirect.addEventListener('click', function (input) {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.get({ 'wikiSettings': {} }, function (response) {
|
2023-11-02 08:12:35 +00:00
|
|
|
var key = input.target.getAttribute('data-wiki-key');
|
2023-11-04 07:54:41 +00:00
|
|
|
response.wikiSettings.set(key, 'redirect');
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': response.wikiSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
2023-11-02 08:12:35 +00:00
|
|
|
inputSearchEngineDisabled.addEventListener('click', function (input) {
|
|
|
|
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
|
|
|
|
var key = input.target.getAttribute('data-wiki-key');
|
2023-11-04 07:54:41 +00:00
|
|
|
response.searchEngineSettings.set(key, 'disabled');
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
|
|
|
|
});
|
|
|
|
});
|
2023-11-03 09:20:45 +00:00
|
|
|
inputSearchEngineReplace.addEventListener('click', function (input) {
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
|
|
|
|
var key = input.target.getAttribute('data-wiki-key');
|
2023-11-04 07:54:41 +00:00
|
|
|
response.searchEngineSettings.set(key, 'replace');
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
|
|
|
|
});
|
|
|
|
});
|
2023-11-03 09:20:45 +00:00
|
|
|
inputSearchEngineHide.addEventListener('click', function (input) {
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) {
|
|
|
|
var key = input.target.getAttribute('data-wiki-key');
|
2023-11-04 07:54:41 +00:00
|
|
|
response.searchEngineSettings.set(key, 'hide');
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Output wiki disable radio button:
|
2023-04-28 05:17:29 +00:00
|
|
|
let inputDisabledText = document.createElement('span');
|
|
|
|
inputDisabledText.classList.add('visuallyHidden');
|
|
|
|
inputDisabledText.textContent = 'Disable action for ' + sites[i].origins_label;
|
|
|
|
labelDisabled.appendChild(inputDisabled);
|
|
|
|
labelDisabled.appendChild(inputDisabledText);
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Output wiki alert radio button:
|
2023-04-28 05:17:29 +00:00
|
|
|
let inputAlertText = document.createElement('span');
|
|
|
|
inputAlertText.classList.add('visuallyHidden');
|
2023-11-02 08:12:35 +00:00
|
|
|
inputAlertText.textContent = 'Show a banner on ' + sites[i].origins_label + ' linking to ' + sites[i].destination;
|
2023-04-28 05:17:29 +00:00
|
|
|
labelAlert.appendChild(inputAlert);
|
|
|
|
labelAlert.appendChild(inputAlertText);
|
|
|
|
|
2023-11-03 09:20:45 +00:00
|
|
|
// Output wiki redirect radio button:
|
|
|
|
let inputRedirectText = document.createElement('span');
|
|
|
|
inputRedirectText.classList.add('visuallyHidden');
|
|
|
|
inputRedirectText.textContent = 'Automatically redirect ' + sites[i].origins_label + ' to ' + sites[i].destination;
|
|
|
|
labelRedirect.appendChild(inputRedirect);
|
|
|
|
labelRedirect.appendChild(inputRedirectText);
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// 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 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);
|
2023-04-28 05:17:29 +00:00
|
|
|
|
2023-11-03 09:20:45 +00:00
|
|
|
// 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);
|
|
|
|
|
2023-04-28 05:17:29 +00:00
|
|
|
// Output wiki info:
|
|
|
|
let wikiInfo = document.createElement('span');
|
2023-11-03 22:51:42 +00:00
|
|
|
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';
|
2023-04-28 05:17:29 +00:00
|
|
|
let icon = document.createElement("img");
|
2023-11-02 08:12:35 +00:00
|
|
|
icon.src = 'favicons/' + sites[i].language.toLowerCase() + '/' + sites[i].destination_icon;
|
2023-04-28 05:17:29 +00:00
|
|
|
icon.alt = 'Visit ' + sites[i].destination;
|
2023-11-03 22:51:42 +00:00
|
|
|
iconLink.appendChild(icon);
|
|
|
|
wikiInfo.appendChild(iconLink);
|
2023-11-02 08:12:35 +00:00
|
|
|
if (lang === 'ALL') {
|
|
|
|
const languageSpan = document.createElement('span');
|
|
|
|
languageSpan.classList.add('text-sm');
|
|
|
|
languageSpan.innerText = ' [' + sites[i].language + '] ';
|
|
|
|
wikiInfo.appendChild(languageSpan);
|
|
|
|
}
|
2023-11-03 22:51:42 +00:00
|
|
|
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';
|
|
|
|
wikiLink.appendChild(document.createTextNode(sites[i].destination));
|
|
|
|
wikiInfo.appendChild(wikiLink);
|
|
|
|
wikiInfo.appendChild(document.createTextNode(' (from ' + sites[i].origins_label + ')'));
|
2023-04-28 05:17:29 +00:00
|
|
|
let siteContainer = document.createElement("div");
|
|
|
|
|
|
|
|
// Output inputs container:
|
|
|
|
let inputsContainer = document.createElement('div');
|
|
|
|
inputsContainer.appendChild(labelDisabled);
|
|
|
|
inputsContainer.appendChild(labelAlert);
|
2023-11-03 09:20:45 +00:00
|
|
|
inputsContainer.appendChild(labelRedirect);
|
2023-11-02 08:12:35 +00:00
|
|
|
inputsContainer.appendChild(labelSearchEngineDisabled);
|
|
|
|
inputsContainer.appendChild(labelSearchEngineReplace);
|
2023-11-03 09:20:45 +00:00
|
|
|
inputsContainer.appendChild(labelSearchEngineHide);
|
2023-04-28 05:17:29 +00:00
|
|
|
inputsContainer.classList = 'inputsContainer';
|
|
|
|
siteContainer.appendChild(wikiInfo);
|
|
|
|
siteContainer.appendChild(inputsContainer);
|
|
|
|
toggleContainer.appendChild(siteContainer);
|
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 05:17:29 +00:00
|
|
|
// Add "select all" button event listeners:
|
2023-11-02 08:12:35 +00:00
|
|
|
const setAllRedirect = document.getElementById('setAllRedirect');
|
2023-04-28 05:17:29 +00:00
|
|
|
setAllRedirect.addEventListener('click', function () {
|
2023-11-02 08:12:35 +00:00
|
|
|
const toggles = document.querySelectorAll('#toggles input.toggleRedirect');
|
2023-04-28 05:17:29 +00:00
|
|
|
for (var i = 0; i < toggles.length; i++) {
|
|
|
|
toggles[i].checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
wikiSettings.set(toggles[i].getAttribute('data-wiki-key'), 'redirect');
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
const setAllAlert = document.getElementById('setAllAlert');
|
2023-04-28 05:17:29 +00:00
|
|
|
setAllAlert.addEventListener('click', function () {
|
2023-11-02 08:12:35 +00:00
|
|
|
const toggles = document.querySelectorAll('#toggles input.toggleAlert');
|
2023-04-28 05:17:29 +00:00
|
|
|
for (var i = 0; i < toggles.length; i++) {
|
|
|
|
toggles[i].checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
wikiSettings.set(toggles[i].getAttribute('data-wiki-key'), 'alert');
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
const setAllDisabled = document.getElementById('setAllDisabled');
|
2023-04-28 05:17:29 +00:00
|
|
|
setAllDisabled.addEventListener('click', function () {
|
2023-11-02 08:12:35 +00:00
|
|
|
const toggles = document.querySelectorAll('#toggles input.toggleDisable');
|
2023-04-28 05:17:29 +00:00
|
|
|
for (var i = 0; i < toggles.length; i++) {
|
|
|
|
toggles[i].checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
wikiSettings.set(toggles[i].getAttribute('data-wiki-key'), 'disabled');
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
const setAllSearchEngineDisabled = document.getElementById('setAllSearchEngineDisabled');
|
|
|
|
setAllSearchEngineDisabled.addEventListener('click', function () {
|
|
|
|
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineDisabled');
|
2023-04-28 05:17:29 +00:00
|
|
|
for (var i = 0; i < toggles.length; i++) {
|
|
|
|
toggles[i].checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
searchEngineSettings.set(toggles[i].getAttribute('data-wiki-key'), 'disabled');
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
|
|
|
});
|
|
|
|
|
|
|
|
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 = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
searchEngineSettings.set(toggles[i].getAttribute('data-wiki-key'), 'hide');
|
2023-11-02 08:12:35 +00:00
|
|
|
}
|
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
const setAllSearchEngineReplace = document.getElementById('setAllSearchEngineReplace');
|
|
|
|
setAllSearchEngineReplace.addEventListener('click', function () {
|
|
|
|
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineReplace');
|
2023-04-28 05:17:29 +00:00
|
|
|
for (var i = 0; i < toggles.length; i++) {
|
2023-11-02 08:12:35 +00:00
|
|
|
toggles[i].checked = true;
|
2023-11-04 07:54:41 +00:00
|
|
|
searchEngineSettings.set(toggles[i].getAttribute('data-wiki-key'), 'replace');
|
2023-04-28 05:17:29 +00:00
|
|
|
}
|
2023-11-02 08:12:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
2023-04-28 05:17:29 +00:00
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set power setting
|
2023-04-27 05:47:34 +00:00
|
|
|
function setPower(setting, storeSetting = true) {
|
|
|
|
if (storeSetting) {
|
2023-04-28 05:17:29 +00:00
|
|
|
chrome.storage.local.set({ 'power': setting });
|
2023-04-27 05:47:34 +00:00
|
|
|
}
|
2023-11-02 08:12:35 +00:00
|
|
|
const powerText = document.getElementById('powerText');
|
2023-04-12 05:01:06 +00:00
|
|
|
powerText.textContent = 'Extension is ' + setting;
|
2023-11-02 08:12:35 +00:00
|
|
|
const powerIcon = document.getElementById('powerIcon');
|
2023-04-12 05:01:06 +00:00
|
|
|
if (setting === 'on') {
|
|
|
|
document.getElementById('powerCheckbox').checked = true;
|
2023-11-02 08:12:35 +00:00
|
|
|
powerIcon.innerText = '🔋';
|
2023-04-12 05:01:06 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById('powerCheckbox').checked = false;
|
2023-11-02 08:12:35 +00:00
|
|
|
powerIcon.innerText = '🪫';
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
action: 'updateIcon',
|
|
|
|
value: setting
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set notifications setting
|
2023-04-27 05:47:34 +00:00
|
|
|
function setNotifications(setting, storeSetting = true) {
|
|
|
|
if (storeSetting) {
|
|
|
|
chrome.storage.sync.set({ 'notifications': setting });
|
|
|
|
}
|
2023-11-02 08:12:35 +00:00
|
|
|
const notificationsIcon = document.getElementById('notificationsIcon');
|
2023-04-12 05:01:06 +00:00
|
|
|
if (setting === 'on') {
|
|
|
|
document.getElementById('notificationsCheckbox').checked = true;
|
2023-11-02 08:12:35 +00:00
|
|
|
notificationsIcon.innerText = '🔔';
|
2023-04-12 05:01:06 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById('notificationsCheckbox').checked = false;
|
2023-11-02 08:12:35 +00:00
|
|
|
notificationsIcon.innerText = '🔕';
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
// Set cross-language setting
|
|
|
|
function setCrossLanguage(setting, storeSetting = true) {
|
|
|
|
if (storeSetting) {
|
|
|
|
chrome.storage.sync.set({ 'crossLanguage': setting });
|
|
|
|
}
|
|
|
|
|
|
|
|
const crossLanguageIcon = document.getElementById('crossLanguageIcon');
|
|
|
|
if (setting === 'on') {
|
|
|
|
document.getElementById('crossLanguageCheckbox').checked = true;
|
|
|
|
crossLanguageIcon.innerText = '🌐';
|
|
|
|
} else {
|
|
|
|
document.getElementById('crossLanguageCheckbox').checked = false;
|
|
|
|
crossLanguageIcon.innerText = '⚪️';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
// Set BreezeWiki settings
|
2023-04-27 05:47:34 +00:00
|
|
|
function setBreezeWiki(setting, storeSetting = true) {
|
|
|
|
if (storeSetting) {
|
|
|
|
chrome.storage.sync.set({ 'breezewiki': setting });
|
|
|
|
}
|
2023-11-02 08:12:35 +00:00
|
|
|
const breezewikiHost = document.getElementById('breezewikiHost');
|
2023-04-12 05:01:06 +00:00
|
|
|
if (setting === 'on') {
|
|
|
|
document.getElementById('breezewikiCheckbox').checked = true;
|
|
|
|
} else {
|
|
|
|
document.getElementById('breezewikiCheckbox').checked = false;
|
|
|
|
}
|
|
|
|
if (setting === 'on') {
|
2023-04-24 05:23:51 +00:00
|
|
|
breezewikiHost.style.display = 'inline-block';
|
2023-04-12 05:01:06 +00:00
|
|
|
chrome.storage.sync.get({ 'breezewikiHost': null }, function (host) {
|
|
|
|
if (!host.breezewikiHost) {
|
|
|
|
fetch('https://bw.getindie.wiki/instances.json')
|
2023-04-28 06:19:55 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json();
|
|
|
|
}
|
|
|
|
throw new Error('Indie Wiki Buddy failed to get BreezeWiki data.');
|
|
|
|
}).then((breezewikiHosts) => {
|
|
|
|
breezewikiHosts = breezewikiHosts.filter(host =>
|
|
|
|
chrome.runtime.getManifest().version.localeCompare(host.iwb_version,
|
2023-11-04 07:54:41 +00:00
|
|
|
undefined,
|
2023-04-28 06:19:55 +00:00
|
|
|
{ numeric: true, sensitivity: 'base' }
|
|
|
|
) >= 0
|
|
|
|
);
|
2023-04-12 05:01:06 +00:00
|
|
|
// Check if BreezeWiki's main site is available
|
|
|
|
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
|
|
|
|
if (breezewikiMain.length > 0) {
|
|
|
|
host.breezewikiHost = breezewikiMain[0].instance;
|
|
|
|
} else {
|
|
|
|
// If BreezeWiki.com is not available, set to a random mirror
|
2023-04-28 06:19:55 +00:00
|
|
|
try {
|
|
|
|
host.breezewikiHost = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
|
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': host.breezewikiHost });
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
|
|
|
document.getElementById('breezewikiHostSelect').value = host.breezewikiHost;
|
2023-04-28 06:19:55 +00:00
|
|
|
}).catch((e) => {
|
|
|
|
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
|
2023-06-28 06:29:50 +00:00
|
|
|
|
|
|
|
// If fetch fails and no host is set, default to breezewiki.com:
|
|
|
|
if (!host) {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
|
2023-06-28 06:29:50 +00:00
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
document.getElementById('breezewikiHostSelect').value = host.breezewikiHost;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
breezewikiHost.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-04 07:54:41 +00:00
|
|
|
async function migrateData() {
|
2023-11-06 04:52:35 +00:00
|
|
|
await chrome.storage.sync.get(async (storage) => {
|
|
|
|
if (!storage.v3migration) {
|
2023-11-06 06:21:03 +00:00
|
|
|
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
|
|
|
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
// Set new default action settings:
|
|
|
|
if (!storage.defaultWikiAction) {
|
|
|
|
if (storage.defaultActionSettings && storage.defaultActionSettings['EN']) {
|
2023-11-06 06:21:03 +00:00
|
|
|
defaultWikiAction = storage.defaultActionSettings['EN'];
|
2023-11-04 07:54:41 +00:00
|
|
|
}
|
2023-11-06 06:21:03 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultWikiAction': defaultWikiAction });
|
2023-11-06 04:52:35 +00:00
|
|
|
}
|
|
|
|
if (!storage.defaultSearchAction) {
|
|
|
|
if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings['EN']) {
|
|
|
|
if (storage.defaultSearchFilterSettings['EN'] === 'false') {
|
2023-11-06 06:21:03 +00:00
|
|
|
defaultSearchAction = 'disabled';
|
2023-11-06 04:52:35 +00:00
|
|
|
} else {
|
2023-11-06 06:21:03 +00:00
|
|
|
defaultSearchAction = 'replace';
|
2023-11-04 07:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-06 06:21:03 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultSearchAction': defaultSearchAction });
|
2023-11-06 04:52:35 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 06:21:03 +00:00
|
|
|
// Remove old objects:
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.remove('defaultActionSettings');
|
|
|
|
chrome.storage.sync.remove('defaultSearchFilterSettings');
|
2023-11-04 07:54:41 +00:00
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
// Migrate wiki settings to new searchEngineSettings and wikiSettings objects
|
|
|
|
sites = await getData();
|
|
|
|
let siteSettings = storage.siteSettings || {};
|
|
|
|
let searchEngineSettings = storage.searchEngineSettings || {};
|
|
|
|
let wikiSettings = storage.wikiSettings || {};
|
|
|
|
|
|
|
|
sites.forEach((site) => {
|
|
|
|
if (!searchEngineSettings[site.id]) {
|
|
|
|
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
|
|
|
if (siteSettings[site.id].searchFilter === 'false') {
|
|
|
|
searchEngineSettings[site.id] = 'disabled';
|
|
|
|
} else {
|
|
|
|
searchEngineSettings[site.id] = 'replace';
|
|
|
|
}
|
2023-11-04 07:54:41 +00:00
|
|
|
} else {
|
2023-11-06 04:52:35 +00:00
|
|
|
searchEngineSettings[site.id] = defaultSearchAction;
|
2023-11-04 07:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
if (!wikiSettings[site.id]) {
|
|
|
|
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
|
|
|
}
|
|
|
|
});
|
2023-11-04 07:54:41 +00:00
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
2023-11-04 07:54:41 +00:00
|
|
|
|
2023-11-06 06:21:03 +00:00
|
|
|
// Remove old object:
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.remove('siteSettings');
|
|
|
|
|
|
|
|
// Mark v3 migration as complete:
|
|
|
|
chrome.storage.sync.set({ 'v3migration': 'done' });
|
|
|
|
}
|
|
|
|
});
|
2023-11-04 07:54:41 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
// Main function that runs on-load
|
2023-11-04 07:54:41 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
2023-09-18 09:05:46 +00:00
|
|
|
// If newly installed, show initial install guide
|
|
|
|
if (new URLSearchParams(window.location.search).get('newinstall')) {
|
|
|
|
document.getElementById('firstInstallInfo').style.display = 'block';
|
|
|
|
}
|
|
|
|
|
2023-07-01 06:33:11 +00:00
|
|
|
// If running Chromium, show warning about service worker bug
|
|
|
|
if (navigator.userAgent.match(/Chrom[e|ium]/)) {
|
2023-10-17 07:06:15 +00:00
|
|
|
const notificationBannerChromeBug = document.getElementById('notificationBannerChromeBug');
|
|
|
|
chrome.storage.local.get({ 'hideChromeBugNote': false }, function (item) {
|
|
|
|
if (!item.hideChromeBugNote) {
|
|
|
|
notificationBannerChromeBug.style.display = 'block';
|
|
|
|
|
|
|
|
document.getElementById('chromeBugHideLink').addEventListener('click', function () {
|
|
|
|
chrome.storage.local.set({ 'hideChromeBugNote': true });
|
|
|
|
notificationBannerChromeBug.style.display = 'none';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2023-07-01 06:33:11 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 07:06:15 +00:00
|
|
|
// If running Opera, show note about search engine access
|
2023-10-16 05:53:26 +00:00
|
|
|
if (navigator.userAgent.match(/OPR\//)) {
|
2023-10-17 07:06:15 +00:00
|
|
|
const notificationBannerOpera = document.getElementById('notificationBannerOpera');
|
|
|
|
chrome.storage.local.get({ 'hideOperaPermissionsNote': false }, function (item) {
|
|
|
|
if (!item.hideOperaPermissionsNote) {
|
|
|
|
notificationBannerOpera.style.display = 'block';
|
|
|
|
|
|
|
|
document.getElementById('operaPermsHideLink').addEventListener('click', function () {
|
|
|
|
chrome.storage.local.set({ 'hideOperaPermissionsNote': true });
|
|
|
|
notificationBannerOpera.style.display = 'none';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2023-10-16 05:53:26 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 05:15:36 +00:00
|
|
|
// Count number of times settings have been opened
|
|
|
|
// Purposefully using local storage instead of sync
|
|
|
|
chrome.storage.local.get({ 'countSettingsOpened': 0 }, function (item) {
|
|
|
|
const countSettingsOpened = item.countSettingsOpened;
|
|
|
|
chrome.storage.local.set({ 'countSettingsOpened': countSettingsOpened + 1 });
|
|
|
|
|
|
|
|
// Show review reminder every 5 opens,
|
|
|
|
// and if the banner hasn't been previously dismissed
|
|
|
|
chrome.storage.local.get({ 'hideReviewReminder': false }, function (item) {
|
|
|
|
if (!item.hideReviewReminder && ((countSettingsOpened - 1) % 5 === 0)) {
|
2023-10-17 07:06:15 +00:00
|
|
|
const notificationBannerReview = document.getElementById('notificationBannerReview');
|
|
|
|
|
|
|
|
notificationBannerReview.style.display = 'block';
|
2023-07-01 06:33:11 +00:00
|
|
|
document.getElementById('notificationBannerReview').style.display = ' block';
|
2023-04-27 05:15:36 +00:00
|
|
|
|
2023-04-27 05:53:24 +00:00
|
|
|
// Disable future review reminders if user clicks links:
|
|
|
|
document.getElementById('reviewReminderChromeLink').addEventListener('click', function () {
|
|
|
|
chrome.storage.local.set({ 'hideReviewReminder': true });
|
2023-07-01 06:33:11 +00:00
|
|
|
});
|
2023-04-27 05:53:24 +00:00
|
|
|
document.getElementById('reviewReminderFirefoxLink').addEventListener('click', function () {
|
|
|
|
chrome.storage.local.set({ 'hideReviewReminder': true });
|
|
|
|
});
|
|
|
|
document.getElementById('reviewReminderHideLink').addEventListener('click', function () {
|
2023-04-27 05:15:36 +00:00
|
|
|
chrome.storage.local.set({ 'hideReviewReminder': true });
|
2023-10-17 07:06:15 +00:00
|
|
|
notificationBannerReview.style.display = 'none';
|
2023-07-01 06:33:11 +00:00
|
|
|
});
|
2023-04-27 05:15:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
// Adding version to popup:
|
|
|
|
const version = chrome.runtime.getManifest().version;
|
|
|
|
document.getElementById('version').textContent = 'v' + version;
|
|
|
|
|
|
|
|
// Get user's last set language
|
|
|
|
chrome.storage.sync.get({ 'lang': 'EN' }, function (item) {
|
|
|
|
langSelect.value = item.lang;
|
|
|
|
loadOptions(item.lang);
|
|
|
|
});
|
|
|
|
// Add event listener for language select
|
2023-11-02 08:12:35 +00:00
|
|
|
const langSelect = document.getElementById("langSelect");
|
2023-04-12 05:01:06 +00:00
|
|
|
langSelect.addEventListener('change', function () {
|
|
|
|
chrome.storage.sync.set({ 'lang': langSelect.value });
|
|
|
|
resetOptions();
|
|
|
|
loadOptions(langSelect.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Set setting toggle values:
|
2023-04-28 05:17:29 +00:00
|
|
|
chrome.storage.local.get({ 'power': 'on' }, function (item) {
|
2023-04-27 05:47:34 +00:00
|
|
|
setPower(item.power, false);
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
|
|
|
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
|
2023-04-27 05:47:34 +00:00
|
|
|
setNotifications(item.notifications, false);
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
2023-11-05 05:52:22 +00:00
|
|
|
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
|
|
|
|
setCrossLanguage(item.crossLanguage, false);
|
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
|
2023-04-27 05:47:34 +00:00
|
|
|
setBreezeWiki(item.breezewiki, false);
|
2023-04-12 05:01:06 +00:00
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Add event listeners for general setting toggles
|
2023-04-12 05:01:06 +00:00
|
|
|
document.getElementById('powerCheckbox').addEventListener('change', function () {
|
2023-04-28 05:17:29 +00:00
|
|
|
chrome.storage.local.get({ 'power': 'on' }, function (item) {
|
2023-04-12 05:01:06 +00:00
|
|
|
if (item.power === 'on') {
|
|
|
|
setPower('off');
|
|
|
|
} else {
|
|
|
|
setPower('on');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
document.getElementById('notificationsCheckbox').addEventListener('change', function () {
|
|
|
|
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
|
|
|
|
if (item.notifications === 'on') {
|
|
|
|
setNotifications('off');
|
|
|
|
} else {
|
|
|
|
setNotifications('on');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-11-05 05:52:22 +00:00
|
|
|
document.getElementById('crossLanguageCheckbox').addEventListener('change', function () {
|
|
|
|
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
|
|
|
|
if (item.crossLanguage === 'on') {
|
|
|
|
setCrossLanguage('off');
|
|
|
|
} else {
|
|
|
|
setCrossLanguage('on');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-11-02 08:12:35 +00:00
|
|
|
|
|
|
|
// Add event listeners for BreezeWiki settings
|
2023-04-12 05:01:06 +00:00
|
|
|
document.getElementById('breezewikiCheckbox').addEventListener('change', function () {
|
|
|
|
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
|
|
|
|
if (item.breezewiki === 'on') {
|
|
|
|
setBreezeWiki('off');
|
|
|
|
} else {
|
|
|
|
setBreezeWiki('on');
|
2023-06-28 06:29:50 +00:00
|
|
|
loadBreezeWikiOptions();
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-11-02 08:12:35 +00:00
|
|
|
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
2023-04-12 05:01:06 +00:00
|
|
|
breezewikiHostSelect.addEventListener('change', function () {
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
|
|
|
|
});
|
|
|
|
|
2023-11-02 08:12:35 +00:00
|
|
|
// Add event listeners for default action selections
|
|
|
|
document.querySelectorAll('[name="defaultWikiAction"]').forEach((el) => {
|
|
|
|
el.addEventListener('change', function () {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
|
2023-11-02 08:12:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
document.querySelectorAll('[name="defaultSearchAction"]').forEach((el) => {
|
|
|
|
el.addEventListener('change', function () {
|
2023-11-04 07:54:41 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
|
2023-11-02 08:12:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
// Get and display stat counts
|
|
|
|
chrome.storage.sync.get({ 'countAlerts': 0 }, function (item) {
|
|
|
|
var key = Object.keys(item)[0];
|
|
|
|
document.getElementById('countAlerts').textContent = item[key];
|
|
|
|
});
|
|
|
|
chrome.storage.sync.get({ 'countRedirects': 0 }, function (item) {
|
|
|
|
var key = Object.keys(item)[0];
|
|
|
|
document.getElementById('countRedirects').textContent = item[key];
|
|
|
|
});
|
|
|
|
chrome.storage.sync.get({ 'countSearchFilters': 0 }, function (item) {
|
|
|
|
var key = Object.keys(item)[0];
|
|
|
|
document.getElementById('countSearchFilters').textContent = item[key];
|
2023-06-27 08:10:03 +00:00
|
|
|
});
|
|
|
|
chrome.storage.sync.get({ 'countBreezeWiki': 0 }, function (item) {
|
|
|
|
var key = Object.keys(item)[0];
|
|
|
|
document.getElementById('countBreezeWiki').textContent = item[key];
|
|
|
|
});
|
2023-09-15 04:35:20 +00:00
|
|
|
});
|
2023-11-05 10:21:33 +00:00
|
|
|
|
|
|
|
// Run v3 data migration:
|
|
|
|
migrateData();
|