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

Unified Diff: safari/include.youtube.js

Issue 4757413714460672: Issue 1259 - Block while checking whether ABP is disabled on YouTube on Safari (Closed)
Patch Set: Created Aug. 22, 2014, 1:59 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 | « safari/ext/content.js ('k') | 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,9 @@
if (document.domain != "www.youtube.com")
return;
+ if (!ext.backgroundPage.sendMessageSync({type: "get-domain-enabled-state"}).enabled)
+ return;
+
function rewriteFlashvars(flashvars)
{
var pairs = flashvars.split("&");
@@ -63,31 +66,11 @@
player.parentNode.replaceChild(newPlayer, player);
}
- var deferred = [];
- function patchPlayerDeferred(player)
- {
- deferred.push(player);
- }
-
- var onBeforeLoadYoutubeVideo = patchPlayerDeferred;
- function onBeforeLoad(event)
+ document.addEventListener("beforeload", function(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, true);
- });
-
- document.addEventListener("beforeload", onBeforeLoad, true);
+ patchPlayer(event.target);
+ }, true);
// if history.pushState is available, YouTube uses the history API
// when navigation from one video to another, and tells the flash
« no previous file with comments | « safari/ext/content.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld