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-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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 (function() { | 18 (function() { |
19 if (document.domain != "www.youtube.com") | 19 if (document.domain != "www.youtube.com") |
20 return; | 20 return; |
21 | 21 |
| 22 if (!ext.backgroundPage.sendMessageSync({type: "get-domain-enabled-state"}).en
abled) |
| 23 return; |
| 24 |
22 function rewriteFlashvars(flashvars) | 25 function rewriteFlashvars(flashvars) |
23 { | 26 { |
24 var pairs = flashvars.split("&"); | 27 var pairs = flashvars.split("&"); |
25 for (var i = 0; i < pairs.length; i++) | 28 for (var i = 0; i < pairs.length; i++) |
26 if (/^((ad|afv|adsense)(_.*)?|(ad3|st)_module|prerolls|interstitial|infrin
ge|iv_cta_url)=/.test(pairs[i])) | 29 if (/^((ad|afv|adsense)(_.*)?|(ad3|st)_module|prerolls|interstitial|infrin
ge|iv_cta_url)=/.test(pairs[i])) |
27 pairs.splice(i--, 1); | 30 pairs.splice(i--, 1); |
28 return pairs.join("&"); | 31 return pairs.join("&"); |
29 } | 32 } |
30 | 33 |
31 function patchPlayer(player) | 34 function patchPlayer(player) |
(...skipping 24 matching lines...) Expand all Loading... |
56 param.setAttribute("value", newValue); | 59 param.setAttribute("value", newValue); |
57 flashvarsChanged = true; | 60 flashvarsChanged = true; |
58 } | 61 } |
59 } | 62 } |
60 } | 63 } |
61 | 64 |
62 if (flashvarsChanged) | 65 if (flashvarsChanged) |
63 player.parentNode.replaceChild(newPlayer, player); | 66 player.parentNode.replaceChild(newPlayer, player); |
64 } | 67 } |
65 | 68 |
66 var deferred = []; | 69 document.addEventListener("beforeload", function(event) |
67 function patchPlayerDeferred(player) | |
68 { | |
69 deferred.push(player); | |
70 } | |
71 | |
72 var onBeforeLoadYoutubeVideo = patchPlayerDeferred; | |
73 function onBeforeLoad(event) | |
74 { | 70 { |
75 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) | 71 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) |
76 onBeforeLoadYoutubeVideo(event.target); | 72 patchPlayer(event.target); |
77 } | 73 }, true); |
78 | |
79 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re
sponse) | |
80 { | |
81 if (response.enabled) | |
82 { | |
83 deferred.forEach(patchPlayer); | |
84 onBeforeLoadYoutubeVideo = patchPlayer; | |
85 } | |
86 else | |
87 document.removeEventListener("beforeload", onBeforeLoad, true); | |
88 }); | |
89 | |
90 document.addEventListener("beforeload", onBeforeLoad, true); | |
91 | 74 |
92 // if history.pushState is available, YouTube uses the history API | 75 // if history.pushState is available, YouTube uses the history API |
93 // when navigation from one video to another, and tells the flash | 76 // when navigation from one video to another, and tells the flash |
94 // player with JavaScript which video and which ads to show next, | 77 // player with JavaScript which video and which ads to show next, |
95 // bypassing our flashvars rewrite code. So we disable | 78 // bypassing our flashvars rewrite code. So we disable |
96 // history.pushState before YouTube's JavaScript runs. | 79 // history.pushState before YouTube's JavaScript runs. |
97 var script = document.createElement("script"); | 80 var script = document.createElement("script"); |
98 script.type = "application/javascript"; | 81 script.type = "application/javascript"; |
99 script.async = false; | 82 script.async = false; |
100 script.textContent = "History.prototype.pushState = undefined;"; | 83 script.textContent = "History.prototype.pushState = undefined;"; |
101 document.documentElement.appendChild(script); | 84 document.documentElement.appendChild(script); |
102 document.documentElement.removeChild(script); | 85 document.documentElement.removeChild(script); |
103 })(); | 86 })(); |
OLD | NEW |