AnimeFLV-auto-skip-Mega-addon

Set video on fullscreen and send data to AnimeFLV addon

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AnimeFLV-auto-skip-Mega-addon
// @namespace    https://grayapps.es/
// @version      0.0.1
// @description  Set video on fullscreen and send data to AnimeFLV addon
// @author       Javiergg
// @match        https://mega.nz/embed/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    console.log("Mega Video Addon running");
    let interval = undefined;

    function logVideoTimes() {
        const video = document.querySelector('video');
        if (video) {
            // Ensure the video is loaded
            video.addEventListener('loadedmetadata', function() {
                if (interval) {
                    clearInterval(interval);
                }
                interval = setInterval(() => {
                    const data = {
                        currentTime: video.currentTime,
                        duration: video.duration
                    };
                    window.parent.postMessage({ type: 'VIDEO_DATA', data: data }, '*');
                }, 1000);

                // Autoplay the video
                video.play().catch(error => {
                    console.log('Autoplay failed:', error);
                });

                // Enter fullscreen mode
                if (video.requestFullscreen) {
                    video.requestFullscreen().catch(error => {
                        console.log('Fullscreen request failed:', error);
                    });
                } else if (video.mozRequestFullScreen) { // Firefox
                    video.mozRequestFullScreen().catch(error => {
                        console.log('Fullscreen request failed:', error);
                    });
                } else if (video.webkitRequestFullscreen) { // Chrome, Safari and Opera
                    video.webkitRequestFullscreen().catch(error => {
                        console.log('Fullscreen request failed:', error);
                    });
                } else if (video.msRequestFullscreen) { // IE/Edge
                    video.msRequestFullscreen().catch(error => {
                        console.log('Fullscreen request failed:', error);
                    });
                }
            });
        } else {
            console.log("No video element found.");
        }
    }

    // Attempt to log times when the DOM is loaded
    window.addEventListener('load', function() {
        logVideoTimes();
    });

    const observer = new MutationObserver(logVideoTimes);
    observer.observe(document.body, { childList: true, subtree: true });
})();