私は最初の Chrome 拡張機能を作成するための最初のステップを作成していますが、YoutubePlayer からのイベントをインターセプトする際にいくつか問題があります。拡張機能は content_scripts タイプの拡張機能です。私の js ファイルでは、イベント ハンドラーを YoutubePlayer の "onStateChange" イベントにアタッチしています。コードはそのように見えます
var playerLoaded = ( document.getElementById("movie_player") == null ), intervalId;
var attachEvents = function(){
var currentVideo =document.getElementById("movie_player");
if(currentVideo){
currentVideo.addEventListener("onStateChange", "onytplayerStateChange");
if(intervalId)
clearInterval(intervalId);
}
}
function onytplayerStateChange() {
alert("Player's new state: " + newState);
};
if(!playerLoaded){
debugger;
intervalId = setInterval(attachEvents,100);
} else{
debugger;
attachEvents();
}
残念ながら、唯一の tplayerStateChange 関数が起動されません。理由を知っている人はいますか?