I'm trying to trigger an event in an extension when a video ends on youtube.com.
I couldn't find any examples from other extensions.
What I tried so far:
EDIT: I injected the script just like here: https://stackoverflow.com/a/9310273/4279201
Now with the injection, the alert('test')
does show up so the injection works up to that point. But then nothing happens, any ideas why?
//script.js file
alert('test');
function onPlayerStateChange(event) {
if(event.data === YT.PlayerState.ENDED) {
alert('done');
}
}
Or:
//script.js file
alert('test');
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player( 'player', {
events: { 'onStateChange': onPlayerStateChange }
});
}
function onPlayerStateChange(event) {
if(event.data === YT.PlayerState.ENDED) {
alert('done');
}
}
The event constant is from: https://developers.google.com/youtube/js_api_reference?csw=1#Events
My manifest file: http://chopapp.com/#j89brn5f, bk.js
is empty, cnt.js
is just like in the script injection link. script.js
is above.