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

Unified Diff: 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
Patch Set: Improve compliance with the 80 column rule Created Nov. 21, 2016, 8:10 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/common.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
{
« no previous file with comments | « no previous file | lib/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld