Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: chrome/content/elemHideEmulation.js

Issue 29361668: Issue 4394 - Create a filter class for element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Left Patch Set: Address kzar's comments Created Nov. 11, 2016, 11:44 a.m.
Right Patch Set: Improve compliance with the 80 column rule Created Nov. 21, 2016, 8:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/common.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/;
2
1 function splitSelector(selector) 3 function splitSelector(selector)
2 { 4 {
3 if (selector.indexOf(",") == -1) 5 if (selector.indexOf(",") == -1)
4 return [selector]; 6 return [selector];
5 7
6 var selectors = []; 8 var selectors = [];
7 var start = 0; 9 var start = 0;
8 var level = 0; 10 var level = 0;
9 var sep = ""; 11 var sep = "";
10 12
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 }, 122 },
121 123
122 load: function(callback) 124 load: function(callback)
123 { 125 {
124 this.getFiltersFunc(function(patterns) 126 this.getFiltersFunc(function(patterns)
125 { 127 {
126 this.patterns = []; 128 this.patterns = [];
127 for (var i = 0; i < patterns.length; i++) 129 for (var i = 0; i < patterns.length; i++)
128 { 130 {
129 var pattern = patterns[i]; 131 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)
135 continue;
136
137 var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/;
138 var match = propertySelectorRegExp.exec(pattern.selector); 132 var match = propertySelectorRegExp.exec(pattern.selector);
139 if (!match) 133 if (!match)
140 continue; 134 continue;
141 135
136 var propertyExpression = match[2];
137 var regexpString;
138 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
139 propertyExpression[propertyExpression.length - 1] == "/")
140 regexpString = propertyExpression.slice(1, -1);
141 else
142 regexpString = filterToRegExp(propertyExpression);
143
142 this.patterns.push({ 144 this.patterns.push({
143 text: pattern.text, 145 text: pattern.text,
144 regexp: new RegExp(filterToRegExp(match[2])), 146 regexp: new RegExp(regexpString, "i"),
145 prefix: pattern.selector.substr(0, match.index), 147 prefix: pattern.selector.substr(0, match.index),
146 suffix: pattern.selector.substr(match.index + match[0].length) 148 suffix: pattern.selector.substr(match.index + match[0].length)
147 }); 149 });
148 } 150 }
149 151
150 callback(); 152 callback();
151 }.bind(this)); 153 }.bind(this));
152 }, 154 },
153 155
154 apply: function() 156 apply: function()
155 { 157 {
156 if (this.patterns.length > 0) 158 if (this.patterns.length > 0)
157 { 159 {
158 var document = this.window.document; 160 var document = this.window.document;
159 this.addSelectors(document.styleSheets); 161 this.addSelectors(document.styleSheets);
160 document.addEventListener("load", this.onLoad.bind(this), true); 162 document.addEventListener("load", this.onLoad.bind(this), true);
161 } 163 }
162 } 164 }
163 }; 165 };
LEFTRIGHT
« no previous file | lib/common.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld