Created
July 21, 2015 01:35
-
-
Save MeoMix/e4f5c9f2d0c94fb1bc79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the port needed to communicate with the parent extension. | |
this.initializePort = function() { | |
this.port = chrome.runtime.connect({ | |
name: 'youTubeIFrameConnectRequest' | |
}); | |
// The extension can request the *exact* time of YouTube's video player. | |
// Respond with that value, but also include a timestamp to account for the time it takes to send the postMessage. | |
this.port.onMessage.addListener(function(message) { | |
if (message === 'getCurrentTimeHighPrecision') { | |
var currentTime = this.videoStream === null ? 0 : this.videoStream.currentTime; | |
this.port.postMessage({ | |
timestamp: performance.now(), | |
currentTimeHighPrecision: currentTime | |
}); | |
} | |
}.bind(this)); | |
}.bind(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment