OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 (function() { |
| 19 if (document.domain != "www.youtube.com") |
| 20 return; |
| 21 |
| 22 function rewriteFlashvars(flashvars) |
| 23 { |
| 24 var pairs = flashvars.split("&"); |
| 25 for (var i = 0; i < pairs.length; i++) |
| 26 if (/^((ad|afv|adsense|iv)(_.*)?|(ad3|iv3|st)_module|prerolls|interstitial
|infringe|invideo)=/.test(pairs[i])) |
| 27 pairs.splice(i--, 1); |
| 28 return pairs.join("&"); |
| 29 } |
| 30 |
| 31 function patchPlayer(player) |
| 32 { |
| 33 var newPlayer = player.cloneNode(true); |
| 34 var flashvarsChanged = false; |
| 35 |
| 36 var flashvars = newPlayer.getAttribute("flashvars"); |
| 37 if (flashvars) |
| 38 { |
| 39 var newFlashvars = rewriteFlashvars(flashvars); |
| 40 if (flashvars != newFlashvars) |
| 41 { |
| 42 newPlayer.setAttribute("flashvars", newFlashvars); |
| 43 flashvarsChanged = true; |
| 44 } |
| 45 } |
| 46 |
| 47 var param = newPlayer.querySelector("param[name=flashvars]"); |
| 48 if (param) |
| 49 { |
| 50 var value = param.getAttribute("value"); |
| 51 if (value) |
| 52 { |
| 53 var newValue = rewriteFlashvars(value); |
| 54 if (value != newValue) |
| 55 { |
| 56 param.setAttribute("value", newValue); |
| 57 flashvarsChanged = true; |
| 58 } |
| 59 } |
| 60 } |
| 61 |
| 62 if (flashvarsChanged) |
| 63 player.parentNode.replaceChild(newPlayer, player); |
| 64 } |
| 65 |
| 66 var deferred = []; |
| 67 function patchPlayerDeferred(player) |
| 68 { |
| 69 deferred.push(player); |
| 70 } |
| 71 |
| 72 var onBeforeLoadYoutubeVideo = patchPlayerDeferred; |
| 73 function onBeforeLoad(event) |
| 74 { |
| 75 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) |
| 76 onBeforeLoadYoutubeVideo(event.target); |
| 77 } |
| 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); |
| 88 }); |
| 89 |
| 90 document.addEventListener("beforeload", onBeforeLoad, true); |
| 91 })(); |
OLD | NEW |