OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
29 selectors.push(selector.substring(start, i)); | 31 selectors.push(selector.substring(start, i)); |
30 start = i + 1; | 32 start = i + 1; |
31 } | 33 } |
32 } | 34 } |
33 } | 35 } |
34 | 36 |
35 selectors.push(selector.substring(start)); | 37 selectors.push(selector.substring(start)); |
36 return selectors; | 38 return selectors; |
37 } | 39 } |
38 | 40 |
39 function CSSPropertyFilters(window, getFiltersFunc, addSelectorsFunc) | 41 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc) |
40 { | 42 { |
41 this.window = window; | 43 this.window = window; |
42 this.getFiltersFunc = getFiltersFunc; | 44 this.getFiltersFunc = getFiltersFunc; |
43 this.addSelectorsFunc = addSelectorsFunc; | 45 this.addSelectorsFunc = addSelectorsFunc; |
44 } | 46 } |
45 | 47 |
46 CSSPropertyFilters.prototype = { | 48 ElemHideEmulation.prototype = { |
47 stringifyStyle: function(style) | 49 stringifyStyle: function(style) |
48 { | 50 { |
49 var styles = []; | 51 var styles = []; |
50 for (var i = 0; i < style.length; i++) | 52 for (var i = 0; i < style.length; i++) |
51 { | 53 { |
52 var property = style.item(i); | 54 var property = style.item(i); |
53 var value = style.getPropertyValue(property); | 55 var value = style.getPropertyValue(property); |
54 var priority = style.getPropertyPriority(property); | 56 var priority = style.getPropertyPriority(property); |
55 styles.push(property + ": " + value + (priority ? " !" + priority : "") +
";"); | 57 styles.push(property + ": " + value + (priority ? " !" + priority : "") +
";"); |
56 } | 58 } |
(...skipping 28 matching lines...) Expand all Loading... |
85 for (var i = 0; i < rules.length; i++) | 87 for (var i = 0; i < rules.length; i++) |
86 { | 88 { |
87 var rule = rules[i]; | 89 var rule = rules[i]; |
88 if (rule.type != rule.STYLE_RULE) | 90 if (rule.type != rule.STYLE_RULE) |
89 continue; | 91 continue; |
90 | 92 |
91 var style = this.stringifyStyle(rule.style); | 93 var style = this.stringifyStyle(rule.style); |
92 for (var j = 0; j < this.patterns.length; j++) | 94 for (var j = 0; j < this.patterns.length; j++) |
93 { | 95 { |
94 var pattern = this.patterns[j]; | 96 var pattern = this.patterns[j]; |
95 var regexp = pattern.regexp; | 97 if (pattern.regexp.test(style)) |
96 | |
97 if (typeof regexp == "string") | |
98 regexp = pattern.regexp = new RegExp(regexp, "i"); | |
99 | |
100 if (regexp.test(style)) | |
101 { | 98 { |
102 var subSelectors = splitSelector(rule.selectorText); | 99 var subSelectors = splitSelector(rule.selectorText); |
103 for (var k = 0; k < subSelectors.length; k++) | 100 for (var k = 0; k < subSelectors.length; k++) |
104 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); | 101 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); |
105 filters[pattern.text] = true; | 102 filters[pattern.text] = true; |
106 } | 103 } |
107 } | 104 } |
108 } | 105 } |
109 }, | 106 }, |
110 | 107 |
(...skipping 10 matching lines...) Expand all Loading... |
121 { | 118 { |
122 var stylesheet = event.target.sheet; | 119 var stylesheet = event.target.sheet; |
123 if (stylesheet) | 120 if (stylesheet) |
124 this.addSelectors([stylesheet]); | 121 this.addSelectors([stylesheet]); |
125 }, | 122 }, |
126 | 123 |
127 load: function(callback) | 124 load: function(callback) |
128 { | 125 { |
129 this.getFiltersFunc(function(patterns) | 126 this.getFiltersFunc(function(patterns) |
130 { | 127 { |
131 this.patterns = patterns; | 128 this.patterns = []; |
| 129 for (var i = 0; i < patterns.length; i++) |
| 130 { |
| 131 var pattern = patterns[i]; |
| 132 var match = propertySelectorRegExp.exec(pattern.selector); |
| 133 if (!match) |
| 134 continue; |
| 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 |
| 144 this.patterns.push({ |
| 145 text: pattern.text, |
| 146 regexp: new RegExp(regexpString, "i"), |
| 147 prefix: pattern.selector.substr(0, match.index), |
| 148 suffix: pattern.selector.substr(match.index + match[0].length) |
| 149 }); |
| 150 } |
| 151 |
132 callback(); | 152 callback(); |
133 }.bind(this)); | 153 }.bind(this)); |
134 }, | 154 }, |
135 | 155 |
136 apply: function() | 156 apply: function() |
137 { | 157 { |
138 if (this.patterns.length > 0) | 158 if (this.patterns.length > 0) |
139 { | 159 { |
140 var document = this.window.document; | 160 var document = this.window.document; |
141 this.addSelectors(document.styleSheets); | 161 this.addSelectors(document.styleSheets); |
142 document.addEventListener("load", this.onLoad.bind(this), true); | 162 document.addEventListener("load", this.onLoad.bind(this), true); |
143 } | 163 } |
144 } | 164 } |
145 }; | 165 }; |
OLD | NEW |