c4r / dnvod

// ==UserScript==
// @name         dnvod
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  多瑙视频 网页全屏 添加音量调节
// @author       c4r
// @match        https://www.dnvod.tv/play*
// @grant        none
// @require      https://code.jquery.com/jquery-latest.js
// @license      MPL-2.0
// ==/UserScript==

(function() {
    'use strict';


    $( document ).ready(function() {

        console.log("====start====")
        let vWidth = $("#video_player").width();
        let vHeight = $("#video_player").height();



        // hide add
        $("div.player-left").hide();
        $("div.player-right").hide();

        let strVol='<input id="vol-control" type="range" min="0" max="100" step="1" ></input>'

        function resize(){
            // console.log("===resize=====")
            let w = $(window).width();
            let h = $(window).height()-$("div.top-nav").height()*2;
            let dWidth = 0
            let dHeight = 0

            if(vHeight/vWidth*w < h){

                dWidth = w;
                dHeight = vHeight/vWidth*w;
            }else{
                dWidth = vWidth/vHeight*h;
                dHeight = h;
            }



            // console.log(dWidth, dHeight)
            $("div.video-player").parent().width(dWidth)
            $("div.video-player").parent().height(dHeight)
            $("div.video-player").width(dWidth*0.9);
            $("div.video-player").height(dHeight*0.9);
            $("div.video-box").width( dWidth*0.9);
            $("div.video-box").height(dHeight*0.9);
            $("#video_player").width( dWidth*0.9);
            $("#video_player").height(dHeight*0.9);

            if($('#vol-control').length == 0){

                $('vg-mute').after(strVol)
            }


        }

        // expand video
        resize()
        window.onresize = ()=>{
            setTimeout(() => {
                resize()
            }, 100);

        }


    })

    function SetVolume(val)
    {
        // console.log("====vol===")
        let player = document.getElementById('video_player');
        // console.log($("#video_player"))
        // console.log('Before: ' + player.volume);
        player.volume = val / 100;
        // console.log('After: ' + player.volume);
    }

    $(document).on('input', '#vol-control', function () {
        // console.log("=======input=========")
        SetVolume(this.value)
    })
    $(document).on('change', '#vol-control', function (v) {
        // console.log("=======change=========")
        SetVolume(this.value)
    })
})();