| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2016 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 var usingContentBlockerAPI = true; | |
| 23 try | |
| 24 { | |
| 25 if (ext.backgroundPage.sendMessageSync({type: "prefs.get", | |
| 26 key: "safariContentBlocker"}) != tru
e) | |
| 27 usingContentBlockerAPI = false; | |
| 28 } | |
| 29 catch (e) | |
| 30 { | |
| 31 } | |
| 32 | |
| 33 if (usingContentBlockerAPI) | |
| 34 return; | |
| 35 | |
| 36 if (ext.backgroundPage.sendMessageSync({type: "filters.isPageWhitelisted"})) | |
| 37 return; | |
| 38 | |
| 39 var badArgumentsRegex = /^((.*_)?(ad|ads|afv|adsense)(_.*)?|(ad3|st)_module|pr
erolls|interstitial|infringe|iv_cta_url)$/; | |
| 40 | |
| 41 function rewriteFlashvars(flashvars) | |
| 42 { | |
| 43 var pairs = flashvars.split("&"); | |
| 44 for (var i = 0; i < pairs.length; i++) | |
| 45 if (badArgumentsRegex.test(pairs[i].split("=")[0])) | |
| 46 pairs.splice(i--, 1); | |
| 47 return pairs.join("&"); | |
| 48 } | |
| 49 | |
| 50 function patchPlayer(player) | |
| 51 { | |
| 52 var newPlayer = player.cloneNode(true); | |
| 53 var flashvarsChanged = false; | |
| 54 | |
| 55 var flashvars = newPlayer.getAttribute("flashvars"); | |
| 56 if (flashvars) | |
| 57 { | |
| 58 var newFlashvars = rewriteFlashvars(flashvars); | |
| 59 if (flashvars != newFlashvars) | |
| 60 { | |
| 61 newPlayer.setAttribute("flashvars", newFlashvars); | |
| 62 flashvarsChanged = true; | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 var param = newPlayer.querySelector("param[name=flashvars]"); | |
| 67 if (param) | |
| 68 { | |
| 69 var value = param.getAttribute("value"); | |
| 70 if (value) | |
| 71 { | |
| 72 var newValue = rewriteFlashvars(value); | |
| 73 if (value != newValue) | |
| 74 { | |
| 75 param.setAttribute("value", newValue); | |
| 76 flashvarsChanged = true; | |
| 77 } | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 if (flashvarsChanged) | |
| 82 player.parentNode.replaceChild(newPlayer, player); | |
| 83 } | |
| 84 | |
| 85 document.addEventListener("beforeload", function(event) | |
| 86 { | |
| 87 if ((event.target.localName == "object" || event.target.localName == "embed"
) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) | |
| 88 patchPlayer(event.target); | |
| 89 }, true); | |
| 90 | |
| 91 runInPageContext(function(badArgumentsRegexSource) | |
| 92 { | |
| 93 var badArgumentsRegex = new RegExp(badArgumentsRegexSource); | |
| 94 | |
| 95 // If history.pushState is available, YouTube uses the history API | |
| 96 // when navigation from one video to another, and tells the flash | |
| 97 // player with JavaScript which video and which ads to show next, | |
| 98 // bypassing our flashvars rewrite code. So we disable | |
| 99 // history.pushState before YouTube's JavaScript runs. | |
| 100 if (typeof History != "undefined") | |
| 101 History.prototype.pushState = undefined; | |
| 102 | |
| 103 // The HTML5 player is configured via ytplayer.config.args. We have | |
| 104 // to make sure that ad-related arguments are ignored as they are set. | |
| 105 var ytplayer = undefined; | |
| 106 Object.defineProperty(window, "ytplayer", | |
| 107 { | |
| 108 configurable: true, | |
| 109 get: function() | |
| 110 { | |
| 111 return ytplayer; | |
| 112 }, | |
| 113 set: function(rawYtplayer) | |
| 114 { | |
| 115 if (!rawYtplayer || typeof rawYtplayer != "object") | |
| 116 { | |
| 117 ytplayer = rawYtplayer; | |
| 118 return; | |
| 119 } | |
| 120 | |
| 121 var config = undefined; | |
| 122 ytplayer = Object.create(rawYtplayer, { | |
| 123 config: { | |
| 124 enumerable: true, | |
| 125 get: function() | |
| 126 { | |
| 127 return config; | |
| 128 }, | |
| 129 set: function(rawConfig) | |
| 130 { | |
| 131 if (!rawConfig || typeof rawConfig != "object") | |
| 132 { | |
| 133 config = rawConfig; | |
| 134 return; | |
| 135 } | |
| 136 | |
| 137 var args = undefined; | |
| 138 config = Object.create(rawConfig, { | |
| 139 args: { | |
| 140 enumerable: true, | |
| 141 get: function() | |
| 142 { | |
| 143 return args; | |
| 144 }, | |
| 145 set: function(rawArgs) | |
| 146 { | |
| 147 if (!rawArgs || typeof rawArgs != "object") | |
| 148 { | |
| 149 args = rawArgs; | |
| 150 return; | |
| 151 } | |
| 152 | |
| 153 args = {}; | |
| 154 for (var arg in rawArgs) | |
| 155 { | |
| 156 if (!badArgumentsRegex.test(arg)) | |
| 157 args[arg] = rawArgs[arg]; | |
| 158 } | |
| 159 } | |
| 160 } | |
| 161 }); | |
| 162 | |
| 163 config.args = rawConfig.args; | |
| 164 } | |
| 165 } | |
| 166 }); | |
| 167 | |
| 168 ytplayer.config = rawYtplayer.config; | |
| 169 } | |
| 170 }); | |
| 171 }, badArgumentsRegex.source); | |
| 172 })(); | |
| OLD | NEW |