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');
|
2024-01-11 04:27:23 +00:00
|
|
|
powerImage.src = '../../images/power-' + setting + '.png';
|
2023-04-12 05:01:06 +00:00
|
|
|
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 10:17:33 +00:00
|
|
|
async function migrateData() {
|
2024-01-10 09:21:47 +00:00
|
|
|
commonFunctionMigrateToV3();
|
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');
|
2024-01-11 04:27:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-11-05 08:58:02 +00:00
|
|
|
// Set default action setting
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.sync.get(['defaultWikiAction'], (item) => {
|
2023-11-05 08:58:02 +00:00
|
|
|
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
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.sync.get(['defaultSearchAction'], (item) => {
|
2023-11-05 08:58:02 +00:00
|
|
|
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
|
|
|
// Main function that runs on-load
|
2023-12-13 10:10:55 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
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');
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.local.get({ 'hideOperaPermissionsNote': false }, (item) => {
|
2023-10-17 07:06:15 +00:00
|
|
|
if (!item.hideOperaPermissionsNote) {
|
|
|
|
notificationBannerOpera.style.display = 'block';
|
|
|
|
|
2023-12-13 10:10:55 +00:00
|
|
|
document.getElementById('operaPermsHideLink').addEventListener('click', () => {
|
2023-10-17 07:06:15 +00:00
|
|
|
chrome.storage.local.set({ 'hideOperaPermissionsNote': true });
|
|
|
|
notificationBannerOpera.style.display = 'none';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2023-10-16 05:53:26 +00:00
|
|
|
}
|
|
|
|
|
2023-12-20 08:39:47 +00:00
|
|
|
// Listener for settings links:
|
|
|
|
document.getElementById('openSettingsButton').addEventListener('click', () => {
|
2024-01-11 04:27:23 +00:00
|
|
|
chrome.tabs.create({ 'url': chrome.runtime.getURL('pages/settings/index.html') });
|
2023-12-20 08:39:47 +00:00
|
|
|
window.close();
|
|
|
|
});
|
|
|
|
document.getElementById('openSettingsLink').addEventListener('click', () => {
|
2024-01-11 04:27:23 +00:00
|
|
|
chrome.tabs.create({ 'url': chrome.runtime.getURL('pages/settings/index.html') });
|
2023-04-12 05:01:06 +00:00
|
|
|
window.close();
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
2024-02-27 09:43:55 +00:00
|
|
|
|
2024-01-10 09:21:47 +00:00
|
|
|
// Add event listener for BreezeWiki host select
|
2023-11-27 03:00:08 +00:00
|
|
|
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
2023-12-13 10:10:55 +00:00
|
|
|
breezewikiHostSelect.addEventListener('change', () => {
|
2023-11-27 03:00:08 +00:00
|
|
|
if (breezewikiHostSelect.value === 'CUSTOM') {
|
|
|
|
document.getElementById('breezewikiCustomHost').style.display = 'block';
|
|
|
|
} else {
|
|
|
|
document.getElementById('breezewikiCustomHost').style.display = 'none';
|
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
|
|
|
|
});
|
2023-11-27 03:00:08 +00:00
|
|
|
|
2024-02-27 09:43:55 +00:00
|
|
|
document.options.addEventListener("submit", function (e) {
|
2023-11-27 03:00:08 +00:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2023-11-05 08:58:02 +00:00
|
|
|
document.querySelectorAll('[name="defaultWikiAction"]').forEach((el) => {
|
2023-12-13 10:10:55 +00:00
|
|
|
el.addEventListener('change', async () => {
|
2023-11-05 08:58:02 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
|
|
|
|
|
|
|
|
let wikiSettings = {};
|
2024-01-10 09:21:47 +00:00
|
|
|
sites = await commonFunctionGetSiteDataByDestination();
|
2023-11-05 08:58:02 +00:00
|
|
|
sites.forEach((site) => {
|
|
|
|
wikiSettings[site.id] = document.options.defaultWikiAction.value;
|
|
|
|
});
|
2024-02-08 08:34:53 +00:00
|
|
|
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
|
2023-11-05 08:58:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
document.querySelectorAll('[name="defaultSearchAction"]').forEach((el) => {
|
2023-12-13 10:10:55 +00:00
|
|
|
el.addEventListener('change', async () => {
|
2023-11-05 08:58:02 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
|
|
|
|
|
|
|
|
let searchEngineSettings = {};
|
2024-01-10 09:21:47 +00:00
|
|
|
sites = await commonFunctionGetSiteDataByDestination();
|
2023-11-05 08:58:02 +00:00
|
|
|
sites.forEach((site) => {
|
|
|
|
searchEngineSettings[site.id] = document.options.defaultSearchAction.value;
|
|
|
|
});
|
2024-02-08 08:34:53 +00:00
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
|
2023-11-05 08:58:02 +00:00
|
|
|
});
|
|
|
|
});
|
2023-11-05 10:21:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Run v3 data migration:
|
|
|
|
migrateData();
|