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

Delta Between Two Patch Sets: chrome/content/cssProperties.js

Issue 29317059: Issue 2395 - Added content script for CSS property filters (Closed)
Left Patch Set: Turned namespace into a class with configurable window object Created Oct. 23, 2015, 9:21 p.m.
Right Patch Set: Make function to add CSS selectors configurable in the constructor Created Nov. 13, 2015, 1:16 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 function CSSPropertyFilters(window) { 1 function CSSPropertyFilters(window, addSelectorsFunc) {
2 this.window = window; 2 this.window = window;
3 this.addSelectorsFunc = addSelectorsFunc;
3 this.load(this.apply.bind(this)); 4 this.load(this.apply.bind(this));
4 } 5 }
5 6
6 CSSPropertyFilters.prototype = { 7 CSSPropertyFilters.prototype = {
7 stringifyStyle: function(style) 8 stringifyStyle: function(style)
8 { 9 {
9 var styles = []; 10 var styles = [];
10 for (var i = 0; i < style.length; i++) 11 for (var i = 0; i < style.length; i++)
11 { 12 {
12 var property = style.item(i); 13 var property = style.item(i);
(...skipping 17 matching lines...) Expand all
30 if (rule.type != this.window.CSSRule.STYLE_RULE) 31 if (rule.type != this.window.CSSRule.STYLE_RULE)
31 continue; 32 continue;
32 33
33 var style = this.stringifyStyle(rule.style); 34 var style = this.stringifyStyle(rule.style);
34 for (var j = 0; j < this.patterns.length; j++) 35 for (var j = 0; j < this.patterns.length; j++)
35 { 36 {
36 var pattern = this.patterns[j]; 37 var pattern = this.patterns[j];
37 var regexp = pattern.regexp; 38 var regexp = pattern.regexp;
38 39
39 if (typeof regexp == "string") 40 if (typeof regexp == "string")
40 regexp = pattern.regexp = new this.window.RegExp(regexp); 41 regexp = pattern.regexp = new RegExp(regexp);
41 42
42 if (regexp.test(style)) 43 if (regexp.test(style))
43 selectors.push(pattern.prefix + rule.selectorText + pattern.suffix); 44 selectors.push(pattern.prefix + rule.selectorText + pattern.suffix);
44 } 45 }
45 } 46 }
46 }, 47 },
47 48
48 addSelectors: function(stylesheets) 49 addSelectors: function(stylesheets)
49 { 50 {
50 var selectors = []; 51 var selectors = [];
51 for (var i = 0; i < stylesheets.length; i++) 52 for (var i = 0; i < stylesheets.length; i++)
52 this.findSelectors(stylesheets[i], selectors); 53 this.findSelectors(stylesheets[i], selectors);
53 addElemHideSelectors(selectors); 54 this.addSelectorsFunc(selectors);
54 }, 55 },
55 56
56 onLoad: function(event) 57 onLoad: function(event)
57 { 58 {
58 var stylesheet = event.target.sheet; 59 var stylesheet = event.target.sheet;
59 if (stylesheet) 60 if (stylesheet)
60 this.addSelectors([stylesheet]); 61 this.addSelectors([stylesheet]);
61 }, 62 },
62 63
63 load: function(callback) 64 load: function(callback)
64 { 65 {
65 ext.backgroundPage.sendMessage( 66 ext.backgroundPage.sendMessage(
66 { 67 {
67 type: "filters.get", 68 type: "filters.get",
68 what: "cssproperties" 69 what: "cssproperties"
69 }, 70 },
70 function(patterns) 71 function(patterns)
71 { 72 {
72 this.patterns = patterns; 73 this.patterns = patterns;
73 callback(); 74 callback();
74 }.bind(this) 75 }.bind(this)
75 ); 76 );
76 }, 77 },
77 78
78 apply: function() 79 apply: function()
79 { 80 {
80 if (patterns.length > 0) 81 if (this.patterns.length > 0)
81 { 82 {
82 var document = this.window.document; 83 var document = this.window.document;
83 this.addSelectors(document.styleSheets); 84 this.addSelectors(document.styleSheets);
84 document.addEventListener("load", this.onLoad.bind(this), true); 85 document.addEventListener("load", this.onLoad.bind(this), true);
85 } 86 }
86 } 87 }
87 }; 88 };
88
89 if (typeof window == "object")
90 new CSSPropertyFilters(window);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld