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

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

Issue 29317059: Issue 2395 - Added content script for CSS property filters (Closed)
Patch Set: Added missing this. Created Oct. 24, 2015, 6:31 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 | 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
(Empty)
1 function CSSPropertyFilters(window) {
2 this.window = window;
3 this.load(this.apply.bind(this));
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 addElemHideSelectors(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"
kzar 2015/11/02 20:30:56 We need to pass the domain here as well, according
Wladimir Palant 2015/11/05 13:10:04 Actually, I don't think we do - sender.frame.url s
kzar 2015/11/05 14:35:32 OK I've updated the description for #2396 accordin
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 };
88
89 if (typeof window == "object")
90 new CSSPropertyFilters(window);
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