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

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

Issue 29372676: [adblockpluscore] Issue 4825 - Let ElemHideEmulation associate selector and filter when calling add… (Closed)
Patch Set: Changed map to two arrays Created Feb. 9, 2017, 8:05 a.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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 }, 74 },
75 75
76 findSelectors: function(stylesheet, selectors, filters) 76 findSelectors: function(stylesheet, selectors, 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 for (let pattern of this.patterns)
95 { 94 {
96 var pattern = this.patterns[j];
97 if (pattern.regexp.test(style)) 95 if (pattern.regexp.test(style))
98 { 96 {
99 var subSelectors = splitSelector(rule.selectorText); 97 let subSelectors = splitSelector(rule.selectorText);
100 for (var k = 0; k < subSelectors.length; k++) 98 for (let subSelector of subSelectors)
101 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); 99 {
102 filters[pattern.text] = true; 100 selectors.push(pattern.prefix + subSelector + pattern.suffix);
101 filters.push(pattern.text);
102 }
103 } 103 }
104 } 104 }
105 } 105 }
106 }, 106 },
107 107
108 addSelectors: function(stylesheets) 108 addSelectors: function(stylesheets)
109 { 109 {
110 var selectors = []; 110 var selectors = [];
111 var filters = {}; 111 var filters = [];
112 for (var i = 0; i < stylesheets.length; i++) 112 for (var i = 0; i < stylesheets.length; i++)
113 this.findSelectors(stylesheets[i], selectors, filters); 113 this.findSelectors(stylesheets[i], selectors, filters);
114 this.addSelectorsFunc(selectors, Object.keys(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 load: function(callback)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 apply: function() 157 apply: function()
158 { 158 {
159 if (this.patterns.length > 0) 159 if (this.patterns.length > 0)
160 { 160 {
161 var document = this.window.document; 161 var document = this.window.document;
162 this.addSelectors(document.styleSheets); 162 this.addSelectors(document.styleSheets);
163 document.addEventListener("load", this.onLoad.bind(this), true); 163 document.addEventListener("load", this.onLoad.bind(this), true);
164 } 164 }
165 } 165 }
166 }; 166 };
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