2023-11-16 10:30:56 +00:00
|
|
|
const LANGS = ["DE", "EN", "ES", "FR", "IT", "KO", "PL", "PT", "TOK", "ZH"];
|
2023-11-05 08:58:02 +00:00
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
// Set power setting
|
|
|
|
function setPower(setting) {
|
2023-04-28 05:17:29 +00:00
|
|
|
chrome.storage.local.set({ 'power': setting });
|
2023-04-12 05:01:06 +00:00
|
|
|
var powerImage = document.getElementById('powerImage');
|
|
|
|
powerImage.src = 'images/power-' + setting + '.png';
|
|
|
|
powerImage.alt = 'Indie Wiki Buddy is ' + setting;
|
2023-02-06 00:48:53 +00:00
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
action: 'updateIcon',
|
|
|
|
value: setting
|
|
|
|
});
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
|
2023-11-05 08:58:02 +00:00
|
|
|
// Get wiki data from data folder
|
|
|
|
async function getData() {
|
|
|
|
var sites = [];
|
|
|
|
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-11-05 10:17:33 +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-05 10:17:33 +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-05 10:17:33 +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-05 10:17:33 +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 || {};
|
2023-11-05 10:17:33 +00:00
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
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-05 10:17:33 +00:00
|
|
|
} else {
|
2023-11-06 04:52:35 +00:00
|
|
|
searchEngineSettings[site.id] = defaultSearchAction;
|
2023-11-05 10:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
if (!wikiSettings[site.id]) {
|
|
|
|
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
|
|
|
}
|
|
|
|
});
|
2023-11-05 10:17:33 +00:00
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
|
|
|
|
2023-11-06 06:21:03 +00:00
|
|
|
// Remove old object:
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.remove('siteSettings');
|
2023-11-05 10:17:33 +00:00
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
// Mark v3 migration as complete:
|
|
|
|
chrome.storage.sync.set({ 'v3migration': 'done' });
|
|
|
|
}
|
|
|
|
});
|
2023-11-05 10:17:33 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 06:29:50 +00:00
|
|
|
// Populate BreezeWiki dropdown when enabled
|
2023-04-12 05:01:06 +00:00
|
|
|
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')
|
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-05 05:52:22 +00:00
|
|
|
undefined,
|
2023-04-28 06:19:55 +00:00
|
|
|
{ numeric: true, sensitivity: 'base' }
|
|
|
|
) >= 0
|
|
|
|
);
|
2023-04-12 05:01:06 +00:00
|
|
|
// 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
|
2023-04-28 06:19:55 +00:00
|
|
|
try {
|
|
|
|
host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
|
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-12 05:01:06 +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-04-12 05:01:06 +00:00
|
|
|
for (var i = 0; i < breezewikiHosts.length; i++) {
|
|
|
|
let option = document.createElement('option');
|
|
|
|
option.value = breezewikiHosts[i].instance;
|
2023-08-07 06:44:21 +00:00
|
|
|
let textContent = breezewikiHosts[i].instance.replace('https://', '');
|
2023-11-05 05:52:22 +00:00
|
|
|
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
2023-04-12 05:01:06 +00:00
|
|
|
if (numberOfPeriods > 1) {
|
2023-08-07 06:44:21 +00:00
|
|
|
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
2023-04-12 05:01:06 +00:00
|
|
|
}
|
2023-08-07 06:44:21 +00:00
|
|
|
option.textContent = textContent;
|
2023-04-12 05:01:06 +00:00
|
|
|
breezewikiHostSelect.appendChild(option);
|
|
|
|
if (option.value === host) {
|
|
|
|
breezewikiHostSelect.value = host;
|
2023-02-07 07:30:20 +00:00
|
|
|
}
|
2023-02-07 23:54:23 +00:00
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
// Store BreezeWiki host details
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': host });
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
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-05 05:52:22 +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 {
|
|
|
|
// 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-04-12 05:01:06 +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-05 05:52:22 +00:00
|
|
|
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
2023-04-12 05:01:06 +00:00
|
|
|
if (numberOfPeriods > 1) {
|
2023-08-07 06:44:21 +00:00
|
|
|
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
2023-08-07 06:44:21 +00:00
|
|
|
option.textContent = textContent;
|
2023-04-12 05:01:06 +00:00
|
|
|
breezewikiHostSelect.appendChild(option);
|
|
|
|
if (option.value === host) {
|
|
|
|
breezewikiHostSelect.value = host;
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-12 05:01:06 +00:00
|
|
|
// Store BreezeWiki host details
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': host });
|
2023-02-06 00:48:53 +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-02-06 00:48:53 +00:00
|
|
|
var powerImage = document.getElementById('powerImage');
|
|
|
|
powerImage.src = 'images/power-' + setting + '.png';
|
2023-04-12 05:01:06 +00:00
|
|
|
powerImage.alt = 'Indie Wiki Buddy is ' + setting;
|
|
|
|
if (setting === 'on') {
|
|
|
|
document.getElementById('powerCheckbox').checked = true;
|
|
|
|
} else {
|
|
|
|
document.getElementById('powerCheckbox').checked = false;
|
|
|
|
}
|
2023-02-06 11:00:44 +00:00
|
|
|
|
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
action: 'updateIcon',
|
|
|
|
value: setting
|
|
|
|
});
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04-09 08:45:46 +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-11-05 08:58:02 +00:00
|
|
|
// Set default action setting
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Set default search engine setting
|
|
|
|
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-02-06 00:48:53 +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-04-12 05:01:06 +00:00
|
|
|
if (setting === 'on') {
|
|
|
|
document.getElementById('breezewikiCheckbox').checked = true;
|
|
|
|
} else {
|
|
|
|
document.getElementById('breezewikiCheckbox').checked = false;
|
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
var breezewikiHost = document.getElementById('breezewikiHost');
|
|
|
|
if (setting === 'on') {
|
|
|
|
breezewikiHost.style.display = 'block';
|
|
|
|
chrome.storage.sync.get({ 'breezewikiHost': null }, function (host) {
|
|
|
|
if (!host.breezewikiHost) {
|
2023-02-06 12:23:21 +00:00
|
|
|
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-05 05:52:22 +00:00
|
|
|
undefined,
|
2023-04-28 06:19:55 +00:00
|
|
|
{ numeric: true, sensitivity: 'base' }
|
|
|
|
) >= 0
|
|
|
|
);
|
2023-02-06 12:23:21 +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-02-06 12:23:21 +00:00
|
|
|
}
|
2023-02-06 00:48:53 +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-05 05:52:22 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
|
2023-06-28 06:29:50 +00:00
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
document.getElementById('breezewikiHostSelect').value = host.breezewikiHost;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
breezewikiHost.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main function that runs on-load
|
2023-11-05 05:52:22 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
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-07-01 06:33:11 +00:00
|
|
|
loadBreezeWikiOptions();
|
|
|
|
|
2023-04-12 05:01:06 +00:00
|
|
|
// Listener for settings page in new tab:
|
|
|
|
document.getElementById('openSettings').addEventListener('click', function () {
|
2023-11-05 05:52:22 +00:00
|
|
|
chrome.tabs.create({ 'url': chrome.runtime.getURL('settings.html') });
|
2023-04-12 05:01:06 +00:00
|
|
|
window.close();
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
|
|
|
|
2023-04-09 08:45:46 +00:00
|
|
|
// 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-02-06 00:48:53 +00:00
|
|
|
});
|
|
|
|
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
|
2023-04-27 05:47:34 +00:00
|
|
|
setNotifications(item.notifications, false);
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
2023-11-05 05:52:22 +00:00
|
|
|
chrome.storage.sync.get({ 'crossLanguage': 'off' }, function (item) {
|
|
|
|
setCrossLanguage(item.crossLanguage, false);
|
|
|
|
});
|
2023-02-06 00:48:53 +00:00
|
|
|
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
|
2023-04-27 05:47:34 +00:00
|
|
|
setBreezeWiki(item.breezewiki, false);
|
2023-06-28 06:29:50 +00:00
|
|
|
|
|
|
|
// Load BreezeWiki options if BreezeWiki is enabled
|
2023-11-05 05:52:22 +00:00
|
|
|
if (item.breezewiki === 'on') {
|
2023-06-28 06:29:50 +00:00
|
|
|
loadBreezeWikiOptions();
|
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
|
|
|
|
2023-04-09 08:45:46 +00:00
|
|
|
// Add event listeners for 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-02-06 00:48:53 +00:00
|
|
|
if (item.power === 'on') {
|
|
|
|
setPower('off');
|
|
|
|
} else {
|
|
|
|
setPower('on');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-04-12 05:01:06 +00:00
|
|
|
document.getElementById('notificationsCheckbox').addEventListener('change', function () {
|
2023-02-06 00:48:53 +00:00
|
|
|
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-04-12 05:01:06 +00:00
|
|
|
document.getElementById('breezewikiCheckbox').addEventListener('change', function () {
|
2023-02-06 00:48:53 +00:00
|
|
|
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-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var breezewikiHostSelect = document.getElementById("breezewikiHostSelect");
|
|
|
|
breezewikiHostSelect.addEventListener('change', function () {
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
|
|
|
|
});
|
2023-11-05 08:58:02 +00:00
|
|
|
document.querySelectorAll('[name="defaultWikiAction"]').forEach((el) => {
|
|
|
|
el.addEventListener('change', async function () {
|
|
|
|
chrome.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
|
|
|
|
|
|
|
|
let wikiSettings = {};
|
|
|
|
sites = await getData();
|
|
|
|
sites.forEach((site) => {
|
|
|
|
wikiSettings[site.id] = document.options.defaultWikiAction.value;
|
|
|
|
});
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
document.querySelectorAll('[name="defaultSearchAction"]').forEach((el) => {
|
|
|
|
el.addEventListener('change', async function () {
|
|
|
|
chrome.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
|
|
|
|
|
|
|
|
let searchEngineSettings = {};
|
|
|
|
sites = await getData();
|
|
|
|
sites.forEach((site) => {
|
|
|
|
searchEngineSettings[site.id] = document.options.defaultSearchAction.value;
|
|
|
|
});
|
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
|
|
|
});
|
|
|
|
});
|
2023-11-05 10:21:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Run v3 data migration:
|
|
|
|
migrateData();
|