OLD | NEW |
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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 60 } |
61 | 61 |
62 if (flashvarsChanged) | 62 if (flashvarsChanged) |
63 player.parentNode.replaceChild(newPlayer, player); | 63 player.parentNode.replaceChild(newPlayer, player); |
64 | 64 |
65 // if history.pushState is available, YouTube uses the history API | 65 // if history.pushState is available, YouTube uses the history API |
66 // when navigation from one video to another, and tells the flash | 66 // when navigation from one video to another, and tells the flash |
67 // player with JavaScript which video and which ads to show next, | 67 // player with JavaScript which video and which ads to show next, |
68 // bypassing our flashvars rewrite code. So we disable | 68 // bypassing our flashvars rewrite code. So we disable |
69 // history.pushState on pages with YouTube's flash player. | 69 // history.pushState on pages with YouTube's flash player. |
70 document.location.href = "javascript:void(history.pushState = undefined);"; | 70 var script = document.createElement("script"); |
| 71 script.type = "application/javascript"; |
| 72 script.async = false; |
| 73 script.textContent = "history.pushState = undefined;"; |
| 74 document.documentElement.appendChild(script); |
| 75 document.documentElement.removeChild(script); |
71 } | 76 } |
72 | 77 |
73 var deferred = []; | 78 var deferred = []; |
74 function patchPlayerDeferred(player) | 79 function patchPlayerDeferred(player) |
75 { | 80 { |
76 deferred.push(player); | 81 deferred.push(player); |
77 } | 82 } |
78 | 83 |
79 var onBeforeLoadYoutubeVideo = patchPlayerDeferred; | 84 var onBeforeLoadYoutubeVideo = patchPlayerDeferred; |
80 function onBeforeLoad(event) | 85 function onBeforeLoad(event) |
81 { | 86 { |
82 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) | 87 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) |
83 onBeforeLoadYoutubeVideo(event.target); | 88 onBeforeLoadYoutubeVideo(event.target); |
84 } | 89 } |
85 | 90 |
86 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re
sponse) | 91 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re
sponse) |
87 { | 92 { |
88 if (response.enabled) | 93 if (response.enabled) |
89 { | 94 { |
90 deferred.forEach(patchPlayer); | 95 deferred.forEach(patchPlayer); |
91 onBeforeLoadYoutubeVideo = patchPlayer; | 96 onBeforeLoadYoutubeVideo = patchPlayer; |
92 } | 97 } |
93 else | 98 else |
94 document.removeEventListener("beforeload", onBeforeLoad); | 99 document.removeEventListener("beforeload", onBeforeLoad); |
95 }); | 100 }); |
96 | 101 |
97 document.addEventListener("beforeload", onBeforeLoad, true); | 102 document.addEventListener("beforeload", onBeforeLoad, true); |
98 })(); | 103 })(); |
OLD | NEW |