Index: chrome/content/elemHideEmulation.js |
=================================================================== |
rename from chrome/content/cssProperties.js |
rename to chrome/content/elemHideEmulation.js |
--- a/chrome/content/cssProperties.js |
+++ b/chrome/content/elemHideEmulation.js |
@@ -1,8 +1,10 @@ |
+var propertySelectorRegExp = /\[\-abp\-properties=(["'])([^"']+)\1\]/; |
+ |
function splitSelector(selector) |
{ |
if (selector.indexOf(",") == -1) |
return [selector]; |
var selectors = []; |
var start = 0; |
var level = 0; |
@@ -31,24 +33,24 @@ |
} |
} |
} |
selectors.push(selector.substring(start)); |
return selectors; |
} |
-function CSSPropertyFilters(window, getFiltersFunc, addSelectorsFunc) |
+function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc) |
{ |
this.window = window; |
this.getFiltersFunc = getFiltersFunc; |
this.addSelectorsFunc = addSelectorsFunc; |
} |
-CSSPropertyFilters.prototype = { |
+ElemHideEmulation.prototype = { |
stringifyStyle: function(style) |
{ |
var styles = []; |
for (var i = 0; i < style.length; i++) |
{ |
var property = style.item(i); |
var value = style.getPropertyValue(property); |
var priority = style.getPropertyPriority(property); |
@@ -87,22 +89,17 @@ |
var rule = rules[i]; |
if (rule.type != rule.STYLE_RULE) |
continue; |
var style = this.stringifyStyle(rule.style); |
for (var j = 0; j < this.patterns.length; j++) |
{ |
var pattern = this.patterns[j]; |
- var regexp = pattern.regexp; |
- |
- if (typeof regexp == "string") |
- regexp = pattern.regexp = new RegExp(regexp, "i"); |
- |
- if (regexp.test(style)) |
+ if (pattern.regexp.test(style)) |
{ |
var subSelectors = splitSelector(rule.selectorText); |
for (var k = 0; k < subSelectors.length; k++) |
selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); |
filters[pattern.text] = true; |
} |
} |
} |
@@ -123,17 +120,40 @@ |
if (stylesheet) |
this.addSelectors([stylesheet]); |
}, |
load: function(callback) |
{ |
this.getFiltersFunc(function(patterns) |
{ |
- this.patterns = patterns; |
+ this.patterns = []; |
+ for (var i = 0; i < patterns.length; i++) |
+ { |
+ var pattern = patterns[i]; |
+ var match = propertySelectorRegExp.exec(pattern.selector); |
+ if (!match) |
+ continue; |
+ |
+ var propertyExpression = match[2]; |
+ var regexpString; |
+ if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && |
+ propertyExpression[propertyExpression.length - 1] == "/") |
+ regexpString = propertyExpression.slice(1, -1); |
+ else |
+ regexpString = filterToRegExp(propertyExpression); |
+ |
+ this.patterns.push({ |
+ text: pattern.text, |
+ regexp: new RegExp(regexpString, "i"), |
+ prefix: pattern.selector.substr(0, match.index), |
+ suffix: pattern.selector.substr(match.index + match[0].length) |
+ }); |
+ } |
+ |
callback(); |
}.bind(this)); |
}, |
apply: function() |
{ |
if (this.patterns.length > 0) |
{ |