Index: safari/include.youtube.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/safari/include.youtube.js |
@@ -0,0 +1,91 @@ |
+/* |
+ * This file is part of Adblock Plus <http://adblockplus.org/>, |
+ * Copyright (C) 2006-2013 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+(function() { |
+ if (document.domain != "www.youtube.com") |
+ return; |
+ |
+ function rewriteFlashvars(flashvars) |
+ { |
+ var pairs = flashvars.split("&"); |
+ for (var i = 0; i < pairs.length; i++) |
+ if (/^((ad|afv|adsense|iv)(_.*)?|(ad3|iv3|st)_module|prerolls|interstitial|infringe|invideo)=/.test(pairs[i])) |
+ pairs.splice(i--, 1); |
+ return pairs.join("&"); |
+ } |
+ |
+ function patchPlayer(player) |
+ { |
+ var newPlayer = player.cloneNode(true); |
+ var flashvarsChanged = false; |
+ |
+ var flashvars = newPlayer.getAttribute("flashvars"); |
+ if (flashvars) |
+ { |
+ var newFlashvars = rewriteFlashvars(flashvars); |
+ if (flashvars != newFlashvars) |
+ { |
+ newPlayer.setAttribute("flashvars", newFlashvars); |
+ flashvarsChanged = true; |
+ } |
+ } |
+ |
+ var param = newPlayer.querySelector("param[name=flashvars]"); |
+ if (param) |
+ { |
+ var value = param.getAttribute("value"); |
+ if (value) |
+ { |
+ var newValue = rewriteFlashvars(value); |
+ if (value != newValue) |
+ { |
+ param.setAttribute("value", newValue); |
+ flashvarsChanged = true; |
+ } |
+ } |
+ } |
+ |
+ if (flashvarsChanged) |
+ player.parentNode.replaceChild(newPlayer, player); |
+ } |
+ |
+ var deferred = []; |
+ function patchPlayerDeferred(player) |
+ { |
+ deferred.push(player); |
+ } |
+ |
+ var onBeforeLoadYoutubeVideo = patchPlayerDeferred; |
+ function onBeforeLoad(event) |
+ { |
+ if ((event.target.localName == "object" || event.target.localName == "embed") && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) |
+ onBeforeLoadYoutubeVideo(event.target); |
+ } |
+ |
+ ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(response) |
+ { |
+ if (response.enabled) |
+ { |
+ deferred.forEach(patchPlayer); |
+ onBeforeLoadYoutubeVideo = patchPlayer; |
+ } |
+ else |
+ document.removeEventListener("beforeload", onBeforeLoad); |
+ }); |
+ |
+ document.addEventListener("beforeload", onBeforeLoad, true); |
+})(); |