Index: lib/contentFiltering.js |
=================================================================== |
--- a/lib/contentFiltering.js |
+++ b/lib/contentFiltering.js |
@@ -94,22 +94,18 @@ |
browser.tabs.removeCSS(tabId, { |
code: styleSheet, |
cssOrigin: "user", |
frameId, |
matchAboutBlank: true |
}); |
} |
-function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) |
+function updateFrameStyles(tabId, frameId, styleSheet, groupName, appendOnly) |
{ |
- 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); |
@@ -191,16 +187,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 styleSheet = ""; |
let selectors = []; |
let emulatedPatterns = []; |
let trace = HitLogger.hasListener(sender.page.id); |
let inline = !userStyleSheetsSupported; |
let {elemhide, snippets} = message.filterTypes || |
{elemhide: true, snippets: true}; |
@@ -229,38 +226,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 = createStyleSheet(selectors); |
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, "standard")) |
{ |
inline = true; |
} |
let response = {trace, inline, emulatedPatterns}; |
- if (trace || inline) |
+ |
+ if (inline) |
+ response.styleSheet = styleSheet; |
+ |
+ if (trace) |
response.selectors = selectors; |
return response; |
}); |
port.on("elemhide.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; |