動畫瘋逐幀切換

try to take over the world!

目前为 2019-10-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         動畫瘋逐幀切換
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       axzxc1236
// @match        https://ani.gamer.com.tw/animeVideo.php?sn=*
// @grant        unsafeWindow
// @require https://code.jquery.com/jquery-3.4.1.slim.min.js#md5=220afd743d9e9643852e31a135a9f3ae,sha256=0925e8ad7bd971391a8b1e98be8e87a6971919eb5b60c196485941c3c1df089a
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012#md5=fd6775a03daee426e576e1394ab2a3b4,sha256=e582c20607e3e723a2e2437ca0546570b1531bf302d4a89cbd99964ccd73e995
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    const frametime = 1/24;

    waitForKeyElements("#ani_video", vid => {
        const video = videojs(document.querySelector("#ani_video"));
        document.addEventListener("keypress", event => {
            let char = event.which || event.keyCode;
            if (char == 44 || char == 60) { //, or <
                if (video.currentTime() > frametime) {
                    video.pause(true);
                    video.currentTime(video.currentTime()-frametime);
                } else {
                    console.error("<error> video playtime is less than a frame");
                }

            } else if (char == 46 || char == 62) { //. or >
                if (video.remainingTime() > frametime) {
                    video.pause(true);
                    video.currentTime(video.currentTime()+frametime);
                } else {
                    console.error("<error> You are playing the last frame of video.");
                }
            } else console.log("<debug> pressed " + event.keyCode);
        })
    }, true);

})();