OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 param.setAttribute("value", newValue); | 79 param.setAttribute("value", newValue); |
80 flashvarsChanged = true; | 80 flashvarsChanged = true; |
81 } | 81 } |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 if (flashvarsChanged) | 85 if (flashvarsChanged) |
86 player.parentNode.replaceChild(newPlayer, player); | 86 player.parentNode.replaceChild(newPlayer, player); |
87 } | 87 } |
88 | 88 |
89 function runInPage(fn, arg) | |
90 { | |
91 var script = document.createElement("script"); | |
92 script.type = "application/javascript"; | |
93 script.async = false; | |
94 script.textContent = "(" + fn + ")(" + arg + ");"; | |
95 document.documentElement.appendChild(script); | |
96 document.documentElement.removeChild(script); | |
97 } | |
98 | |
99 document.addEventListener("beforeload", function(event) | 89 document.addEventListener("beforeload", function(event) |
100 { | 90 { |
101 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) | 91 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) |
102 patchPlayer(event.target); | 92 patchPlayer(event.target); |
103 }, true); | 93 }, true); |
104 | 94 |
105 runInPage(function(badArgumentsRegex) | 95 runInPage(function(badArgumentsRegexSource) |
106 { | 96 { |
| 97 var badArgumentsRegex = new RegExp(badArgumentsRegexSource); |
| 98 |
107 // If history.pushState is available, YouTube uses the history API | 99 // If history.pushState is available, YouTube uses the history API |
108 // when navigation from one video to another, and tells the flash | 100 // when navigation from one video to another, and tells the flash |
109 // player with JavaScript which video and which ads to show next, | 101 // player with JavaScript which video and which ads to show next, |
110 // bypassing our flashvars rewrite code. So we disable | 102 // bypassing our flashvars rewrite code. So we disable |
111 // history.pushState before YouTube's JavaScript runs. | 103 // history.pushState before YouTube's JavaScript runs. |
112 History.prototype.pushState = undefined; | 104 History.prototype.pushState = undefined; |
113 | 105 |
114 // The HTML5 player is configured via ytplayer.config.args. We have | 106 // The HTML5 player is configured via ytplayer.config.args. We have |
115 // to make sure that ad-related arguments are ignored as they are set. | 107 // to make sure that ad-related arguments are ignored as they are set. |
116 var ytplayer = undefined; | 108 var ytplayer = undefined; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 }); | 164 }); |
173 | 165 |
174 config.args = rawConfig.args; | 166 config.args = rawConfig.args; |
175 } | 167 } |
176 } | 168 } |
177 }); | 169 }); |
178 | 170 |
179 ytplayer.config = rawYtplayer.config; | 171 ytplayer.config = rawYtplayer.config; |
180 } | 172 } |
181 }); | 173 }); |
182 }, badArgumentsRegex); | 174 }, badArgumentsRegex.source); |
183 })(); | 175 })(); |
OLD | NEW |