2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Entry Point
|
2020-06-30 18:41:58 +02:00
|
|
|
* Belongs to LocalCDN (since 2020-02-26)
|
|
|
|
* (Origin: Decentraleyes)
|
2020-02-27 13:45:29 +01:00
|
|
|
*
|
|
|
|
* @author Thomas Rientjes
|
|
|
|
* @since 2016-04-04
|
2020-06-30 18:41:58 +02:00
|
|
|
*
|
|
|
|
* @author nobody
|
|
|
|
* @since 2020-02-26
|
|
|
|
*
|
2020-02-27 13:45:29 +01:00
|
|
|
* @license MPL-2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Main
|
|
|
|
*/
|
|
|
|
|
2024-04-28 07:18:40 +02:00
|
|
|
let main = {};
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Private Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
main._initializeSettings = function () {
|
2020-08-30 18:56:36 +02:00
|
|
|
storageManager.checkStorageType();
|
|
|
|
|
2020-11-14 12:31:17 +01:00
|
|
|
storageManager.type.get(null, function (items) {
|
2020-11-15 12:32:06 +01:00
|
|
|
// Delete old keys
|
2021-02-07 09:54:18 +01:00
|
|
|
if (items.whitelistedDomains !== undefined) {
|
|
|
|
if (items.allowlistedDomains === undefined || Object.keys(items.allowlistedDomains).length === 0) {
|
2020-11-21 07:02:33 +01:00
|
|
|
items['allowlistedDomains'] = items.whitelistedDomains;
|
2020-11-15 12:32:06 +01:00
|
|
|
}
|
2020-11-14 12:33:40 +01:00
|
|
|
delete items['whitelistedDomains'];
|
|
|
|
storageManager.type.remove('whitelistedDomains');
|
|
|
|
}
|
|
|
|
|
2020-11-14 12:31:17 +01:00
|
|
|
// Convert value of notifications
|
2021-02-07 09:54:18 +01:00
|
|
|
if (items.hideReleaseNotes !== undefined) {
|
2020-11-15 12:32:06 +01:00
|
|
|
if (items.hideReleaseNotes === true) {
|
|
|
|
items.updateNotification = 0;
|
|
|
|
} else {
|
|
|
|
items.updateNotification = 2;
|
|
|
|
}
|
2020-11-14 12:31:17 +01:00
|
|
|
delete items['hideReleaseNotes'];
|
|
|
|
storageManager.type.remove('hideReleaseNotes');
|
|
|
|
}
|
|
|
|
|
2020-11-15 12:32:06 +01:00
|
|
|
// Use default if key is missing
|
|
|
|
for (const key of Object.keys(SettingDefaults)) {
|
|
|
|
if (items[key] === undefined) {
|
|
|
|
items[key] = SettingDefaults[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items.disablePrefetch !== false) {
|
|
|
|
chrome.privacy.network.networkPredictionEnabled.set({
|
|
|
|
'value': false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-09 20:58:18 +02:00
|
|
|
stateManager.selectedIcon = items.selectedIcon;
|
2020-07-08 16:37:03 +02:00
|
|
|
wrappers.setIcon({
|
2020-07-09 20:58:18 +02:00
|
|
|
'path': stateManager.selectedIcon
|
|
|
|
}, 'Enabled');
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-08-11 06:29:09 +02:00
|
|
|
storageManager.amountInjected = items.amountInjected;
|
|
|
|
interceptor.xhrTestDomain = items.xhrTestDomain;
|
|
|
|
interceptor.allowedDomainsGoogleFonts = items.allowedDomainsGoogleFonts;
|
|
|
|
interceptor.blockMissing = items.blockMissing;
|
|
|
|
interceptor.blockGoogleFonts = items.blockGoogleFonts;
|
|
|
|
requestAnalyzer.allowlistedDomains = items.allowlistedDomains;
|
|
|
|
|
|
|
|
wrappers.badgeDefaultTextColor = items.badgeDefaultTextColor;
|
|
|
|
wrappers.badgeDefaultBackgroundColor = items.badgeDefaultBackgroundColor;
|
|
|
|
wrappers.badgeHTMLfilterTextColor = items.badgeHTMLfilterTextColor;
|
|
|
|
wrappers.badgeHTMLFilterBackgroundColor = items.badgeHTMLFilterBackgroundColor;
|
2021-08-12 06:37:45 +02:00
|
|
|
wrappers.badgeMissingResourceTextColor = items.badgeMissingResourceTextColor;
|
|
|
|
wrappers.badgeMissingResourceBackgroundColor = items.badgeMissingResourceBackgroundColor;
|
2021-08-11 06:29:09 +02:00
|
|
|
|
|
|
|
wrappers.setBadgeTextColor({'color': items.badgeDefaultTextColor, 'type': 'default'});
|
|
|
|
wrappers.setBadgeBackgroundColor({'color': items.badgeDefaultBackgroundColor, 'type': 'default'});
|
2021-07-10 06:40:13 +02:00
|
|
|
|
2020-08-30 18:56:36 +02:00
|
|
|
storageManager.type.set(items);
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
main._showReleaseNotes = function (details) {
|
2020-08-30 18:56:36 +02:00
|
|
|
storageManager.checkStorageType();
|
|
|
|
|
2020-03-08 12:30:03 +01:00
|
|
|
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
|
2020-08-30 18:56:36 +02:00
|
|
|
storageManager.type.set({
|
2020-10-11 12:52:17 +02:00
|
|
|
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
|
2021-02-17 07:01:08 +01:00
|
|
|
}, function () {
|
2020-04-06 18:04:53 +02:00
|
|
|
if (details.temporary !== true) {
|
2020-11-14 12:31:17 +01:00
|
|
|
chrome.tabs.create({
|
2021-04-11 08:03:42 +02:00
|
|
|
'url': chrome.runtime.getURL('pages/welcome/welcome.html'),
|
2021-03-26 06:51:46 +01:00
|
|
|
'active': true
|
2020-04-06 18:04:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-03-08 12:30:03 +01:00
|
|
|
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
|
2020-11-16 07:03:40 +01:00
|
|
|
storageManager.type.get(null, function (items) {
|
2020-10-11 12:52:17 +02:00
|
|
|
let mappingUpdate = items.lastMappingUpdate !== mappings.lastMappingUpdate;
|
2020-04-06 18:04:53 +02:00
|
|
|
|
2021-08-11 06:29:09 +02:00
|
|
|
// Migrate old keys to new keys https://codeberg.org/nobody/LocalCDN/issues/613
|
|
|
|
if (items.badgeDefaultBackgroundColor === undefined) {
|
|
|
|
items.badgeDefaultBackgroundColor = items.badgeColor;
|
|
|
|
delete items.badgeColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Migrate old keys to new keys https://codeberg.org/nobody/LocalCDN/issues/613
|
|
|
|
if (items.badgeDefaultTextColor === undefined) {
|
|
|
|
items.badgeDefaultTextColor = items.badgeTextColor;
|
|
|
|
delete items.badgeTextColor;
|
|
|
|
}
|
|
|
|
|
2020-11-16 07:03:40 +01:00
|
|
|
// Remove old keys
|
|
|
|
for (const key of Object.keys(items)) {
|
2021-08-11 06:29:09 +02:00
|
|
|
if (!(key in SettingDefaults) && key !== undefined) {
|
2020-11-16 07:03:40 +01:00
|
|
|
delete items[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Override old value https://codeberg.org/nobody/LocalCDN/issues/177
|
|
|
|
items.xhrTestDomain = 'localcdn.org';
|
|
|
|
|
2020-11-14 12:31:17 +01:00
|
|
|
// Updated mappings.js
|
|
|
|
if (mappingUpdate) {
|
2020-11-16 07:03:40 +01:00
|
|
|
items.lastMappingUpdate = mappings.lastMappingUpdate;
|
2020-11-14 12:31:17 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
if ((mappingUpdate && items.updateNotification === 1) || items.updateNotification === 2) {
|
2020-11-14 12:31:17 +01:00
|
|
|
chrome.tabs.create({
|
2021-04-11 08:03:42 +02:00
|
|
|
'url': chrome.runtime.getURL(`pages/updates/updates.html?mappingupdate=${mappingUpdate}`),
|
2020-11-14 12:31:17 +01:00
|
|
|
'active': false
|
2020-03-08 12:30:03 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// No mappings.js update
|
|
|
|
}
|
2021-08-11 06:29:09 +02:00
|
|
|
storageManager.type.set(items);
|
2020-03-08 12:30:03 +01:00
|
|
|
});
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Initializations
|
|
|
|
*/
|
|
|
|
chrome.runtime.onInstalled.addListener(main._showReleaseNotes);
|
|
|
|
main._initializeSettings();
|