| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 } | 79 } |
| 80 | 80 |
| 81 document.addEventListener("beforeload", function(event) | 81 document.addEventListener("beforeload", function(event) |
| 82 { | 82 { |
| 83 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) | 83 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) |
| 84 patchPlayer(event.target); | 84 patchPlayer(event.target); |
| 85 }, true); | 85 }, true); |
| 86 | 86 |
| 87 runInPage(function(badArgumentsRegex) | 87 runInPage(function(badArgumentsRegex) |
| 88 { | 88 { |
| 89 // if history.pushState is available, YouTube uses the history API | 89 // If history.pushState is available, YouTube uses the history API |
| 90 // when navigation from one video to another, and tells the flash | 90 // when navigation from one video to another, and tells the flash |
| 91 // player with JavaScript which video and which ads to show next, | 91 // player with JavaScript which video and which ads to show next, |
| 92 // bypassing our flashvars rewrite code. So we disable | 92 // bypassing our flashvars rewrite code. So we disable |
| 93 // history.pushState before YouTube's JavaScript runs. | 93 // history.pushState before YouTube's JavaScript runs. |
| 94 History.prototype.pushState = undefined; | 94 History.prototype.pushState = undefined; |
| 95 | 95 |
| 96 // the HMLT5 player is configured via ytplayer.config.args. We have | 96 // The HTML5 player is configured via ytplayer.config.args. We have |
|
Wladimir Palant
2014/08/28 16:43:38
Nit: "The HTML5 player" (properly capitalized and
Sebastian Noack
2014/08/29 14:51:24
Done.
| |
| 97 // to make sure that ad-related arguments are ignored as they are set. | 97 // to make sure that ad-related arguments are ignored as they are set. |
| 98 var ytplayer = undefined; | 98 var ytplayer = undefined; |
|
Wladimir Palant
2014/08/28 16:43:38
What if ytplayer variable was set already? I'd rec
Sebastian Noack
2014/08/29 14:51:24
This hack only works anyway, if our JavaScript run
| |
| 99 Object.defineProperty(window, "ytplayer", | 99 Object.defineProperty(window, "ytplayer", |
| 100 { | 100 { |
| 101 configurable: true, | |
| 101 get: function() | 102 get: function() |
| 102 { | 103 { |
| 103 return ytplayer; | 104 return ytplayer; |
| 104 }, | 105 }, |
| 105 set: function(rawYtplayer) | 106 set: function(rawYtplayer) |
| 106 { | 107 { |
| 107 if (typeof rawYtplayer != "object") | 108 if (!rawYtplayer || typeof rawYtplayer != "object") |
|
Wladimir Palant
2014/08/28 16:43:38
console.log(typeof null);
This should be:
if (
Sebastian Noack
2014/08/29 14:51:24
Thanks for reminding me that null is an object. I'
| |
| 108 { | 109 { |
| 109 ytplayer = rawYtplayer; | 110 ytplayer = rawYtplayer; |
| 110 return; | 111 return; |
| 111 } | 112 } |
| 112 | 113 |
| 113 var config = undefined; | 114 var config = undefined; |
|
Wladimir Palant
2014/08/28 16:43:38
Here as well: what if the config property is alrea
Sebastian Noack
2014/08/29 14:51:24
This was handled by the loop below:
for (var pr
| |
| 114 ytplayer = { | 115 ytplayer = Object.create(rawYtplayer, { |
| 115 get config() | 116 config: { |
| 116 { | 117 enumerable: true, |
| 117 return config; | 118 get: function() |
| 118 }, | |
| 119 set config(rawConfig) | |
| 120 { | |
| 121 if (typeof rawConfig != "object") | |
|
Wladimir Palant
2014/08/28 16:43:38
Here as well: please consider the possibility that
Sebastian Noack
2014/08/29 14:51:24
Done.
| |
| 122 { | 119 { |
| 123 config = rawConfig; | 120 return config; |
| 124 return; | 121 }, |
| 122 set: function(rawConfig) | |
| 123 { | |
| 124 if (!rawConfig || typeof rawConfig != "object") | |
| 125 { | |
| 126 config = rawConfig; | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 var args = undefined; | |
| 131 config = Object.create(rawConfig, { | |
| 132 args: { | |
| 133 enumerable: true, | |
| 134 get: function() | |
| 135 { | |
| 136 return args; | |
| 137 }, | |
| 138 set: function(rawArgs) | |
| 139 { | |
| 140 if (!rawArgs || typeof rawArgs != "object") | |
| 141 { | |
| 142 args = rawArgs; | |
| 143 return; | |
| 144 } | |
| 145 | |
| 146 args = {}; | |
| 147 for (var arg in rawArgs) | |
| 148 { | |
| 149 if (!badArgumentsRegex.test(arg)) | |
| 150 args[arg] = rawArgs[arg]; | |
| 151 } | |
| 152 } | |
| 153 } | |
| 154 }); | |
| 155 | |
| 156 config.args = rawConfig.args; | |
| 125 } | 157 } |
| 158 } | |
| 159 }); | |
| 126 | 160 |
| 127 var args = undefined; | 161 ytplayer.config = rawYtplayer.config; |
| 128 config = { | 162 } |
| 129 get args() | |
| 130 { | |
| 131 return args; | |
| 132 }, | |
| 133 set args(rawArgs) | |
| 134 { | |
| 135 if (typeof rawArgs != "object") | |
| 136 { | |
| 137 args = rawArgs; | |
| 138 return; | |
| 139 } | |
| 140 | |
| 141 args = {}; | |
| 142 for (var arg in rawArgs) | |
| 143 { | |
| 144 if (!badArgumentsRegex.test(arg)) | |
| 145 args[arg] = rawArgs[arg]; | |
| 146 } | |
| 147 } | |
| 148 }; | |
|
Wladimir Palant
2014/08/28 16:43:38
There is a recurring pattern here: you wrap object
Sebastian Noack
2014/08/29 14:51:24
Of course, I already considered that. However, the
| |
| 149 | |
| 150 for (var prop in rawConfig) | |
| 151 config[prop] = rawConfig[prop]; | |
| 152 } | |
| 153 }; | |
| 154 | |
| 155 for (var prop in rawYtplayer) | |
| 156 ytplayer[prop] = rawYtplayer[prop]; | |
|
Wladimir Palant
2014/08/28 16:43:38
I think that inheriting from rawYtplayer would be
Sebastian Noack
2014/08/29 14:51:24
Done. However, I'm not convinced that it is a bett
| |
| 157 }, | |
| 158 configurable: true | |
| 159 }); | 163 }); |
| 160 }, badArgumentsRegex); | 164 }, badArgumentsRegex); |
| 161 })(); | 165 })(); |
| LEFT | RIGHT |