Index: lib/cssInjection.js |
=================================================================== |
--- a/lib/cssInjection.js |
+++ b/lib/cssInjection.js |
@@ -21,74 +21,55 @@ |
const {RegExpFilter} = require("filterClasses"); |
const {ElemHide} = require("elemHide"); |
const {checkWhitelisted} = require("whitelisting"); |
const {extractHostFromFrame} = require("url"); |
const {port} = require("messaging"); |
const devtools = require("devtools"); |
-let userStylesheetsSupported = true; |
+const userStyleSheetsSupported = "extensionTypes" in chrome && |
+ "CSSOrigin" in chrome.extensionTypes; |
function hideElements(tabId, frameId, selectors) |
{ |
- let code = selectors.join(", ") + "{display: none !important;}"; |
- |
- try |
- { |
- chrome.tabs.insertCSS(tabId, |
- { |
- code, |
- cssOrigin: "user", |
- frameId, |
- matchAboutBlank: true, |
- runAt: "document_start" |
- } |
- ); |
- return true; |
- } |
- catch (error) |
- { |
- if (/\bError processing cssOrigin\b/.test(error.message) == -1) |
- throw error; |
- |
- userStylesheetsSupported = false; |
- return false; |
- } |
+ chrome.tabs.insertCSS(tabId, { |
+ code: selectors.join(", ") + "{display: none !important;}", |
+ cssOrigin: "user", |
+ frameId, |
+ matchAboutBlank: true, |
+ runAt: "document_start" |
+ }); |
} |
port.on("elemhide.getSelectors", (msg, sender) => |
{ |
- let selectors; |
+ let selectors = []; |
let trace = devtools && devtools.hasPanel(sender.page); |
+ let inject = !userStyleSheetsSupported; |
if (!checkWhitelisted(sender.page, sender.frame, |
RegExpFilter.typeMap.DOCUMENT | |
RegExpFilter.typeMap.ELEMHIDE)) |
{ |
let specificOnly = checkWhitelisted(sender.page, sender.frame, |
RegExpFilter.typeMap.GENERICHIDE); |
selectors = ElemHide.getSelectorsForDomain( |
extractHostFromFrame(sender.frame), |
specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING |
); |
- } |
- else |
- { |
- selectors = []; |
+ |
+ if (!inject && selectors.length > 0) |
+ hideElements(sender.page.id, sender.frame.id, selectors); |
} |
- if (selectors.length == 0 || userStylesheetsSupported && |
- hideElements(sender.page.id, sender.frame.id, selectors)) |
- { |
- if (trace) |
- return {selectors, trace: true, inject: false}; |
+ let response = {trace, inject}; |
Sebastian Noack
2017/09/19 23:09:17
Nit: I would remove this blank line, so that the c
Manish Jethani
2017/09/20 01:36:30
Acknowledged.
But this is outdated now with the l
Sebastian Noack
2017/09/20 01:51:52
This comment is on the latest patch in this review
Manish Jethani
2017/09/20 02:24:00
Rietveld may have messed up, because it looks like
|
- return {trace: false, inject: false}; |
- } |
+ if (trace || inject) |
+ response.selectors = selectors; |
- return {selectors, trace, inject: true}; |
+ return response; |
}); |
port.on("elemhide.injectSelectors", (msg, sender) => |
{ |
- return hideElements(sender.page.id, sender.frame.id, msg.selectors); |
+ hideElements(sender.page.id, sender.frame.id, msg.selectors); |
}); |