Left: | ||
Right: |
OLD | NEW |
---|---|
1 function splitSelector(selector) | 1 function splitSelector(selector) |
2 { | 2 { |
3 if (selector.indexOf(",") == -1) | 3 if (selector.indexOf(",") == -1) |
4 return [selector]; | 4 return [selector]; |
5 | 5 |
6 var selectors = []; | 6 var selectors = []; |
7 var start = 0; | 7 var start = 0; |
8 var level = 0; | 8 var level = 0; |
9 var sep = ""; | 9 var sep = ""; |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 selectors.push(selector.substring(start, i)); | 29 selectors.push(selector.substring(start, i)); |
30 start = i + 1; | 30 start = i + 1; |
31 } | 31 } |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 selectors.push(selector.substring(start)); | 35 selectors.push(selector.substring(start)); |
36 return selectors; | 36 return selectors; |
37 } | 37 } |
38 | 38 |
39 function CSSPropertyFilters(window, getFiltersFunc, addSelectorsFunc) | 39 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc) |
40 { | 40 { |
41 this.window = window; | 41 this.window = window; |
42 this.getFiltersFunc = getFiltersFunc; | 42 this.getFiltersFunc = getFiltersFunc; |
43 this.addSelectorsFunc = addSelectorsFunc; | 43 this.addSelectorsFunc = addSelectorsFunc; |
44 } | 44 } |
45 | 45 |
46 CSSPropertyFilters.prototype = { | 46 ElemHideEmulation.prototype = { |
47 stringifyStyle: function(style) | 47 stringifyStyle: function(style) |
48 { | 48 { |
49 var styles = []; | 49 var styles = []; |
50 for (var i = 0; i < style.length; i++) | 50 for (var i = 0; i < style.length; i++) |
51 { | 51 { |
52 var property = style.item(i); | 52 var property = style.item(i); |
53 var value = style.getPropertyValue(property); | 53 var value = style.getPropertyValue(property); |
54 var priority = style.getPropertyPriority(property); | 54 var priority = style.getPropertyPriority(property); |
55 styles.push(property + ": " + value + (priority ? " !" + priority : "") + ";"); | 55 styles.push(property + ": " + value + (priority ? " !" + priority : "") + ";"); |
56 } | 56 } |
(...skipping 28 matching lines...) Expand all Loading... | |
85 for (var i = 0; i < rules.length; i++) | 85 for (var i = 0; i < rules.length; i++) |
86 { | 86 { |
87 var rule = rules[i]; | 87 var rule = rules[i]; |
88 if (rule.type != rule.STYLE_RULE) | 88 if (rule.type != rule.STYLE_RULE) |
89 continue; | 89 continue; |
90 | 90 |
91 var style = this.stringifyStyle(rule.style); | 91 var style = this.stringifyStyle(rule.style); |
92 for (var j = 0; j < this.patterns.length; j++) | 92 for (var j = 0; j < this.patterns.length; j++) |
93 { | 93 { |
94 var pattern = this.patterns[j]; | 94 var pattern = this.patterns[j]; |
95 var regexp = pattern.regexp; | 95 if (pattern.regexp.test(style)) |
96 | |
97 if (typeof regexp == "string") | |
98 regexp = pattern.regexp = new RegExp(regexp); | |
99 | |
100 if (regexp.test(style)) | |
101 { | 96 { |
102 var subSelectors = splitSelector(rule.selectorText); | 97 var subSelectors = splitSelector(rule.selectorText); |
103 for (var k = 0; k < subSelectors.length; k++) | 98 for (var k = 0; k < subSelectors.length; k++) |
104 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); | 99 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); |
105 filters[pattern.text] = true; | 100 filters[pattern.text] = true; |
106 } | 101 } |
107 } | 102 } |
108 } | 103 } |
109 }, | 104 }, |
110 | 105 |
(...skipping 10 matching lines...) Expand all Loading... | |
121 { | 116 { |
122 var stylesheet = event.target.sheet; | 117 var stylesheet = event.target.sheet; |
123 if (stylesheet) | 118 if (stylesheet) |
124 this.addSelectors([stylesheet]); | 119 this.addSelectors([stylesheet]); |
125 }, | 120 }, |
126 | 121 |
127 load: function(callback) | 122 load: function(callback) |
128 { | 123 { |
129 this.getFiltersFunc(function(patterns) | 124 this.getFiltersFunc(function(patterns) |
130 { | 125 { |
131 this.patterns = patterns; | 126 this.patterns = []; |
127 for (var i = 0; i < patterns.length; i++) | |
128 { | |
129 var pattern = patterns[i]; | |
130 | |
131 // We currently don't support any element hiding emulation feature | |
132 // except for property selectors, so we remove rules that use other | |
133 // features. See https://issues.adblockplus.org/ticket/3143. | |
134 if (pattern.features != elemHideEmulationFeatureMap.PROPERTY_SELECTOR) | |
kzar
2016/11/04 15:45:56
Before I suggested adding a supportedFeatures para
Felix Dahlke
2016/11/04 16:43:35
I'm not sure. For one, I feel that logic belongs i
| |
135 continue; | |
136 | |
137 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/; | |
138 var match = propertySelectorRegExp.exec(pattern.selector); | |
kzar
2016/11/04 15:45:56
I guess the regexp won't necessarily match and if
Felix Dahlke
2016/11/04 16:43:35
Oops, true, I'll fix that.
Felix Dahlke
2016/11/11 11:51:42
Done.
| |
139 this.patterns.push({ | |
140 text: pattern.text, | |
141 regexp: new RegExp(filterToRegExp(match[2])), | |
142 prefix: pattern.selector.substr(0, match.index), | |
143 suffix: pattern.selector.substr(match.index + match[0].length) | |
144 }); | |
145 } | |
146 | |
132 callback(); | 147 callback(); |
133 }.bind(this)); | 148 }.bind(this)); |
134 }, | 149 }, |
135 | 150 |
136 apply: function() | 151 apply: function() |
137 { | 152 { |
138 if (this.patterns.length > 0) | 153 if (this.patterns.length > 0) |
139 { | 154 { |
140 var document = this.window.document; | 155 var document = this.window.document; |
141 this.addSelectors(document.styleSheets); | 156 this.addSelectors(document.styleSheets); |
142 document.addEventListener("load", this.onLoad.bind(this), true); | 157 document.addEventListener("load", this.onLoad.bind(this), true); |
143 } | 158 } |
144 } | 159 } |
145 }; | 160 }; |
OLD | NEW |