saisai9321 / 优酷HTML5替换

// ==UserScript==
// @name         优酷HTML5替换
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *://v.youku.com/v_show/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    /**
     * Created by chen on 2017/4/28.
     */
//优酷网执行脚本
    if(String(location.origin).indexOf('youku')>-1){
        //获取vid /v_show/id_XMjczMzE1MzI0NA==.html
        var _pathName=location.pathname||"",
            _ccVid=_pathName.match(/id_(\S*).html/)[1],
            ts=String((new Date()).getTime()).substring(0,9);


        var _ccTimer=setInterval(function(){
            var _ykPlayer=document.getElementById('player');
            if(_ykPlayer){
                _ykPlayer.parentNode.removeChild(_ykPlayer);
                _$ccJsonp("https://ups.youku.com/ups/get.json?vid="+_ccVid+"&ccode=0501&client_ip=0.0.0.0&client_ts="+ts+"&utid=o0ZrEYwXMhACAXLdfEiRtUIE");
                clearInterval(_ccTimer);
            }
        },100);
        setTimeout(function(){
            clearInterval(_ccTimer);
        },15000);
    }





//jsnop请求
    function _$ccJsonp(url){
        window.jsonpCallback=function(res){
            insertVideo(chooseSrc(res.data.stream||[]));
        };
        var _script=document.createElement('script');
        _script.type = "application/javascript";
        _script.src = url+'&callback=jsonpCallback';

        document.getElementsByTagName('head')[0].appendChild(_script);
    }
//筛选MP4地址
    function chooseSrc(list){
        var maxMp4={};
        list.forEach(function(one){
            var oneSegs=one.segs||[];
            oneSegs.forEach(function(_segs){
                if(String(_segs.cdn_url).indexOf('mp4')>-1){
                    if(!(_segs.size<maxMp4.size)){
                        maxMp4=_segs;
                    }
                }
            });
        });
        return maxMp4.cdn_url;
    }

//获取MP4链接
    function insertVideo(src){
        var _video=document.createElement('video'),
            _ykPlayerContainer=document.getElementById('module_basic_player');
        if(_ykPlayerContainer){
            _video.src=src;
            _video.style.width="100%";
            _video.style.height="100%";
            _video.controls=true;
            _ykPlayerContainer.appendChild(_video);
        }
    }
    // Your code here...
})();