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

Unified Diff: safari/include.youtube.js

Issue 4663448277352448: Disable history API on YouTube in order to block ads in subsequent videos (Closed)
Patch Set: Made pushStateDisabled a local variable Created Feb. 24, 2014, 12:25 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/include.youtube.js
===================================================================
--- a/safari/include.youtube.js
+++ b/safari/include.youtube.js
@@ -19,6 +19,8 @@
if (document.domain != "www.youtube.com")
return;
+ var pushStateDisabled = false;
+
function rewriteFlashvars(flashvars)
{
var pairs = flashvars.split("&");
@@ -61,6 +63,21 @@
if (flashvarsChanged)
player.parentNode.replaceChild(newPlayer, player);
+
+ // if history.pushState is available, YouTube uses the history API
+ // when navigation from one video to another, and tells the flash
+ // player with JavaScript which video and which ads to show next,
+ // bypassing our flashvars rewrite code. So we disable
+ // history.pushState on pages with YouTube's flash player.
+ if (!pushStateDisabled)
+ {
+ var script = document.createElement("script");
+ script.type = "application/javascript";
+ script.textContent = "history.pushState = undefined;";
+ document.documentElement.appendChild(script);
+
+ pushStateDisabled = true;
+ }
}
var deferred = [];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld