Greasy Fork

Greasy Fork is available in English.

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

Gyao shortcut key control script

当前为 2022-11-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         GYAO キーコントロール SCRIPT Version 2
// @namespace    http://tampermonkey.net/
// @version      2.0.1
// @description  Gyao shortcut key control script
// @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,false],
        playB:[37,false,false],
        playF:[39,false,false],
        rateB:[37,true,false],
        rateF:[39,true,false],
        volP:[38,false,false],
        volM:[40,false,false],
        play0:[37,false,true],
        play100:[39,false,true]
    }
    var rotate = 100
    var checkTime = 3000 / rotate
    var buttonS = [".vjs-setting-container-playback-rate",".vjs-setting-container-buttons"]
    var scriptionItem = [
        "container-video-grid-item-sidebar",//target element class name
        "Gyao-keyControl-Scription",//place element zone
        [//texts
            "",
        ]
    ]
    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")
        console.log([document.activeElement == v,document.activeElement,v])
        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
        var time = v.currentTime
        if(c == "F")d = time + (BFval)
        if(c == "B")d = time + (BFval * -1)
        if(c == "0")d = 0
        if(c == "100")d = v.duration
        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)
        console.log(va)
        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=["","",""]){
        console.log([n,timeout[0]])
        var knull = document.querySelector(n[0])
        timeout[0]++;
        if(timeout[0] > timeout[1]){console.log("out");return false}
        if(knull == null){
            setTimeout(function(){loadkey(buttonS)},checkTime)
            return false
        }
        var key = document.querySelector(n[0]).querySelectorAll(n[1])
        var video = document.querySelector("video")
        if(video != null && key.length>0){
            console.log(key)
            pb[0] = key.length
            var e = null
            window.addEventListener( "keydown" , function(e){
                var b = [e.keyCode,e.shiftKey,e.ctrlKey]
                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 if(b[2] == true){
                    switch(b[0]){
                        case button.play0[0]:e.preventDefault();videoControler("0");break;
                        case button.play100[0]:e.preventDefault();videoControler("100");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 setTimeout(function(){loadkey(buttonS)},checkTime)
    }
    setTimeout(function(){loadkey(buttonS)},checkTime)
    function StartVideo(){
        var v = document.querySelector("video")
        if(v == null)setTimeout(StartVideo,checkTime*10)
        else if(!v.played)setTimeout(StartVideo,checkTime*10)
        else if(v.played.length == 0)setTimeout(StartVideo,checkTime*10)
        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...
})();