| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- (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);
- });
- vid.addEventListener("playing", function (evt) {
- msgPlayEvt("playing", evt.target);
- });
- vid.addEventListener("pause", function (evt) {
- msgPlayEvt("pause", evt.target);
- });
- vid.addEventListener("ended", function (evt) {
- msgPlayEvt("ended", evt.target);
- });
- }
- // Listen for messages from the popup or background script
- browser.runtime.onMessage.addListener((message) => {
- if (message.type === "print") {
- console.log("MESSAGE", message);
- }
- if (message.type === "autoplay") {
- console.log('press play');
- const play = document.querySelector(
- 'button.ytp-play-button.ytp-button[data-title-no-tooltip="Play"]',
- );
- if (play) {
- play.click();
- }
- }
- });
- })();
|