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

Side by Side Diff: chrome/content/elemHideEmulation.js

Issue 29375888: [adblockpluscore] Issue 4911 - Merge ElemHideEmulation.load/apply into one function (Closed)
Patch Set: Removed unused callback parameter Created Feb. 18, 2017, 12:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 this.addSelectorsFunc(selectors, filters); 114 this.addSelectorsFunc(selectors, filters);
115 }, 115 },
116 116
117 onLoad: function(event) 117 onLoad: function(event)
118 { 118 {
119 var stylesheet = event.target.sheet; 119 var stylesheet = event.target.sheet;
120 if (stylesheet) 120 if (stylesheet)
121 this.addSelectors([stylesheet]); 121 this.addSelectors([stylesheet]);
122 }, 122 },
123 123
124 load: function(callback) 124 apply: function()
125 { 125 {
126 this.getFiltersFunc(function(patterns) 126 this.getFiltersFunc(function(patterns)
127 { 127 {
128 this.patterns = []; 128 this.patterns = [];
129 for (var i = 0; i < patterns.length; i++) 129 for (var i = 0; i < patterns.length; i++)
130 { 130 {
131 var pattern = patterns[i]; 131 var pattern = patterns[i];
132 var match = propertySelectorRegExp.exec(pattern.selector); 132 var match = propertySelectorRegExp.exec(pattern.selector);
133 if (!match) 133 if (!match)
134 continue; 134 continue;
135 135
136 var propertyExpression = match[2]; 136 var propertyExpression = match[2];
137 var regexpString; 137 var regexpString;
138 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && 138 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
139 propertyExpression[propertyExpression.length - 1] == "/") 139 propertyExpression[propertyExpression.length - 1] == "/")
140 regexpString = propertyExpression.slice(1, -1) 140 regexpString = propertyExpression.slice(1, -1)
141 .replace("\\x7B ", "{").replace("\\x7D ", "}"); 141 .replace("\\x7B ", "{").replace("\\x7D ", "}");
142 else 142 else
143 regexpString = filterToRegExp(propertyExpression); 143 regexpString = filterToRegExp(propertyExpression);
144 144
145 this.patterns.push({ 145 this.patterns.push({
146 text: pattern.text, 146 text: pattern.text,
147 regexp: new RegExp(regexpString, "i"), 147 regexp: new RegExp(regexpString, "i"),
148 prefix: pattern.selector.substr(0, match.index), 148 prefix: pattern.selector.substr(0, match.index),
149 suffix: pattern.selector.substr(match.index + match[0].length) 149 suffix: pattern.selector.substr(match.index + match[0].length)
150 }); 150 });
151 } 151 }
152 152
153 callback(); 153 if (this.patterns.length > 0)
154 {
155 var document = this.window.document;
156 this.addSelectors(document.styleSheets);
157 document.addEventListener("load", this.onLoad.bind(this), true);
158 }
154 }.bind(this)); 159 }.bind(this));
155 },
156
157 apply: function()
158 {
159 if (this.patterns.length > 0)
160 {
161 var document = this.window.document;
162 this.addSelectors(document.styleSheets);
163 document.addEventListener("load", this.onLoad.bind(this), true);
164 }
165 } 160 }
166 }; 161 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld