(function () { console.log("HELLO FROM PLAYLIST!", Math.floor(Math.random() * 999)); function msgPlayEvt(type, target) { const payload = { type, url: window.location.href, timestamp: target.currentTime, duration: target.duration, title: document.title.replace(/ - YouTube$/, ""), }; return browser.runtime.sendMessage(payload); } const vid = document.querySelector("video"); if (vid) { vid.addEventListener("play", function (evt) { msgPlayEvt("play", evt.target); console.log("NOW PLAYING (msg here for test)"); }); vid.addEventListener("playing", function (evt) { msgPlayEvt("playing", evt.target); console.log("playing... (msg here for test)"); }); vid.addEventListener("pause", function (evt) { msgPlayEvt("pause", evt.target); console.log("paused (msg here for test)"); }); vid.addEventListener("ended", function (evt) { msgPlayEvt("ended", evt.target); console.log("ON TO THE NEXT ONE! ...but not yet."); setTimeout(async function () { // const msg = { // type: "requestNext", // //currentVideo: 'something', // //currentList: 'something' // }; // const resp = await chrome.runtime.sendMessage(msg); // console.log("NAVIGATING?", resp); // if( resp.goto ) { // console.log("NAVIGATING to", resp.goto); // window.location = resp.goto; // console.log("AFTER?"); // } //TODO: MOVE "NEXT" REQUEST TO BACKGROUND SCRIPT // (background script will determine if this tab is playing a playlist) msgPlayEvt("next", evt.target); }, 3000); }); console.log("ATTACHED!"); } // Listen for messages from the popup or background script browser.runtime.onMessage.addListener((message) => { console.log("MESSAGE", message); if (message.type === "print") { console.log(message); return Promise.resolve({ status: "Injection completed" }); } }); })();