OleVod Multimedia

A script to allow olevod site adapt multimedia key to next or previous episode

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         OleVod Multimedia
// @namespace    http://tampermonkey.net/
// @version      0.2.2
// @description  A script to allow olevod site adapt multimedia key to next or previous episode
// @author       You
// @match        *://*.olevod.me/*
// @match        *://*.olevod.com/*
// @match        *://*.olehdtv.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=olevod.me
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js
// @grant        GM_xmlhttpRequest
// @license      MIT
// ==/UserScript==
/* global $ */

(function() {
    console.log = function() {};
    console.clear = function() {};
    console.info("tzwei connected");

    'use strict';

    const toggleFullscreen = (videoElement) => {
        const methods = [
            'requestFullscreen',
            'mozRequestFullScreen',
            'webkitRequestFullscreen',
            'msRequestFullscreen'
        ];
        for (const method of methods) {
            if (videoElement[method]) {
                videoElement[method]();
                break;
            }
        }
    };

    const exitFullscreen = () => {
        if (document.fullscreenElement && document.exitFullscreen) {
            document.exitFullscreen();
            parent.focus();
        }
    };

    const seekForward = (sec) => {
        const iframeElement = document.querySelector('iframe[name="pif"]');
        const videoElement = getVideoElement();
        if (videoElement) {
            videoElement.currentTime += sec;
        }
    };

    const getVideoElement = () => {
        const iframeElement = document.querySelector('iframe[name="pif"]');
        let videoElement = iframeElement?.contentDocument?.querySelector("video");
        if (!videoElement) {
            videoElement = document.querySelector("video");
        }
        return videoElement;
    };

    const handleSkipIntro = () => {
        const skipIntroLink = $("<a href='javascript:void(0)'>跳过片头&nbsp;<i class='iconfont skip-intro'></i></a>");
        $("div.play_but.bline > ul > li").append(skipIntroLink);
        skipIntroLink.on("click", () => seekForward(70));
    };

    const handleKeyEvents = () => {
        document.addEventListener("keydown", (event) => {
            const videoElement = getVideoElement();

            if (videoElement) {
                if (event.key === 'f' || event.keyCode === 70) {
                    toggleFullscreen(videoElement);
                }
            }

            if (event.keyCode === 176 || event.keyCode === 187) {
                exitFullscreen();
                parent.$(".next-t").click();
            }

            if (event.keyCode === 177 || event.keyCode === 189) {
                exitFullscreen();
                parent.$(".pre-t").click();
            }

            if (event.keyCode === 221) {
                exitFullscreen();
                parent.$(".skip-intro").click();
            }
        });
    };

    // Call your functions to initialize the script
    handleSkipIntro();
    handleKeyEvents();
})();