播放优化

播放页面 “<”后退秒 “>”前进面 “↑”“↓”调节音量 直接点击数字键就可以调节倍速 (输入数字 1.5 就是 1.5倍)

// ==UserScript==
// @name         播放优化
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  播放页面 “<”后退秒  “>”前进面  “↑”“↓”调节音量   直接点击数字键就可以调节倍速 (输入数字 1.5 就是 1.5倍)


// @author       You
// @match        *://*/*
// @match        *:///*/*
// @icon         https://www.nunuyy3.org/favicon.ico
// @grant        none
// @license      ***
// ==/UserScript==

(function video_tool() {
    'use strict';
    var videos = document.getElementsByTagName('video');
    var video = videos[0];
    var load_count = 10;
    var playbackRate ='';

    var i = 0;

    if(video){
        console.log('video.src',videos.length,video.src , video.src=='');
        while(i<videos.length && video.src==''){
            console.log('video.src',video.src , video.src=='');
            video = videos[i++];
            console.log('video.src',video.src , video.src=='');
        }
    }

    function setPlaybackRate(){
        console.log(playbackRate)
        if(playbackRate>0){
            console.log(playbackRate,video)

            if(isNaN(playbackRate)){
                playbackRate = 1
            }
            video.playbackRate = playbackRate;
        }
        playbackRate = '';
    }
    function loadvideo(){

        if(video && video.src!=''){
            console.log('video',video);
            if(video.paused ==false ){

                video.addEventListener("pause", function(){
                    console.log('video stoped and wait video play');
                    window.setTimeout(video_tool,1000);
                });

                document.onkeydown=function(e){
                    console.log(e.keyCode);
                    if(!isNaN(e.key) || e.keyCode == 110 /* '.'*/ ){
                        playbackRate += e.key;
                        setTimeout(setPlaybackRate,500);
                    }else{
                        if(e.keyCode==188){
                            video.currentTime = video.currentTime - 5;
                        }
                        if(e.keyCode==190){
                            console.log(video);
                            console.log(video.currentTime= video.currentTime + 5 );
                        }
                        if(e.keyCode==38){
                            video.volume = video.volume - 5;
                        }
                        if(e.keyCode==40){
                            video.volume= video.volume + 5;
                        }
                        /*  //全屏
                if(e.keyCode==70){
                    var element = document.documentElement;
                    if(element.requestFullScreen) {
                        element.requestFullScreen();
                    } else if(element.mozRequestFullScreen) {
                        element.mozRequestFullScreen();
                    } else if(element.webkitRequestFullScreen) {
                        element.webkitRequestFullScreen();
                    }
                }*/
                    }
                }
            }else{
                console.log('wait video');
                window.setTimeout(video_tool,1000);
            }
        }else{
            console.log('wait video');
            window.setTimeout(video_tool,1000);
        }
    }
    loadvideo();
})();