Skip to content
Snippets Groups Projects
Verified Commit e81ed053 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Refactor existing codebase

parent c219fae3
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ const Setting = {
'BLOCK_MISSING': 'blockMissing',
'DISABLE_PREFETCH': 'disablePrefetch',
'SHOW_ICON_BADGE': 'showIconBadge',
'SHOW_RELEASE_NOTES': 'showReleaseNotes',
'STRIP_METADATA': 'stripMetadata',
'WHITELISTED_DOMAINS': 'whitelistedDomains'
};
......
......@@ -26,11 +26,11 @@ var main = {};
main._initializeOptions = function () {
let optionDefaults = {
'showIconBadge': true,
'blockMissing': false,
'disablePrefetch': true,
'stripMetadata': true,
'whitelistedDomains': {}
[Setting.SHOW_ICON_BADGE]: true,
[Setting.BLOCK_MISSING]: false,
[Setting.DISABLE_PREFETCH]: true,
[Setting.STRIP_METADATA]: true,
[Setting.WHITELISTED_DOMAINS]: {}
};
chrome.storage.local.get(optionDefaults, function (options) {
......@@ -68,7 +68,7 @@ main._showReleaseNotes = function (details) {
if (details.temporary !== true) {
chrome.storage.local.get({
'showReleaseNotes': true
[Setting.SHOW_RELEASE_NOTES]: true
}, function (options) {
if (options.showReleaseNotes === true) {
......
......@@ -57,6 +57,17 @@ requestSanitizer._stripMetadata = function (requestDetails) {
}
return {
'requestHeaders': requestDetails.requestHeaders
[WebRequest.HEADERS]: requestDetails.requestHeaders
};
};
/**
* Initializations
*/
chrome.storage.local.get({[Setting.STRIP_METADATA]: true}, function (options) {
if (options === null || options.stripMetadata !== false) {
requestSanitizer.enable();
}
});
......@@ -58,14 +58,14 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
interceptor.amountInjected = items.amountInjected;
chrome.storage.local.set({
'amountInjected': ++interceptor.amountInjected
[Setting.AMOUNT_INJECTED]: ++interceptor.amountInjected
});
});
} else {
chrome.storage.local.set({
'amountInjected': ++interceptor.amountInjected
[Setting.AMOUNT_INJECTED]: ++interceptor.amountInjected
});
}
};
......@@ -150,7 +150,7 @@ stateManager._updateTab = function (details) {
stateManager._handleStorageChanged = function (changes) {
if ('showIconBadge' in changes) {
if (Setting.SHOW_ICON_BADGE in changes) {
stateManager.showIconBadge = changes.showIconBadge.newValue;
......@@ -162,7 +162,7 @@ stateManager._handleStorageChanged = function (changes) {
}
}
if ('stripMetadata' in changes) {
if (Setting.STRIP_METADATA in changes) {
requestSanitizer.disable();
......@@ -198,7 +198,7 @@ chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._createTab);
});
chrome.storage.local.get('showIconBadge', function (items) {
chrome.storage.local.get(Setting.SHOW_ICON_BADGE, function (items) {
stateManager.showIconBadge = items.showIconBadge || true;
});
......@@ -244,11 +244,4 @@ chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
}, {'urls': [Address.ANY]});
chrome.storage.local.get({'stripMetadata': true}, function (options) {
if (options === null || options.stripMetadata !== false) {
requestSanitizer.enable();
}
});
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
......@@ -90,11 +90,11 @@ options._getOptionElement = function (optionKey) {
options._getOptionElements = function () {
let optionElements = {
'showIconBadge': options._getOptionElement(Setting.SHOW_ICON_BADGE),
'blockMissing': options._getOptionElement(Setting.BLOCK_MISSING),
'disablePrefetch': options._getOptionElement(Setting.DISABLE_PREFETCH),
'stripMetadata': options._getOptionElement(Setting.STRIP_METADATA),
'whitelistedDomains': options._getOptionElement(Setting.WHITELISTED_DOMAINS)
[Setting.SHOW_ICON_BADGE]: options._getOptionElement(Setting.SHOW_ICON_BADGE),
[Setting.BLOCK_MISSING]: options._getOptionElement(Setting.BLOCK_MISSING),
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
[Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS)
};
return optionElements;
......
......@@ -157,7 +157,7 @@ popup._determineAmountInjected = function () {
return new Promise((resolve) => {
chrome.storage.local.get('amountInjected', function (items) {
chrome.storage.local.get(Setting.AMOUNT_INJECTED, function (items) {
popup._amountInjected = items.amountInjected || 0;
resolve();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment