Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 CSSPropertyFilters = { | |
2 stringifyStyle: function(style) | |
3 { | |
4 var styles = []; | |
5 for (var i = 0; i < style.length; i++) | |
6 { | |
7 var property = style.item(i); | |
8 var value = style.getPropertyValue(property); | |
9 var priority = style.getPropertyPriority(property); | |
10 styles.push(property + ": " + value + (priority ? " !" + priority : "") + ";"); | |
11 } | |
12 styles.sort(); | |
13 return styles.join(" "); | |
14 }, | |
15 | |
16 findSelectors: function(stylesheet, selectors) | |
17 { | |
18 var rules = stylesheet.cssRules; | |
19 if (!rules) | |
20 return; | |
21 | |
22 for (var i = 0; i < rules.length; i++) | |
23 { | |
24 var rule = rules[i]; | |
25 if (rule.type != CSSRule.STYLE_RULE) | |
26 continue; | |
27 | |
28 var style = this.stringifyStyle(rule.style); | |
29 for (var j = 0; j < this.patterns.length; j++) | |
30 { | |
31 var pattern = this.patterns[j]; | |
32 var regexp = pattern.regexp; | |
33 | |
34 if (typeof regexp == "string") | |
35 regexp = pattern.regexp = new RegExp(regexp); | |
Wladimir Palant
2015/10/23 18:36:37
What about invalid regexps? new RegExp() can throw
Sebastian Noack
2015/10/23 20:49:31
The regular expression is generated by our code. S
| |
36 | |
37 if (regexp.test(style)) | |
38 selectors.push(pattern.prefix + rule.selectorText + pattern.suffix); | |
39 } | |
40 } | |
41 }, | |
42 | |
43 addSelectors: function(stylesheets) | |
44 { | |
45 var selectors = []; | |
46 for (var i = 0; i < stylesheets.length; i++) | |
47 this.findSelectors(stylesheets[i], selectors); | |
48 addElemHideSelectors(selectors); | |
49 }, | |
50 | |
51 onLoad: function(event) | |
52 { | |
53 var stylesheet = event.target.sheet; | |
54 if (stylesheet) | |
55 CSSPropertyFilters.addSelectors([stylesheet]); | |
56 }, | |
57 | |
58 load: function(callback) | |
59 { | |
60 ext.backgroundPage.sendMessage( | |
61 { | |
62 type: "filters.get", | |
63 what: "cssproperties" | |
64 }, | |
65 function(patterns) | |
66 { | |
67 this.patterns = patterns; | |
68 callback(); | |
69 }.bind(this) | |
70 ); | |
71 }, | |
72 | |
73 apply: function() | |
74 { | |
75 if (patterns.length > 0) | |
76 { | |
77 this.addSelectors(document.styleSheets); | |
78 document.addEventListener("load", this.onLoad, true); | |
Wladimir Palant
2015/10/23 18:36:36
Are you sure that the "load" event is being trigge
Sebastian Noack
2015/10/23 20:49:31
Seems so. Tested using https://pastebin.mozilla.or
| |
79 } | |
80 }, | |
81 | |
82 init: function() | |
83 { | |
84 this.load(this.apply.bind(this)); | |
85 } | |
86 }; | |
87 | |
88 CSSPropertyFilters.init(); | |
Wladimir Palant
2015/10/23 18:36:37
As I said earlier, CSSPropertyFilters should ideal
Sebastian Noack
2015/10/23 20:49:31
I've added the check. Do we have to use a construc
Wladimir Palant
2015/10/23 21:04:40
In Firefox there will be more than one window/docu
Sebastian Noack
2015/10/23 21:23:22
Gotya.
| |
OLD | NEW |