Index: lib/devtools.js |
diff --git a/lib/devtools.js b/lib/devtools.js |
index d4a6e7b9039d4fde52a158c91bb992f8decc0a9c..ba9f5c93193ad3208b45c45e2d195a732d76fb5f 100644 |
--- a/lib/devtools.js |
+++ b/lib/devtools.js |
@@ -44,7 +44,7 @@ function hasPanels() |
function getActivePanel(page) |
{ |
let panel = panels[page.id]; |
- if(panel && !panel.reload && !panel.reloading) |
+ if (panel && !panel.reload && !panel.reloading) |
return panel; |
return null; |
} |
@@ -71,7 +71,7 @@ function getFilterInfo(filter) |
return { |
text: filter.text, |
whitelisted: filter instanceof WhitelistFilter, |
- userDefined: userDefined, |
+ userDefined, |
subscription: subscriptionTitle |
}; |
} |
@@ -79,16 +79,17 @@ function getFilterInfo(filter) |
function hasRecord(panel, request, filter) |
{ |
return panel.records.some(record => |
- record.request.url == request.url && |
+ record.request.url == request.url && |
record.request.docDomain == request.docDomain && |
// Ignore partial (e.g. ELEMHIDE) whitelisting if there is already |
// a DOCUMENT exception which disables all means of blocking. |
- (record.request.type == "DOCUMENT" ? nonRequestTypes.indexOf(request.type) != -1 |
- : record.request.type == request.type) && |
+ (record.request.type == "DOCUMENT" ? |
+ nonRequestTypes.includes(request.type) : |
+ record.request.type == request.type) && |
// Matched element hiding filters don't relate to a particular request, |
- // so we also have to match the CSS selector in order to distinguish them. |
+ // so we have to compare the selector in order to avoid duplicates. |
(record.filter && record.filter.selector) == (filter && filter.selector) |
); |
} |
@@ -99,14 +100,11 @@ function addRecord(panel, request, filter) |
{ |
panel.port.postMessage({ |
type: "add-record", |
- request: request, |
+ request, |
filter: getFilterInfo(filter) |
}); |
- panel.records.push({ |
- request: request, |
- filter: filter |
- }); |
+ panel.records.push({request, filter}); |
} |
} |
@@ -129,10 +127,12 @@ function matchRequest(request) |
* @param {string} url The URL of the request |
* @param {string} type The request type |
* @param {string} docDomain The IDN-decoded hostname of the document |
- * @param {boolean} thirdParty Whether the origin of the request and document differs |
+ * @param {boolean} thirdParty Whether the origin of the request and |
+ * document differs |
* @param {?string} sitekey The active sitekey if there is any |
* @param {?boolean} specificOnly Whether generic filters should be ignored |
- * @param {?BlockingFilter} filter The matched filter or null if there is no match |
+ * @param {?BlockingFilter} filter The matched filter or null if there is no |
+ * match |
*/ |
exports.logRequest = function(page, url, type, docDomain, |
thirdParty, sitekey, |
@@ -141,15 +141,7 @@ exports.logRequest = function(page, url, type, docDomain, |
let panel = getActivePanel(page); |
if (panel) |
{ |
- let request = { |
- url: url, |
- type: type, |
- docDomain: docDomain, |
- thirdParty: thirdParty, |
- sitekey: sitekey, |
- specificOnly: specificOnly |
- }; |
- |
+ let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; |
addRecord(panel, request, filter); |
} |
}; |
@@ -181,11 +173,11 @@ function logHiddenElements(page, selectors, docDomain) |
if (!filter.isActiveOnDomain(docDomain)) |
continue; |
- addRecord(panel, {type: "ELEMHIDE", docDomain: docDomain}, filter); |
+ addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); |
} |
} |
} |
-}; |
+} |
/** |
* Logs a whitelisting filter, that disables (some kind of) |
@@ -193,11 +185,14 @@ function logHiddenElements(page, selectors, docDomain) |
* |
* @param {Page} page The page the whitelisting is active on |
* @param {string} url The url of the whitelisted document |
- * @param {number} typeMask The bit mask of whitelisting types checked for |
- * @param {string} docDomain The IDN-decoded hostname of the parent document |
+ * @param {number} typeMask The bit mask of whitelisting types checked |
+ * for |
+ * @param {string} docDomain The IDN-decoded hostname of the parent |
+ * document |
* @param {WhitelistFilter} filter The matched whitelisting filter |
*/ |
-exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, filter) |
+exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, |
+ filter) |
{ |
let panel = getActivePanel(page); |
if (panel) |
@@ -205,7 +200,7 @@ exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, filter |
for (let type of nonRequestTypes) |
{ |
if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) |
- addRecord(panel, {url: url, type: type, docDomain: docDomain}, filter); |
+ addRecord(panel, {url, type, docDomain}, filter); |
} |
} |
}; |
@@ -339,9 +334,9 @@ function onSubscriptionAdded(subscription) |
updateFilters(subscription.filters, true); |
} |
-chrome.runtime.onConnect.addListener(port => |
+chrome.runtime.onConnect.addListener(newPort => |
{ |
- let match = port.name.match(/^devtools-(\d+)$/); |
+ let match = newPort.name.match(/^devtools-(\d+)$/); |
if (!match) |
return; |
@@ -351,7 +346,7 @@ chrome.runtime.onConnect.addListener(port => |
chrome.webRequest.onBeforeRequest.addListener( |
localOnBeforeRequest, |
{ |
- urls: ["<all_urls>"], |
+ urls: ["<all_urls>"], |
types: ["main_frame"], |
tabId: inspectedTabId |
} |
@@ -365,7 +360,7 @@ chrome.runtime.onConnect.addListener(port => |
FilterNotifier.on("subscription.added", onSubscriptionAdded); |
} |
- port.onDisconnect.addListener(() => |
+ newPort.onDisconnect.addListener(() => |
{ |
delete panels[inspectedTabId]; |
chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); |
@@ -379,7 +374,7 @@ chrome.runtime.onConnect.addListener(port => |
} |
}); |
- panels[inspectedTabId] = {port: port, records: []}; |
+ panels[inspectedTabId] = {port: newPort, records: []}; |
}); |
port.on("devtools.traceElemHide", (message, sender) => |