Index: lib/cssInjection.js |
=================================================================== |
--- a/lib/cssInjection.js |
+++ b/lib/cssInjection.js |
@@ -21,43 +21,30 @@ |
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; |
+let userStyleSheetsSupported = "extensionTypes" in chrome && |
Manish Jethani
2017/09/15 13:02:42
Note: "style sheet" is actually two words, I've ch
Sebastian Noack
2017/09/15 18:46:37
In which case, does chrome.extensionTypes does not
Manish Jethani
2017/09/15 21:26:08
It doesn't exist on Chrome.
Sebastian Noack
2017/09/15 22:52:44
Indeed. The MDN compatibility information are misl
|
+ "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, |
Sebastian Noack
2017/09/15 18:46:37
Nit: The additional indentation (and one additiona
Manish Jethani
2017/09/15 21:26:09
Done.
|
+ { |
+ code: selectors.join(", ") + "{display: none !important;}", |
+ cssOrigin: "user", |
+ frameId, |
+ matchAboutBlank: true, |
+ runAt: "document_start" |
+ } |
+ ); |
} |
port.on("elemhide.getSelectors", (msg, sender) => |
{ |
let selectors; |
let trace = devtools && devtools.hasPanel(sender.page); |
if (!checkWhitelisted(sender.page, sender.frame, |
@@ -71,24 +58,27 @@ |
specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING |
); |
} |
else |
{ |
selectors = []; |
} |
- if (selectors.length == 0 || userStylesheetsSupported && |
- hideElements(sender.page.id, sender.frame.id, selectors)) |
+ if (selectors.length == 0 || userStyleSheetsSupported) |
Sebastian Noack
2017/09/15 18:46:37
I had a go before. But you were quicker, getting y
Manish Jethani
2017/09/15 21:26:08
I've incorporated the simplifications and made som
|
{ |
+ if (userStyleSheetsSupported && selectors.length > 0) |
+ hideElements(sender.page.id, sender.frame.id, selectors); |
Manish Jethani
2017/09/15 13:02:42
If userStyleSheetsSupported is true then a call to
|
+ |
if (trace) |
return {selectors, trace: true, inject: false}; |
return {trace: false, inject: false}; |
} |
return {selectors, trace, inject: true}; |
}); |
port.on("elemhide.injectSelectors", (msg, sender) => |
{ |
- return hideElements(sender.page.id, sender.frame.id, msg.selectors); |
+ if (userStyleSheetsSupported) |
Manish Jethani
2017/09/15 13:02:42
Since there's no try...catch in hideElements now,
Sebastian Noack
2017/09/15 18:46:37
It seems no message of this type is send by the co
Manish Jethani
2017/09/15 21:26:09
Done.
|
+ hideElements(sender.page.id, sender.frame.id, msg.selectors); |
}); |