Just code style
This commit is contained in:
parent
536dd6a80b
commit
e37087e825
|
@ -31,24 +31,20 @@ var stateManager = {};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
stateManager.registerInjection = function (tabIdentifier, injection) {
|
stateManager.registerInjection = function (tabIdentifier, injection) {
|
||||||
|
|
||||||
let injectionIdentifier, registeredTab, injectionCount;
|
let injectionIdentifier, registeredTab, injectionCount;
|
||||||
|
|
||||||
injectionIdentifier = injection.source + injection.path + injection.version;
|
injectionIdentifier = injection.source + injection.path + injection.version;
|
||||||
registeredTab = stateManager.tabs[tabIdentifier];
|
registeredTab = stateManager.tabs[tabIdentifier];
|
||||||
|
|
||||||
registeredTab.injections[injectionIdentifier] = injection;
|
registeredTab.injections[injectionIdentifier] = injection;
|
||||||
injectionCount = Object.keys(registeredTab.injections).length || 0;
|
injectionCount = Object.keys(registeredTab.injections).length || 0;
|
||||||
|
|
||||||
if (injectionCount > 0) {
|
if (injectionCount > 0) {
|
||||||
|
|
||||||
chrome.browserAction.setTitle({
|
chrome.browserAction.setTitle({
|
||||||
'tabId': tabIdentifier,
|
'tabId': tabIdentifier,
|
||||||
'title': `LocalCDN (${injectionCount})`
|
'title': `LocalCDN (${injectionCount})`
|
||||||
});
|
});
|
||||||
|
|
||||||
if (stateManager.showIconBadge === true) {
|
if (stateManager.showIconBadge === true) {
|
||||||
|
|
||||||
wrappers.setBadgeText({
|
wrappers.setBadgeText({
|
||||||
'tabId': tabIdentifier,
|
'tabId': tabIdentifier,
|
||||||
'text': injectionCount.toString()
|
'text': injectionCount.toString()
|
||||||
|
@ -57,42 +53,34 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNaN(storageManager.amountInjected)) {
|
if (isNaN(storageManager.amountInjected)) {
|
||||||
|
|
||||||
storageManager.type.get(Setting.AMOUNT_INJECTED, function (items) {
|
storageManager.type.get(Setting.AMOUNT_INJECTED, function (items) {
|
||||||
|
|
||||||
storageManager.amountInjected = items.amountInjected;
|
storageManager.amountInjected = items.amountInjected;
|
||||||
|
|
||||||
storageManager.type.set({
|
storageManager.type.set({
|
||||||
[Setting.AMOUNT_INJECTED]: ++storageManager.amountInjected
|
[Setting.AMOUNT_INJECTED]: ++storageManager.amountInjected
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
[Setting.AMOUNT_INJECTED]: ++storageManager.amountInjected
|
[Setting.AMOUNT_INJECTED]: ++storageManager.amountInjected
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stateManager.internalStatistics) {
|
if (stateManager.internalStatistics) {
|
||||||
stats.setStats(injection);
|
stats.setStats(injection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager.addDomainToAllowlist = function (domain) {
|
stateManager.addDomainToAllowlist = function (domain) {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
let allowlistedDomains = requestAnalyzer.allowlistedDomains;
|
let allowlistedDomains = requestAnalyzer.allowlistedDomains;
|
||||||
allowlistedDomains[domain] = true;
|
|
||||||
|
|
||||||
|
allowlistedDomains[domain] = true;
|
||||||
storageManager.type.set({allowlistedDomains}, resolve);
|
storageManager.type.set({allowlistedDomains}, resolve);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager.removeDomainFromAllowlist = function (domain) {
|
stateManager.removeDomainFromAllowlist = function (domain) {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
let allowlistedDomains, wildcard;
|
let allowlistedDomains, wildcard;
|
||||||
|
|
||||||
allowlistedDomains = requestAnalyzer.allowlistedDomains;
|
allowlistedDomains = requestAnalyzer.allowlistedDomains;
|
||||||
|
@ -109,10 +97,9 @@ stateManager.removeDomainFromAllowlist = function (domain) {
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager.addDomainToManipulateDOMlist = function (domain) {
|
stateManager.addDomainToManipulateDOMlist = function (domain) {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
|
let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
|
||||||
|
|
||||||
domainsManipulateDOM[domain] = true;
|
domainsManipulateDOM[domain] = true;
|
||||||
|
|
||||||
storageManager.type.set({domainsManipulateDOM}, resolve);
|
storageManager.type.set({domainsManipulateDOM}, resolve);
|
||||||
|
@ -120,10 +107,9 @@ stateManager.addDomainToManipulateDOMlist = function (domain) {
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager.removeDomainFromManipulateDOMlist = function (domain) {
|
stateManager.removeDomainFromManipulateDOMlist = function (domain) {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
|
let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
|
||||||
|
|
||||||
delete domainsManipulateDOM[domain];
|
delete domainsManipulateDOM[domain];
|
||||||
|
|
||||||
storageManager.type.set({domainsManipulateDOM}, resolve);
|
storageManager.type.set({domainsManipulateDOM}, resolve);
|
||||||
|
@ -136,7 +122,6 @@ stateManager.removeDomainFromManipulateDOMlist = function (domain) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
stateManager._createTab = function (tab) {
|
stateManager._createTab = function (tab) {
|
||||||
|
|
||||||
let tabIdentifier, requestFilters;
|
let tabIdentifier, requestFilters;
|
||||||
|
|
||||||
tabIdentifier = tab.id;
|
tabIdentifier = tab.id;
|
||||||
|
@ -151,10 +136,8 @@ stateManager._createTab = function (tab) {
|
||||||
};
|
};
|
||||||
|
|
||||||
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
|
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
|
||||||
|
|
||||||
tab = stateManager.tabs[tabIdentifier].details || {};
|
tab = stateManager.tabs[tabIdentifier].details || {};
|
||||||
return interceptor.handleRequest(requestDetails, tabIdentifier, tab);
|
return interceptor.handleRequest(requestDetails, tabIdentifier, tab);
|
||||||
|
|
||||||
}, requestFilters, [WebRequest.BLOCKING]);
|
}, requestFilters, [WebRequest.BLOCKING]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -163,12 +146,10 @@ stateManager._removeTab = function (tabIdentifier) {
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager._updateTab = function (details) {
|
stateManager._updateTab = function (details) {
|
||||||
|
|
||||||
let tabDomain, domainIsAllowlisted, frameIdentifier, tabIdentifier;
|
let tabDomain, domainIsAllowlisted, frameIdentifier, tabIdentifier;
|
||||||
|
|
||||||
tabDomain = helpers.extractDomainFromUrl(details.url, true);
|
tabDomain = helpers.extractDomainFromUrl(details.url, true);
|
||||||
domainIsAllowlisted = stateManager._domainIsListed(tabDomain);
|
domainIsAllowlisted = stateManager._domainIsListed(tabDomain);
|
||||||
|
|
||||||
frameIdentifier = details.frameId;
|
frameIdentifier = details.frameId;
|
||||||
tabIdentifier = details.tabId;
|
tabIdentifier = details.tabId;
|
||||||
|
|
||||||
|
@ -182,9 +163,7 @@ stateManager._updateTab = function (details) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (domainIsAllowlisted) {
|
if (domainIsAllowlisted) {
|
||||||
|
|
||||||
stateManager._setIconDisabled(tabIdentifier);
|
stateManager._setIconDisabled(tabIdentifier);
|
||||||
|
|
||||||
chrome.browserAction.setTitle({
|
chrome.browserAction.setTitle({
|
||||||
'tabId': tabIdentifier,
|
'tabId': tabIdentifier,
|
||||||
'title': 'LocalCDN (–)'
|
'title': 'LocalCDN (–)'
|
||||||
|
@ -201,43 +180,30 @@ stateManager._updateTab = function (details) {
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager._handleStorageChanged = function (changes) {
|
stateManager._handleStorageChanged = function (changes) {
|
||||||
|
|
||||||
if (Setting.SHOW_ICON_BADGE in changes) {
|
if (Setting.SHOW_ICON_BADGE in changes) {
|
||||||
|
|
||||||
stateManager.showIconBadge = changes.showIconBadge.newValue;
|
stateManager.showIconBadge = changes.showIconBadge.newValue;
|
||||||
|
|
||||||
if (changes.showIconBadge.newValue !== true) {
|
if (changes.showIconBadge.newValue !== true) {
|
||||||
|
|
||||||
chrome.tabs.query({}, function (tabs) {
|
chrome.tabs.query({}, function (tabs) {
|
||||||
tabs.forEach(stateManager._removeIconBadgeFromTab);
|
tabs.forEach(stateManager._removeIconBadgeFromTab);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} else if (Setting.STRIP_METADATA in changes) {
|
||||||
|
|
||||||
if (Setting.STRIP_METADATA in changes) {
|
|
||||||
|
|
||||||
requestSanitizer.disable();
|
requestSanitizer.disable();
|
||||||
|
|
||||||
if (changes.stripMetadata.newValue !== false) {
|
if (changes.stripMetadata.newValue !== false) {
|
||||||
requestSanitizer.enable();
|
requestSanitizer.enable();
|
||||||
}
|
}
|
||||||
}
|
} else if (Setting.NEGATE_HTML_FILTER_LIST in changes) {
|
||||||
if (Setting.NEGATE_HTML_FILTER_LIST in changes) {
|
|
||||||
stateManager.getInvertOption = changes.negateHtmlFilterList.newValue;
|
stateManager.getInvertOption = changes.negateHtmlFilterList.newValue;
|
||||||
}
|
} else if (Setting.SELECTED_ICON in changes) {
|
||||||
if (Setting.SELECTED_ICON in changes) {
|
|
||||||
stateManager.selectedIcon = changes.selectedIcon.newValue;
|
stateManager.selectedIcon = changes.selectedIcon.newValue;
|
||||||
}
|
} else if (Setting.INTERNAL_STATISTICS in changes) {
|
||||||
if (Setting.INTERNAL_STATISTICS in changes) {
|
|
||||||
stateManager.internalStatistics = changes.internalStatistics.newValue;
|
stateManager.internalStatistics = changes.internalStatistics.newValue;
|
||||||
}
|
} else if (Setting.INTERNAL_STATISTICS_DATA in changes) {
|
||||||
if (Setting.INTERNAL_STATISTICS_DATA in changes) {
|
|
||||||
stats.data = changes.internalStatisticsData.newValue;
|
stats.data = changes.internalStatisticsData.newValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager._clearBadgeText = function (tabIdentifier) {
|
stateManager._clearBadgeText = function (tabIdentifier) {
|
||||||
|
|
||||||
wrappers.setBadgeText({
|
wrappers.setBadgeText({
|
||||||
'tabId': tabIdentifier,
|
'tabId': tabIdentifier,
|
||||||
'text': ''
|
'text': ''
|
||||||
|
@ -250,7 +216,6 @@ stateManager._removeIconBadgeFromTab = function (tab) {
|
||||||
|
|
||||||
stateManager._domainIsListed = function (domain, listname) {
|
stateManager._domainIsListed = function (domain, listname) {
|
||||||
if (domain !== null) {
|
if (domain !== null) {
|
||||||
|
|
||||||
let allowlistRecord, isAllowlisted;
|
let allowlistRecord, isAllowlisted;
|
||||||
|
|
||||||
if (listname === 'manipulate-dom') {
|
if (listname === 'manipulate-dom') {
|
||||||
|
@ -260,15 +225,12 @@ stateManager._domainIsListed = function (domain, listname) {
|
||||||
allowlistRecord = helpers.checkAllowlisted(domain);
|
allowlistRecord = helpers.checkAllowlisted(domain);
|
||||||
isAllowlisted = Boolean(allowlistRecord);
|
isAllowlisted = Boolean(allowlistRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isAllowlisted;
|
return isAllowlisted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
stateManager._setIconDisabled = function (tabIdentifier) {
|
stateManager._setIconDisabled = function (tabIdentifier) {
|
||||||
|
|
||||||
wrappers.setIcon({
|
wrappers.setIcon({
|
||||||
'path': stateManager.selectedIcon,
|
'path': stateManager.selectedIcon,
|
||||||
'tabId': tabIdentifier
|
'tabId': tabIdentifier
|
||||||
|
@ -288,7 +250,6 @@ stateManager.selectedIcon = 'Default';
|
||||||
stateManager.internalStatistics = false;
|
stateManager.internalStatistics = false;
|
||||||
|
|
||||||
for (let mapping in mappings.cdn) {
|
for (let mapping in mappings.cdn) {
|
||||||
|
|
||||||
let supportedHost = Address.ANY_PROTOCOL + mapping + Address.ANY_PATH;
|
let supportedHost = Address.ANY_PROTOCOL + mapping + Address.ANY_PATH;
|
||||||
stateManager.validHosts.push(supportedHost);
|
stateManager.validHosts.push(supportedHost);
|
||||||
}
|
}
|
||||||
|
@ -298,7 +259,6 @@ chrome.tabs.query({}, function (tabs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
storageManager.type.get([Setting.SHOW_ICON_BADGE, Setting.SELECTED_ICON], function (items) {
|
storageManager.type.get([Setting.SHOW_ICON_BADGE, Setting.SELECTED_ICON], function (items) {
|
||||||
|
|
||||||
if (items.showIconBadge === undefined) {
|
if (items.showIconBadge === undefined) {
|
||||||
items.showIconBadge = true;
|
items.showIconBadge = true;
|
||||||
}
|
}
|
||||||
|
@ -322,14 +282,11 @@ chrome.tabs.onCreated.addListener(stateManager._createTab);
|
||||||
chrome.tabs.onRemoved.addListener(stateManager._removeTab);
|
chrome.tabs.onRemoved.addListener(stateManager._removeTab);
|
||||||
|
|
||||||
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
|
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
|
||||||
|
|
||||||
if (requestDetails.tabId !== -1 && stateManager.tabs[requestDetails.tabId]) {
|
if (requestDetails.tabId !== -1 && stateManager.tabs[requestDetails.tabId]) {
|
||||||
|
|
||||||
stateManager.tabs[requestDetails.tabId].details = {
|
stateManager.tabs[requestDetails.tabId].details = {
|
||||||
'url': requestDetails.url
|
'url': requestDetails.url
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}, {'types': [WebRequestType.MAIN_FRAME], 'urls': [Address.ANY]}, [WebRequest.BLOCKING]);
|
}, {'types': [WebRequestType.MAIN_FRAME], 'urls': [Address.ANY]}, [WebRequest.BLOCKING]);
|
||||||
|
|
||||||
chrome.webNavigation.onCommitted.addListener(stateManager._updateTab, {
|
chrome.webNavigation.onCommitted.addListener(stateManager._updateTab, {
|
||||||
|
@ -337,23 +294,17 @@ chrome.webNavigation.onCommitted.addListener(stateManager._updateTab, {
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.webRequest.onErrorOccurred.addListener(function (requestDetails) {
|
chrome.webRequest.onErrorOccurred.addListener(function (requestDetails) {
|
||||||
|
|
||||||
if (stateManager.requests[requestDetails.requestId]) {
|
if (stateManager.requests[requestDetails.requestId]) {
|
||||||
delete stateManager.requests[requestDetails.requestId];
|
delete stateManager.requests[requestDetails.requestId];
|
||||||
}
|
}
|
||||||
|
|
||||||
}, {'urls': [Address.ANY]});
|
}, {'urls': [Address.ANY]});
|
||||||
|
|
||||||
chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
|
chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
|
||||||
|
|
||||||
let knownRequest = stateManager.requests[requestDetails.requestId];
|
let knownRequest = stateManager.requests[requestDetails.requestId];
|
||||||
|
|
||||||
if (knownRequest) {
|
if (knownRequest) {
|
||||||
|
|
||||||
stateManager.registerInjection(knownRequest.tabIdentifier, knownRequest.targetDetails);
|
stateManager.registerInjection(knownRequest.tabIdentifier, knownRequest.targetDetails);
|
||||||
delete stateManager.requests[requestDetails.requestId];
|
delete stateManager.requests[requestDetails.requestId];
|
||||||
}
|
}
|
||||||
|
|
||||||
}, {'urls': [Address.ANY]});
|
}, {'urls': [Address.ANY]});
|
||||||
|
|
||||||
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
|
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
|
||||||
|
|
Loading…
Reference in New Issue