Left: | ||
Right: |
OLD | NEW |
---|---|
1 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/; | 1 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/; |
2 | 2 |
3 function splitSelector(selector) | 3 function splitSelector(selector) |
4 { | 4 { |
5 if (selector.indexOf(",") == -1) | 5 if (selector.indexOf(",") == -1) |
6 return [selector]; | 6 return [selector]; |
7 | 7 |
8 var selectors = []; | 8 var selectors = []; |
9 var start = 0; | 9 var start = 0; |
10 var level = 0; | 10 var level = 0; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 { | 66 { |
67 return new URL(stylesheet.href).origin == this.window.location.origin; | 67 return new URL(stylesheet.href).origin == this.window.location.origin; |
68 } | 68 } |
69 catch (e) | 69 catch (e) |
70 { | 70 { |
71 // Invalid URL, assume that it is first-party. | 71 // Invalid URL, assume that it is first-party. |
72 return true; | 72 return true; |
73 } | 73 } |
74 }, | 74 }, |
75 | 75 |
76 findSelectors: function(stylesheet, selectors, filters) | 76 findSelectors: function(stylesheet, filters) |
77 { | 77 { |
78 // Explicitly ignore third-party stylesheets to ensure consistent behavior | 78 // Explicitly ignore third-party stylesheets to ensure consistent behavior |
79 // between Firefox and Chrome. | 79 // between Firefox and Chrome. |
80 if (!this.isSameOrigin(stylesheet)) | 80 if (!this.isSameOrigin(stylesheet)) |
81 return; | 81 return; |
82 | 82 |
83 var rules = stylesheet.cssRules; | 83 let rules = stylesheet.cssRules; |
84 if (!rules) | 84 if (!rules) |
85 return; | 85 return; |
86 | 86 |
87 for (var i = 0; i < rules.length; i++) | 87 for (let rule of rules) |
88 { | 88 { |
89 var rule = rules[i]; | |
90 if (rule.type != rule.STYLE_RULE) | 89 if (rule.type != rule.STYLE_RULE) |
91 continue; | 90 continue; |
92 | 91 |
93 var style = this.stringifyStyle(rule.style); | 92 let style = this.stringifyStyle(rule.style); |
94 for (var j = 0; j < this.patterns.length; j++) | 93 |
94 for (let pattern of this.patterns) | |
95 { | 95 { |
96 var pattern = this.patterns[j]; | |
97 if (pattern.regexp.test(style)) | 96 if (pattern.regexp.test(style)) |
98 { | 97 { |
99 var subSelectors = splitSelector(rule.selectorText); | 98 let selectors = filters.get(pattern.text); |
100 for (var k = 0; k < subSelectors.length; k++) | 99 if (!selectors) |
101 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); | 100 { |
102 filters[pattern.text] = true; | 101 selectors = []; |
102 filters.set(pattern.text, selectors); | |
103 } | |
104 | |
105 let subSelectors = splitSelector(rule.selectorText); | |
Sebastian Noack
2017/02/07 14:55:53
The temporary variable is no longer necessary, as
wspee
2017/02/07 15:01:06
Done.
| |
106 for (let subSelector of subSelectors) | |
107 selectors.push(pattern.prefix + subSelector + pattern.suffix); | |
103 } | 108 } |
104 } | 109 } |
105 } | 110 } |
106 }, | 111 }, |
107 | 112 |
108 addSelectors: function(stylesheets) | 113 addSelectors: function(stylesheets) |
109 { | 114 { |
110 var selectors = []; | 115 var filters = new Map(); |
Sebastian Noack
2017/02/07 14:55:53
While you took the liberty to convert var-statemen
wspee
2017/02/07 15:01:06
Done.
| |
111 var filters = {}; | 116 for (let stylesheet of stylesheets) |
112 for (var i = 0; i < stylesheets.length; i++) | 117 this.findSelectors(stylesheet, filters); |
113 this.findSelectors(stylesheets[i], selectors, filters); | 118 this.addSelectorsFunc(filters); |
114 this.addSelectorsFunc(selectors, Object.keys(filters)); | |
115 }, | 119 }, |
116 | 120 |
117 onLoad: function(event) | 121 onLoad: function(event) |
118 { | 122 { |
119 var stylesheet = event.target.sheet; | 123 var stylesheet = event.target.sheet; |
120 if (stylesheet) | 124 if (stylesheet) |
121 this.addSelectors([stylesheet]); | 125 this.addSelectors([stylesheet]); |
122 }, | 126 }, |
123 | 127 |
124 load: function(callback) | 128 load: function(callback) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 apply: function() | 161 apply: function() |
158 { | 162 { |
159 if (this.patterns.length > 0) | 163 if (this.patterns.length > 0) |
160 { | 164 { |
161 var document = this.window.document; | 165 var document = this.window.document; |
162 this.addSelectors(document.styleSheets); | 166 this.addSelectors(document.styleSheets); |
163 document.addEventListener("load", this.onLoad.bind(this), true); | 167 document.addEventListener("load", this.onLoad.bind(this), true); |
164 } | 168 } |
165 } | 169 } |
166 }; | 170 }; |
OLD | NEW |