OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return; | 92 return; |
93 | 93 |
94 browser.tabs.removeCSS(tabId, { | 94 browser.tabs.removeCSS(tabId, { |
95 code: styleSheet, | 95 code: styleSheet, |
96 cssOrigin: "user", | 96 cssOrigin: "user", |
97 frameId, | 97 frameId, |
98 matchAboutBlank: true | 98 matchAboutBlank: true |
99 }); | 99 }); |
100 } | 100 } |
101 | 101 |
102 function updateFrameStyles(tabId, frameId, selectors, groupName) | 102 function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) |
103 { | 103 { |
104 let styleSheet = null; | 104 let styleSheet = ""; |
105 if (selectors.length > 0) | 105 if (selectors.length > 0) |
106 styleSheet = createStyleSheet(selectors); | 106 styleSheet = createStyleSheet(selectors); |
107 | 107 |
108 let frame = ext.getFrame(tabId, frameId); | 108 let frame = ext.getFrame(tabId, frameId); |
109 if (!frame) | 109 if (!frame) |
110 return false; | 110 return false; |
111 | 111 |
112 if (!frame.injectedStyleSheets) | 112 if (!frame.injectedStyleSheets) |
113 frame.injectedStyleSheets = new Map(); | 113 frame.injectedStyleSheets = new Map(); |
114 | 114 |
115 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); | 115 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); |
116 | 116 |
| 117 if (appendOnly && oldStyleSheet) |
| 118 styleSheet = oldStyleSheet + styleSheet; |
| 119 |
117 // Ideally we would compare the old and new style sheets and skip this code | 120 // Ideally we would compare the old and new style sheets and skip this code |
118 // if they're the same, but the old style sheet can be a leftover from a | 121 // if they're the same, but the old style sheet can be a leftover from a |
119 // previous instance of the frame. We must add the new style sheet | 122 // previous instance of the frame. We must add the new style sheet |
120 // regardless. | 123 // regardless. |
121 | 124 |
122 // Add the new style sheet first to keep previously hidden elements from | 125 // Add the new style sheet first to keep previously hidden elements from |
123 // reappearing momentarily. | 126 // reappearing momentarily. |
124 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) | 127 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) |
125 return false; | 128 return false; |
126 | 129 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // add styles for emulation filters inline. | 177 // add styles for emulation filters inline. |
175 if (!styleSheetRemovalSupported) | 178 if (!styleSheetRemovalSupported) |
176 response.inlineEmulated = true; | 179 response.inlineEmulated = true; |
177 | 180 |
178 return response; | 181 return response; |
179 }); | 182 }); |
180 | 183 |
181 port.on("elemhide.injectSelectors", (message, sender) => | 184 port.on("elemhide.injectSelectors", (message, sender) => |
182 { | 185 { |
183 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 186 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
184 message.groupName); | 187 message.groupName, message.appendOnly); |
185 }); | 188 }); |
OLD | NEW |