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 = null; |
let trace = devtools && devtools.hasPanel(sender.page); |
+ let inject = !userStyleSheetsSupported; |
Manish Jethani
2017/09/17 13:51:38
The trace and inject values are pretty much consta
|
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) |
Manish Jethani
2017/09/17 13:51:38
This has been moved inside the if block. If we're
|
+ 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}; |
Manish Jethani
2017/09/17 13:51:38
trace and inject pretty much have to be passed as
|
- return {trace: false, inject: false}; |
- } |
+ if ((trace || inject) && selectors && selectors.length > 0) |
Manish Jethani
2017/09/17 13:51:38
Include a selectors property only if either trace
Manish Jethani
2017/09/17 15:09:19
Or:
let selectors = null;
...
...
...
r
Sebastian Noack
2017/09/18 22:46:37
How about this?
let selectors = [];
...
if
Manish Jethani
2017/09/19 05:47:26
OK, I like this.
Done.
Sebastian Noack
2017/09/19 23:09:17
Yes, you have to check for selectors.length regard
Manish Jethani
2017/09/20 01:36:29
With the latest patch there's no check for selecto
Sebastian Noack
2017/09/20 01:51:52
Sure, but why don't you just flatten the logic by
Manish Jethani
2017/09/20 02:23:59
Done.
selectors starting out as null or an empty
|
+ 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); |
}); |