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

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

Issue 5088751004942336: Issue 370 - Right-clicked element is removed independent of created filter (Closed)
Patch Set: Rebase to rev 3c9cea80c481 Created July 18, 2014, 8:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « safari/icons/abp-32-notification-information.png ('k') | skin/popup.css » ('j') | 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-2014 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)(_.*)?|(ad3|st)_module|prerolls|interstitial|infrin ge|iv_cta_url)=/.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, true);
88 });
89
90 document.addEventListener("beforeload", onBeforeLoad, true);
91
92 // if history.pushState is available, YouTube uses the history API
93 // when navigation from one video to another, and tells the flash
94 // player with JavaScript which video and which ads to show next,
95 // bypassing our flashvars rewrite code. So we disable
96 // history.pushState before YouTube's JavaScript runs.
97 var script = document.createElement("script");
98 script.type = "application/javascript";
99 script.async = false;
100 script.textContent = "History.prototype.pushState = undefined;";
101 document.documentElement.appendChild(script);
102 document.documentElement.removeChild(script);
103 })();
OLDNEW
« no previous file with comments | « safari/icons/abp-32-notification-information.png ('k') | skin/popup.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld