Index: lib/contentFiltering.js |
=================================================================== |
--- a/lib/contentFiltering.js |
+++ b/lib/contentFiltering.js |
@@ -92,22 +92,19 @@ |
browser.tabs.removeCSS(tabId, { |
code: styleSheet, |
cssOrigin: "user", |
frameId, |
matchAboutBlank: true |
}); |
} |
-function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) |
+function updateFrameStyles(tabId, frameId, styleSheet, groupName = "standard", |
+ appendOnly = false) |
{ |
- let styleSheet = ""; |
- if (selectors.length > 0) |
- styleSheet = createStyleSheet(selectors); |
- |
let frame = ext.getFrame(tabId, frameId); |
if (!frame) |
return false; |
if (!frame.injectedStyleSheets) |
frame.injectedStyleSheets = new Map(); |
let oldStyleSheet = frame.injectedStyleSheets.get(groupName); |
@@ -189,17 +186,17 @@ |
// tabs.insertCSS for why we catch any error here and simply |
// return a rejected promise. |
return Promise.reject(error); |
} |
} |
port.on("content.applyFilters", (message, sender) => |
{ |
- let selectors = []; |
+ let styleSheet = {code: "", selectors: []}; |
let emulatedPatterns = []; |
let trace = HitLogger.hasListener(sender.page.id); |
let inline = !userStyleSheetsSupported; |
let {elemhide, snippets} = message.filterTypes || |
{elemhide: true, snippets: true}; |
if (!checkWhitelisted(sender.page, sender.frame, null, |
@@ -226,39 +223,44 @@ |
} |
} |
if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, |
RegExpFilter.typeMap.ELEMHIDE)) |
{ |
let specificOnly = checkWhitelisted(sender.page, sender.frame, null, |
RegExpFilter.typeMap.GENERICHIDE); |
- selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly); |
+ styleSheet = ElemHide.generateStyleSheetForDomain(docDomain, specificOnly, |
Manish Jethani
2018/09/28 20:57:00
If the third argument is false here, style sheet g
|
+ trace); |
for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) |
emulatedPatterns.push({selector: filter.selector, text: filter.text}); |
} |
} |
if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, |
- selectors, "standard")) |
+ styleSheet.code)) |
{ |
inline = true; |
} |
let response = {trace, inline, emulatedPatterns}; |
- if (trace || inline) |
- response.selectors = selectors; |
+ |
+ if (inline) |
+ response.styleSheet = styleSheet; |
+ else if (trace) |
+ response.styleSheet = {selectors: styleSheet.selectors}; |
return response; |
}); |
port.on("content.injectSelectors", (message, sender) => |
{ |
- updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
+ updateFrameStyles(sender.page.id, sender.frame.id, |
+ createStyleSheet(message.selectors), |
message.groupName, message.appendOnly); |
}); |
fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) |
.then(response => response.ok ? response.text() : "") |
.then(text => |
{ |
snippetsLibrarySource = text; |