html5 video speed controller (vlc like) modified by Sapioit

Simple html5 video speed control with 's', 'd', and 'r'. 's': decrease by 0.25, 'd': increase by 0.25, 'r': back to 1.0x

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        html5 video speed controller (vlc like) modified by Sapioit
// @namespace   github.com/sky-bro
// @version     1.1.0.0
// @description Simple html5 video speed control with 's', 'd', and 'r'. 's': decrease by 0.25, 'd': increase by 0.25, 'r': back to 1.0x
// @author      https://sky-bro.github.io      https://sapioit.com
// @match       https://www.youtube.com/*
// @match       https://www.bilibili.com/*
// @match       *://*.zhihuishu.com/*
// @license     GPL-2.0-only; http://www.gnu.org/licenses/gpl-2.0.txt
// @grant       none
// ==/UserScript==

(function() {
    'use strict';
    function setPlaybackRate(player, rate) {
        if (rate < 0.1) rate = 0.1;
        else if (rate > 40) rate = 40;
        player.playbackRate = rate;
        console.log("playing in %sx", (rate).toFixed(1));
    }

    window.addEventListener('keypress', function(event) {
        var player = document.querySelector("video");
        // console.log(event);
        var curRate = Number(player.playbackRate);
        // vlc actually uses '[' and ']', but they are used by vimium
        if (event.key == "s") {
            console.log("s pressed");
            setPlaybackRate(player, curRate - 0.25);
        } else if(event.key == "d") {
            console.log("d pressed");
            setPlaybackRate(player, curRate + 0.25);
        } else if(event.key == "r") {
            console.log("r pressed");
            setPlaybackRate(player, 1);
        }
    });
})();