Greasy Fork

Video Fast Forward/Rewind with Arrow Keys

Use right and left arrow keys to fast forward or rewind HTML video

目前为 2024-03-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         Video Fast Forward/Rewind with Arrow Keys
// @version      1
// @description  Use right and left arrow keys to fast forward or rewind HTML video
// @author       pb
// @grant        none
// @match https://www.jiocinema.com/*
// @match https://www.sonyliv.com/*
// @namespace https://gist.github.com/prashantbaid/314139311b151964f81bceb2c48fec50
// @license MIT
// ==/UserScript==

(function() {
  document.body.onkeydown = e => {
        //do not interfere with navigating jio in-video slider
        if (isJioSlickSlider(e)) {
            return;
        }

        const videos = document.getElementsByTagName('video');

        console.log('videos ', videos);

        if (videos.length > 0) {
            const video = videos[0];

            const seek = time => {
                e.stopImmediatePropagation();
                video.currentTime += time;
            }

            switch (e.key) {
                case 'ArrowRight':
                    seek(10);
                    break;
                case 'ArrowLeft':
                    seek(-10);
                    break;
                default:
                    break;
            }
        }
    }
})();

const isJioSlickSlider = e => {
    return e.target.className.toLowerCase().includes('slick-');
}