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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main
|
|
|
|
*/
|
|
|
|
|
|
|
|
var main = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
main._initializeSettings = function () {
|
|
|
|
|
|
|
|
let settingDefaults = {
|
|
|
|
[Setting.XHR_TEST_DOMAIN]: Address.DECENTRALEYES,
|
|
|
|
[Setting.SHOW_ICON_BADGE]: true,
|
|
|
|
[Setting.BLOCK_MISSING]: false,
|
|
|
|
[Setting.DISABLE_PREFETCH]: true,
|
|
|
|
[Setting.ENFORCE_STAGING]: false,
|
2020-04-06 18:04:53 +02:00
|
|
|
[Setting.HIDE_RELEASE_NOTES]: false,
|
2020-02-27 13:45:29 +01:00
|
|
|
[Setting.STRIP_METADATA]: true,
|
2020-03-29 10:23:16 +02:00
|
|
|
[Setting.WHITELISTED_DOMAINS]: {},
|
2020-05-25 22:30:07 +02:00
|
|
|
[Setting.LOGGING]: false,
|
2020-06-25 07:54:17 +02:00
|
|
|
[Setting.DOMAINS_MANIPULATE_DOM]: {},
|
2020-07-03 08:37:00 +02:00
|
|
|
[Setting.NEGATE_HTML_FILTER_LIST]: false,
|
|
|
|
[Setting.BLOCK_GOOGLE_FONTS]: true
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
2020-06-08 11:38:52 +02:00
|
|
|
chrome.storage.sync.get(settingDefaults, function (items) {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
if (items === null) {
|
|
|
|
items = settingDefaults; // Restore setting defaults.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items.disablePrefetch !== false) {
|
|
|
|
|
|
|
|
chrome.privacy.network.networkPredictionEnabled.set({
|
|
|
|
'value': false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-08 11:38:52 +02:00
|
|
|
chrome.storage.sync.set(items);
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
main._showReleaseNotes = function (details) {
|
|
|
|
|
2020-03-08 12:30:03 +01:00
|
|
|
let location, updateAdBlockerRules, previousVersion;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
location = chrome.extension.getURL('pages/welcome/welcome.html');
|
2020-03-08 12:30:03 +01:00
|
|
|
updateAdBlockerRules = chrome.extension.getURL('pages/updates/updates.html');
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-03-08 12:30:03 +01:00
|
|
|
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-06-08 11:38:52 +02:00
|
|
|
chrome.storage.sync.set({
|
2020-04-06 18:04:53 +02:00
|
|
|
[Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate
|
|
|
|
}, function() {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-04-06 18:04:53 +02:00
|
|
|
previousVersion = details.previousVersion;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-04-06 18:04:53 +02:00
|
|
|
if (previousVersion && previousVersion.charAt(0) === '2') {
|
|
|
|
return; // Do not show release notes after minor updates.
|
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-04-06 18:04:53 +02:00
|
|
|
if (details.temporary !== true) {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-06-08 11:38:52 +02:00
|
|
|
chrome.storage.sync.get([Setting.HIDE_RELEASE_NOTES], function (items) {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-04-06 18:04:53 +02:00
|
|
|
if (items.hideReleaseNotes !== true) {
|
|
|
|
|
|
|
|
chrome.tabs.create({
|
|
|
|
'url': location,
|
|
|
|
'active': false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-03-08 12:30:03 +01:00
|
|
|
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
|
2020-04-06 18:04:53 +02:00
|
|
|
|
|
|
|
let newValue = lastMappingUpdate;
|
|
|
|
let oldValue = "";
|
|
|
|
|
2020-03-08 12:30:03 +01:00
|
|
|
// If add-on update true, check last update of mappings.js
|
2020-06-08 11:38:52 +02:00
|
|
|
chrome.storage.sync.get([Setting.LAST_MAPPING_UPDATE, Setting.HIDE_RELEASE_NOTES], function (items) {
|
2020-04-06 18:04:53 +02:00
|
|
|
|
|
|
|
oldValue = items.lastMappingUpdate;
|
|
|
|
|
|
|
|
if (oldValue !== newValue) {
|
2020-03-08 12:30:03 +01:00
|
|
|
// Updated mappings.js
|
2020-06-08 11:38:52 +02:00
|
|
|
chrome.storage.sync.set({
|
2020-04-06 18:04:53 +02:00
|
|
|
[Setting.LAST_MAPPING_UPDATE]: newValue
|
|
|
|
}, function() {
|
|
|
|
if (!items.hideReleaseNotes) {
|
|
|
|
chrome.tabs.create({
|
|
|
|
'url': updateAdBlockerRules,
|
2020-06-13 06:10:54 +02:00
|
|
|
'active': false
|
2020-04-06 18:04:53 +02:00
|
|
|
});
|
|
|
|
}
|
2020-03-08 12:30:03 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// No mappings.js update
|
2020-04-06 18:04:53 +02:00
|
|
|
return;
|
2020-03-08 12:30:03 +01:00
|
|
|
}
|
|
|
|
});
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializations
|
|
|
|
*/
|
|
|
|
|
|
|
|
chrome.runtime.onInstalled.addListener(main._showReleaseNotes);
|
|
|
|
main._initializeSettings();
|
|
|
|
|
|
|
|
wrappers.setBadgeBackgroundColor({
|
|
|
|
'color': [74, 130, 108, 255]
|
|
|
|
});
|
|
|
|
|
|
|
|
wrappers.setBadgeTextColor({
|
|
|
|
'color': [255, 255, 255, 255]
|
|
|
|
});
|