Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: safari/include.youtube.js

Issue 4922142982406144: Implemented blocking of YouTube video ads, by rewriting flashvars, for Safari (Closed)
Patch Set: Created Nov. 28, 2013, 5:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« metadata.common ('K') | « safari/ext/content.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 function rewriteFlashvars(flashvars)
20 {
21 var pairs = flashvars.split("&");
22 for (var i = 0; i < pairs.length; i++)
23 if (/^((ad|afv|adsense|iv)(_.*)?|(ad3|iv3|st)_module|prerolls|interstitial |infringe|invideo)=/.test(pairs[i]))
24 pairs.splice(i--, 1);
25 return pairs.join("&");
26 }
27
28 function patchPlayer(player)
29 {
30 var newPlayer = player.cloneNode(true);
31 var flashvarsChanged = false;
32
33 var flashvars = newPlayer.getAttribute("flashvars");
34 if (flashvars)
35 {
36 var newFlashvars = rewriteFlashvars(flashvars);
37 if (flashvars != newFlashvars)
38 {
39 newPlayer.setAttribute("flashvars", newFlashvars);
40 flashvarsChanged = true;
41 }
42 }
43
44 var param = newPlayer.querySelector("param[name=flashvars]");
45 if (param)
46 {
47 var value = param.getAttribute("value");
48 if (value)
49 {
50 var newValue = rewriteFlashvars(value);
51 if (value != newValue)
52 {
53 param.setAttribute("value", newValue);
54 flashvarsChanged = true;
55 }
56 }
57 }
58
59 if (flashvarsChanged)
60 player.parentNode.replaceChild(newPlayer, player);
61 }
62
63 var deferred = [];
64 function patchPlayerDeferred(player)
65 {
66 deferred.push(player);
67 }
68
69 var onBeforeLoadYoutubeVideo = patchPlayerDeferred;
70 function onBeforeLoad(event)
71 {
72 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url))
73 onBeforeLoadYoutubeVideo(event.target);
74 }
75
76 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re sponse)
77 {
78 if (response.enabled)
79 {
80 deferred.forEach(patchPlayer);
81 onBeforeLoadYoutubeVideo = patchPlayer;
82 }
83 else
84 document.removeEventListener("beforeload", onBeforeLoad);
85 });
Wladimir Palant 2013/12/06 10:58:35 This code was meant for Chrome where synchronous m
Sebastian Noack 2013/12/10 18:51:35 We only use synchronous messaging under the hood i
86
87 document.addEventListener("beforeload", onBeforeLoad, true);
Wladimir Palant 2013/12/06 10:58:35 Adding this listener on non-YouTube websites is to
Sebastian Noack 2013/12/06 11:32:33 I assumed that YouTube videos embedded on other we
Wladimir Palant 2013/12/06 11:38:10 There are two ways to embed YouTube video: 1) The
Sebastian Noack 2013/12/20 09:23:46 Done.
88 })();
OLDNEW
« metadata.common ('K') | « safari/ext/content.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld