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

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

Issue 29335650: Issue 2595 - Use the core code from adblockpluscore (Closed)
Patch Set: Created Feb. 4, 2016, 6:35 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 | chrome/content/ui/subscriptions.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 function CSSPropertyFilters(window, addSelectorsFunc) {
2 this.window = window;
3 this.addSelectorsFunc = addSelectorsFunc;
4 }
5
6 CSSPropertyFilters.prototype = {
7 stringifyStyle: function(style)
8 {
9 var styles = [];
10 for (var i = 0; i < style.length; i++)
11 {
12 var property = style.item(i);
13 var value = style.getPropertyValue(property);
14 var priority = style.getPropertyPriority(property);
15 styles.push(property + ": " + value + (priority ? " !" + priority : "") + ";");
16 }
17 styles.sort();
18 return styles.join(" ");
19 },
20
21 findSelectors: function(stylesheet, selectors)
22 {
23 var rules = stylesheet.cssRules;
24 if (!rules)
25 return;
26
27 for (var i = 0; i < rules.length; i++)
28 {
29 var rule = rules[i];
30 if (rule.type != this.window.CSSRule.STYLE_RULE)
31 continue;
32
33 var style = this.stringifyStyle(rule.style);
34 for (var j = 0; j < this.patterns.length; j++)
35 {
36 var pattern = this.patterns[j];
37 var regexp = pattern.regexp;
38
39 if (typeof regexp == "string")
40 regexp = pattern.regexp = new RegExp(regexp);
41
42 if (regexp.test(style))
43 selectors.push(pattern.prefix + rule.selectorText + pattern.suffix);
44 }
45 }
46 },
47
48 addSelectors: function(stylesheets)
49 {
50 var selectors = [];
51 for (var i = 0; i < stylesheets.length; i++)
52 this.findSelectors(stylesheets[i], selectors);
53 this.addSelectorsFunc(selectors);
54 },
55
56 onLoad: function(event)
57 {
58 var stylesheet = event.target.sheet;
59 if (stylesheet)
60 this.addSelectors([stylesheet]);
61 },
62
63 load: function(callback)
64 {
65 ext.backgroundPage.sendMessage(
66 {
67 type: "filters.get",
68 what: "cssproperties"
69 },
70 function(patterns)
71 {
72 this.patterns = patterns;
73 callback();
74 }.bind(this)
75 );
76 },
77
78 apply: function()
79 {
80 if (this.patterns.length > 0)
81 {
82 var document = this.window.document;
83 this.addSelectors(document.styleSheets);
84 document.addEventListener("load", this.onLoad.bind(this), true);
85 }
86 }
87 };
OLDNEW
« no previous file with comments | « no previous file | chrome/content/ui/subscriptions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld