Verified Commit e81ed053 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Refactor existing codebase

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