fsteinerhm.edu / Proxer HD Player und Controls

// ==UserScript==
// @name         Proxer HD Player und Controls
// @version      1.09
// @description  Diese Erweiterung fügt den Proxer HD Videos zusätzliche Kontrolloptionen hinzu und ändert den Video Player.
// @author       fraenkthetaenk, WorldSEnder
// @contributor  Dragowynd, Desnoo
// @include      http://stream.proxer.me/*
// @include      https://stream.proxer.me/*
// @run-at       document-end
// ==/UserScript==
 
$(document).ready(function (e) {
    console.log("document.ready start");
    var KEYS = {
        UP: 38,
        DOWN: 40,
        SPACE: 32,
        LEFT: 37,
        RIGHT: 39,
        K: 75,
        L: 76,
        F: 70,
        M: 77,
        T: 84,
        C: 67,
        S: 83,
        B: 66,
        N: 78
    };
    var KEYNAMES = [];
    for(var name in KEYS) {
        KEYNAMES[KEYS[name]] = name;
    }
    var showControls = false;
    var VOLUME_STEP = 0.01;
    var TIME_STEP_SMALL = 5;
    var TIME_STEP_BIG = 85;
    var FORCEHIDE_INTERFACE_CLASS = "hide-controls";
    var BUTTON_DOWN = [];
    BUTTON_DOWN[KEYS.UP] = () => $("#htmlstream_html5_api").prop("volume", (i, val) => Math.min(val + VOLUME_STEP, 1));
    BUTTON_DOWN[KEYS.DOWN] = () => $("#htmlstream_html5_api").prop("volume", (i, val) => Math.max(val - VOLUME_STEP, 0));
 
    var BUTTON_UP = [];
    BUTTON_UP[KEYS.SPACE] = togglePlay;
    BUTTON_UP[KEYS.LEFT] = () => $("#htmlstream_html5_api").prop("currentTime", (i, val) => val -= TIME_STEP_SMALL);
    BUTTON_UP[KEYS.RIGHT] = () => $("#htmlstream_html5_api").prop("currentTime", (i, val) => val += TIME_STEP_SMALL);
    BUTTON_UP[KEYS.K] = () => $("#htmlstream_html5_api").prop("currentTime", (i, val) => val -= TIME_STEP_BIG);
    BUTTON_UP[KEYS.L] = () => $("#htmlstream_html5_api").prop("currentTime", (i, val) => val += TIME_STEP_BIG);
    BUTTON_UP[KEYS.F] = toggleFull;
    BUTTON_UP[KEYS.M] =  () => $("#htmlstream_html5_api").prop("muted", (i, val) => !val);
    BUTTON_UP[KEYS.T] =  function() {
        var videojsvideo = $("#htmlstream_html5_api")[0];
        videojsvideo.pause();
        var time = window.prompt("Which time do you want to skip to (format mm:ss) ?", "00:00");
        videojsvideo.currentTime = time.substring(0,2) * 60 + time.substring(3,5) * 1;
        videojsvideo.play();
    };
    BUTTON_UP[KEYS.C] =  function() {
        showControls = !showControls;
        $(".video-js").toggleClass(FORCEHIDE_INTERFACE_CLASS, showControls);
        $(".vjs-control-bar").css();
    };
    
     BUTTON_UP[KEYS.S] =  function() {
        var videojsvideo = $("#htmlstream_html5_api")[0];
        videojsvideo.pause();
        var rate = window.prompt("Which Speed would you like to watch in? ", "1");
        videojsvideo.playbackRate = rate;
        videojsvideo.play();
    };
      BUTTON_UP[KEYS.N] =  function() {
          console.log(document.getElementsByClassName("menu")[0]);
      };  
        
    BUTTON_UP[KEYS.B] =  function() {
    };
 

   
 
    function loadInlineStyle(styledef) {
        var sheet = document.createElement('style');
        sheet.innerHTML = styledef;
        $(document.head).append(sheet);

    }
   
    function loadStylesheet(url) {
        var style = document.createElement('link');
        style.href = url;
        style.rel = "stylesheet";
        $(document.head).append(style);
    }
 
    function cancelFullScreen(el) {
        var requestMethod = el.cancelFullScreen||el.webkitCancelFullScreen||el.mozCancelFullScreen||el.exitFullscreen;
        if (requestMethod) { // cancel full screen.
            requestMethod.call(el);
        } else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
            var wscript = new ActiveXObject("WScript.Shell");
            if (wscript !== null) {
                wscript.SendKeys("{F11}");
            }
        }
    }
 
    function requestFullScreen(el) {
       
        var requestMethod = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;
 
        if (requestMethod) { // Native full screen.
            requestMethod.call(el);
        }
        $("#htmlstream_html5_api").css({position: "fixed"});
        return false;
    }
 
    function toggleFull() {
        var elem = document.body; // Make the body go full screen.
        var isInFullScreen = (document.fullScreenElement && document.fullScreenElement !== null) ||  (document.mozFullScreen || document.webkitIsFullScreen);
 
        if (isInFullScreen) {
            cancelFullScreen(document);
        } else {
            requestFullScreen(elem);
        }
        return false;
    }
 
    function togglePlay() {
        var videojsvideo = $("#htmlstream_html5_api")[0];
        if (videojsvideo.paused) {
            videojsvideo.play();
        } else {
            videojsvideo.pause();
        }
    }
 
    window.oncontextmenu = function () {
        return true;
    };
 
  


    loadInlineStyle("\
       .video-js {\
           width: 100% !important;\
           height: 100% !important;\
       }\
       .video-js button.vjs-big-play-button {\
           position: absolute;\
           top: 50%;\
           left: 50%;\
           -webkit-transform: translate(-50%, -50%);\
           -ms-transform: translate(-50%, -50%);\
           transform: translate(-50%, -50%);\
       }\
       .video-js.hide-controls .vjs-control-bar {\
           position: fixed !important;\
           backgroundColor: #000;\
           display: none;\
           visibility: invisible;\
           opacity: 0;\
       }\
       .video-js .vjs-control-bar {\
           position: fixed !important;\
           backgroundColor: #000;\
           display: none;\
           visibility: invisible;\
           opacity: 0;\
       }\
       .hide-controls, .vjs-playing.vjs-user-inactive {\
           cursor: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjbQg61aAAAADUlEQVQYV2P4//8/IwAI/QL/+TZZdwAAAABJRU5ErkJggg=='),\
               url(images/blank.cur),\
               none !important;\
       }"
    );
    loadStylesheet("https://vjs.zencdn.net/5.2.4/video-js.css");
 
   
    $(document).keydown(function (e) {
        var func = BUTTON_DOWN[e.which];
        if(func) {
            console.log("keydown " + KEYNAMES[e.which]);
            func();
        }
    });
 
    $(document).keyup(function (e) {
        var func = BUTTON_UP[e.which];
        if(func) {
            console.log("keyup " + KEYNAMES[e.which]);
            func();
        }
    });
   
    console.log("document.ready end");
});

$(window).load(function(){
 srctag = document.getElementsByTagName("video")[0].src;
 if(srctag===''){
srctag = document.getElementsByTagName("source")[0].src;
 }
    console.log(srctag);
   
     function loadScript(url, callback) {
        var head = document.head;
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = url;
        script.onreadystatechange = callback;
        script.onload = callback;
        head.appendChild(script);
       
    }
    loadScript("https://vjs.zencdn.net/5.2.4/video.js", function () {
        var video = document.createElement("video");
        video.setAttribute("id", "htmlstream");
        video.setAttribute("class", "video-js");
        video.setAttribute("data-setup", "{}");
        video.setAttribute("controls", "");
        video.setAttribute("preload", "auto");
        video.setAttribute("width", "50%");
        video.setAttribute("height", "15%");
        video.setAttribute("src", srctag);

        $(video).css({position: "fixed"});
   var oldplayer = $("#player_code");
        oldplayer.replaceWith(video);
 
        videojs("htmlstream").ready(function() {
            var volume = readCookie("videojsvolume");
            var videojsvideo = document.getElementById("htmlstream_html5_api");
            videojsvideo.volume = volume !== "" ? volume : videojsvideo.volume;
            videojsvideo.muted = false;
            var d = new Date();
            d.setTime(d.getTime() + (30*24*60*60*1000));
            var expires = "expires="+d.toUTCString();
            videojsvideo.addEventListener("volumechange", function() { document.cookie="videojsvolume="+ videojsvideo.volume +"; "+ expires;});
        });
    });
    
    
});