Greasy Fork

Greasy Fork is available in English.

GYAO キーコントロール SCRIPT Version 2

try to take over the world!

目前为 2022-11-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         GYAO キーコントロール SCRIPT Version 2
// @namespace    None
// @version      2.0
// @description  try to take over the world!
// @author       ouninnoran
// @match        https://gyao.yahoo.co.jp/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=yahoo.co.jp
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var button = {
        foucs:[86,false],
        playB:[37,false],
        playF:[39,false],
        rateB:[37,true],
        rateF:[39,true],
        volP:[38,false],
        volM:[40,false]
    }
    var rotate = 100
    var checkTime = 3000 / rotate
    var buttonS = [".vjs-setting-container-playback-rate",".vjs-setting-container-buttons"]
    var selectRate = ".is-selected"
    var audioval = 0.1; // 音声 1未満
    var BFval = 5; // 動画飛ばし
    var LSs = "gyao.player.speed"
    var pb = [-1,1]
    var timeout = [0,rotate]
    var max_retry = [0,100]
    function keydisable(e){
        e.preventDefault()
    }
    function isfocus(){
        var v = document.querySelector("Video")
        if(!v)return false
        if(document.activeElement != v)return false
        return true
    }
    function videoControler(c){
        var v = document.querySelector("Video")
        var d = 0
        if(!isfocus())return false
        if(c == "F")d = BFval
        if(c == "B")d = BFval * -1
        v.currentTime += d
        var vc = v.currentTime
        console.log(String((vc / 3600).toFixed()) + ":" + String((vc / 60 % 60).toFixed()) + ":" + String((vc % 60).toFixed()))
    }
    function audioControl(c){
        var v = document.querySelector("video")
        var a = 0
        if(!isfocus())return false
        if(c=="P")a = audioval
        if(c=="M")a = audioval * -1
        var va = v.volume + a
        if(va > 1.0)va = 1.0
        else if(va < 0.0)va = 0.0
        va = va.toFixed(1)
        v.volume = va
    }
    function videofocus(){
        var v = document.querySelector("video")
        if(!v)return false
        console.log("focus")
        v.focus()
    }
    function clickRate(c,n=[,]){
        if(!isfocus() && c != "WL")return false
        var key = document.querySelector(n[0]).querySelectorAll(n[1])
        if(key.length == 0) return false
        if(c == "F") pb[1] = ( pb[1] + 1 ) % key.length;
        if(c == "B") pb[1]--;
        if(pb[1] < 0) pb[1] = pb[0] + pb[1]
        var k = pb[1]
        if(c == "WL"){
            if(LSs in window.localStorage)k = Number(window.localStorage[LSs])
        }
        window.localStorage[LSs] = k
        console.log(['speed',k,key[k].getAttribute("data-value")])
        key[k].click()
    }
    function loadkey(n=["","",""]){
        var knull = document.querySelector(n[0])
        if(knull == null){
            setTimeout(function(){loadkey(buttonS)},checkTime)
            return false
        }
        var key = document.querySelector(n[0]).querySelectorAll(n[1])
        var video = document.querySelector("video")
        timeout[0]++;
        if(video != null && key.length>0){
            pb[0] = key.length
            var e = null
            window.addEventListener( "keydown" , function(e){
                var b = [e.keyCode,e.shiftKey]
                if(b[1] == true){
                    switch(b[0]){
                        case button.rateB[0]:e.preventDefault();clickRate("B",buttonS);break;
                        case button.rateF[0]:e.preventDefault();clickRate("F",buttonS);break;
                        case button.volP[0]:e.preventDefault();audioControl("P");break;
                        case button.volM[0]:e.preventDefault();audioControl("M");break;
                    }
                }
                else{
                    switch(b[0]){
                        case button.foucs[0]:e.preventDefault();videofocus();break;
                        case button.playB[0]:e.preventDefault();videoControler("B");break;
                        case button.playF[0]:e.preventDefault();videoControler("F");break;
                    }
                }
            })
        }
        else if(timeout[0]>timeout[1]){console.log("time out is limit set of video cache");return false}
        else setTimeout(function(){loadkey(buttonS)},checkTime)
    }
    setTimeout(function(){loadkey(buttonS)},checkTime)
    function StartVideo(){
        var v = document.querySelector("video")
        if(v == null)setTimeout(StartVideo,checkTime)
        else if(!v.played)setTimeout(StartVideo,checkTime)
        else if(v.played.length == 0)setTimeout(StartVideo,checkTime)
        else clickRate("WL",buttonS)
        if(max_retry[0]>max_retry[1])console.log('this page is video none')
    }
    window.addEventListener('load',function(){
        StartVideo()
    })

    // Your code here...
})();