| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 findSelectors: function(stylesheet, selectors) | 59 isSameOrigin: function(stylesheet) |
| 60 { | 60 { |
| 61 try | 61 try |
|
Sebastian Noack
2016/04/19 14:47:01
I guess we should move this logic to a seperate fu
Wladimir Palant
2016/04/19 15:07:42
Done.
| |
| 62 { | 62 { |
| 63 // Explicitly ignore third-party stylesheets to ensure consistent behavior | 63 return new URL(stylesheet.href).origin == this.window.location.origin; |
| 64 // between Firefox and Chrome. | |
| 65 if (stylesheet.href && | |
|
Sebastian Noack
2016/04/19 14:47:01
This check seems to be redundant as we catch the e
Wladimir Palant
2016/04/19 15:07:42
I don't really like intentionally running into exc
| |
| 66 new URL(stylesheet.href).origin != this.window.location.origin) | |
| 67 { | |
|
Sebastian Noack
2016/04/19 14:47:01
Nit: Redundant braces.
Wladimir Palant
2016/04/19 15:07:42
Not redundant, actually required for readability s
| |
| 68 return; | |
| 69 } | |
| 70 } | 64 } |
| 71 catch (e) | 65 catch (e) |
| 72 { | 66 { |
| 73 // An invalid URL, can be ignored. | 67 // Invalid URL, assume that it is first-party. |
| 68 return true; | |
| 74 } | 69 } |
| 70 }, | |
| 71 | |
| 72 findSelectors: function(stylesheet, selectors) | |
| 73 { | |
| 74 // Explicitly ignore third-party stylesheets to ensure consistent behavior | |
| 75 // between Firefox and Chrome. | |
| 76 if (!this.isSameOrigin(stylesheet)) | |
| 77 return; | |
| 75 | 78 |
| 76 var rules = stylesheet.cssRules; | 79 var rules = stylesheet.cssRules; |
| 77 if (!rules) | 80 if (!rules) |
| 78 return; | 81 return; |
| 79 | 82 |
| 80 for (var i = 0; i < rules.length; i++) | 83 for (var i = 0; i < rules.length; i++) |
| 81 { | 84 { |
| 82 var rule = rules[i]; | 85 var rule = rules[i]; |
| 83 if (rule.type != rule.STYLE_RULE) | 86 if (rule.type != rule.STYLE_RULE) |
| 84 continue; | 87 continue; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 apply: function() | 138 apply: function() |
| 136 { | 139 { |
| 137 if (this.patterns.length > 0) | 140 if (this.patterns.length > 0) |
| 138 { | 141 { |
| 139 var document = this.window.document; | 142 var document = this.window.document; |
| 140 this.addSelectors(document.styleSheets); | 143 this.addSelectors(document.styleSheets); |
| 141 document.addEventListener("load", this.onLoad.bind(this), true); | 144 document.addEventListener("load", this.onLoad.bind(this), true); |
| 142 } | 145 } |
| 143 } | 146 } |
| 144 }; | 147 }; |
| LEFT | RIGHT |