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

Delta Between Two Patch Sets: safari/include.youtube.js

Issue 4663448277352448: Disable history API on YouTube in order to block ads in subsequent videos (Closed)
Left Patch Set: Made pushStateDisabled a local variable Created Feb. 24, 2014, 12:25 p.m.
Right Patch Set: Addressed comments Created Feb. 24, 2014, 2:26 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 (function() { 18 (function() {
19 if (document.domain != "www.youtube.com") 19 if (document.domain != "www.youtube.com")
20 return; 20 return;
21
22 var pushStateDisabled = false;
23 21
24 function rewriteFlashvars(flashvars) 22 function rewriteFlashvars(flashvars)
25 { 23 {
26 var pairs = flashvars.split("&"); 24 var pairs = flashvars.split("&");
27 for (var i = 0; i < pairs.length; i++) 25 for (var i = 0; i < pairs.length; i++)
28 if (/^((ad|afv|adsense|iv)(_.*)?|(ad3|iv3|st)_module|prerolls|interstitial |infringe|invideo)=/.test(pairs[i])) 26 if (/^((ad|afv|adsense|iv)(_.*)?|(ad3|iv3|st)_module|prerolls|interstitial |infringe|invideo)=/.test(pairs[i]))
29 pairs.splice(i--, 1); 27 pairs.splice(i--, 1);
30 return pairs.join("&"); 28 return pairs.join("&");
31 } 29 }
32 30
(...skipping 29 matching lines...) Expand all
62 } 60 }
63 61
64 if (flashvarsChanged) 62 if (flashvarsChanged)
65 player.parentNode.replaceChild(newPlayer, player); 63 player.parentNode.replaceChild(newPlayer, player);
66 64
67 // if history.pushState is available, YouTube uses the history API 65 // if history.pushState is available, YouTube uses the history API
68 // when navigation from one video to another, and tells the flash 66 // when navigation from one video to another, and tells the flash
69 // player with JavaScript which video and which ads to show next, 67 // player with JavaScript which video and which ads to show next,
70 // bypassing our flashvars rewrite code. So we disable 68 // bypassing our flashvars rewrite code. So we disable
71 // history.pushState on pages with YouTube's flash player. 69 // history.pushState on pages with YouTube's flash player.
72 if (!pushStateDisabled) 70 document.location.href = "javascript:void(history.pushState = undefined);";
73 {
74 var script = document.createElement("script");
75 script.type = "application/javascript";
76 script.textContent = "history.pushState = undefined;";
77 document.documentElement.appendChild(script);
78
79 pushStateDisabled = true;
80 }
81 } 71 }
82 72
83 var deferred = []; 73 var deferred = [];
84 function patchPlayerDeferred(player) 74 function patchPlayerDeferred(player)
85 { 75 {
86 deferred.push(player); 76 deferred.push(player);
87 } 77 }
88 78
89 var onBeforeLoadYoutubeVideo = patchPlayerDeferred; 79 var onBeforeLoadYoutubeVideo = patchPlayerDeferred;
90 function onBeforeLoad(event) 80 function onBeforeLoad(event)
91 { 81 {
92 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) 82 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url))
93 onBeforeLoadYoutubeVideo(event.target); 83 onBeforeLoadYoutubeVideo(event.target);
94 } 84 }
95 85
96 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re sponse) 86 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re sponse)
97 { 87 {
98 if (response.enabled) 88 if (response.enabled)
99 { 89 {
100 deferred.forEach(patchPlayer); 90 deferred.forEach(patchPlayer);
101 onBeforeLoadYoutubeVideo = patchPlayer; 91 onBeforeLoadYoutubeVideo = patchPlayer;
102 } 92 }
103 else 93 else
104 document.removeEventListener("beforeload", onBeforeLoad); 94 document.removeEventListener("beforeload", onBeforeLoad);
105 }); 95 });
106 96
107 document.addEventListener("beforeload", onBeforeLoad, true); 97 document.addEventListener("beforeload", onBeforeLoad, true);
108 })(); 98 })();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld