OLD | NEW |
1 function splitSelector(selector) | 1 function splitSelector(selector) |
2 { | 2 { |
3 if (selector.indexOf(",") == -1) | 3 if (selector.indexOf(",") == -1) |
4 return [selector]; | 4 return [selector]; |
5 | 5 |
6 var selectors = []; | 6 var selectors = []; |
7 var start = 0; | 7 var start = 0; |
8 var level = 0; | 8 var level = 0; |
9 var sep = ""; | 9 var sep = ""; |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 { | 49 { |
50 var property = style.item(i); | 50 var property = style.item(i); |
51 var value = style.getPropertyValue(property); | 51 var value = style.getPropertyValue(property); |
52 var priority = style.getPropertyPriority(property); | 52 var priority = style.getPropertyPriority(property); |
53 styles.push(property + ": " + value + (priority ? " !" + priority : "") +
";"); | 53 styles.push(property + ": " + value + (priority ? " !" + priority : "") +
";"); |
54 } | 54 } |
55 styles.sort(); | 55 styles.sort(); |
56 return styles.join(" "); | 56 return styles.join(" "); |
57 }, | 57 }, |
58 | 58 |
| 59 isSameOrigin: function(stylesheet) |
| 60 { |
| 61 try |
| 62 { |
| 63 return new URL(stylesheet.href).origin == this.window.location.origin; |
| 64 } |
| 65 catch (e) |
| 66 { |
| 67 // Invalid URL, assume that it is first-party. |
| 68 return true; |
| 69 } |
| 70 }, |
| 71 |
59 findSelectors: function(stylesheet, selectors) | 72 findSelectors: function(stylesheet, selectors) |
60 { | 73 { |
| 74 // Explicitly ignore third-party stylesheets to ensure consistent behavior |
| 75 // between Firefox and Chrome. |
| 76 if (!this.isSameOrigin(stylesheet)) |
| 77 return; |
| 78 |
61 var rules = stylesheet.cssRules; | 79 var rules = stylesheet.cssRules; |
62 if (!rules) | 80 if (!rules) |
63 return; | 81 return; |
64 | 82 |
65 for (var i = 0; i < rules.length; i++) | 83 for (var i = 0; i < rules.length; i++) |
66 { | 84 { |
67 var rule = rules[i]; | 85 var rule = rules[i]; |
68 if (rule.type != rule.STYLE_RULE) | 86 if (rule.type != rule.STYLE_RULE) |
69 continue; | 87 continue; |
70 | 88 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 apply: function() | 138 apply: function() |
121 { | 139 { |
122 if (this.patterns.length > 0) | 140 if (this.patterns.length > 0) |
123 { | 141 { |
124 var document = this.window.document; | 142 var document = this.window.document; |
125 this.addSelectors(document.styleSheets); | 143 this.addSelectors(document.styleSheets); |
126 document.addEventListener("load", this.onLoad.bind(this), true); | 144 document.addEventListener("load", this.onLoad.bind(this), true); |
127 } | 145 } |
128 } | 146 } |
129 }; | 147 }; |
OLD | NEW |