Greasy Fork is available in English.

巴哈動漫瘋

取得動漫瘋m3u8檔案,用potplayer觀看,加上很多問題

Fra 2017-02-12 15:05:54 UTC. Se den seneste versjonen.

// ==UserScript==
// @name         巴哈動漫瘋
// @namespace    none
// @version      0.4
// @description  取得動漫瘋m3u8檔案,用potplayer觀看,加上很多問題
// @author       sheepdragon
// @match        http://ani.gamer.com.tw/animeVideo.php?sn=*
// @grant        none
// @icon         https://i2.bahamut.com.tw/anime/baha_s.png
// ==/UserScript==
(function() {
    'use strict';
    // Your code here...
    var snID = animefun.videoSn;
    var deviceID, listSrc, Origin, Words = [],
        Player = [],Info,
        adID, resolution = ['360p', '540p', '720p', '1080p'],
        locked = true,hash;
    $(document).ajaxSuccess(
        function(event, xhr, settings) {
            //settings.url.search("token.php?")>1           
            if (settings.url.match(/ajax\/token\.php\?adID\=\d+&sn\=\d+&device\=[0-9a-z]+&hash\=[0-9a-z]+/) !== null) {
                Info=$.parseJSON(xhr.responseText);
                //console.log(Info);
                let url = settings.url.split('?')[1];
                let get = url.split('&');
                for (let i in get) {
                    let nam = get[i].split('=')[0];
                    let val = get[i].split('=')[1];
                    let has = get[i].split('=')[1];
                    if (nam === 'adID') {
                        adID = val;
                    } else if (nam === 'device') {
                        deviceID = val;
                    }
                    else if(has === 'hash'){
                        hash=has;
                    }
                }
                control();       
            }
        });
    function remove(){
        $('.ncc a').eq(0).click(function() {
            setTimeout(function() {
                $('.vast-blocker').removeAttr('href');
                $('.vast-blocker').removeAttr('target');
                $('.vast-skip-button').attr("href", "#");
                $('.vast-skip-button').removeAttr("target");
                $('#ani_video').removeClass('vjs-ad-playing');
            }, 500);
        });
    }
    let getM3u8s = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'ajax/m3u8.php',
                data: { sn: snID, device: deviceID},
                type: "GET",
                dataType: 'json',
                success: resolve,
                error: reject
            });
        });
    };
    let CastVishu = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'ajax/videoCastcishu.php',
                data: { sn: snID, s: adID },
                type: "GET",
                dataType: 'text',
                success: resolve,
                error: reject
            });
        });
    };
    let token = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'ajax/token.php',
                data: { sn: snID, device: deviceID ,'hash':hash,'adID':adID },
                type: "GET",
                dataType: 'text',
                success: resolve,
                error: reject
            });
        });
    };
    let viblastAD = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'https://licensing.viblast.com/licensing/rest/check/bth44tqf2a?stream=//gamer-cds.cdn.hinet.net/vod/gamer/gamer_ad-' + adID + '/hls-ae-2s/index.m3u8',
                type: "POST",
                dataType: 'json',
                success: resolve,
                error: reject
            });
        });
    };
    let adindex = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'http://gamer-cds.cdn.hinet.net/vod/gamer/gamer_ad-' + adID + '/hls-ae-2s/index.m3u8',
                type: "GET",
                dataType: 'text',
                success: resolve,
                error: reject
            });
        });
    };
    let unlock = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'ajax/unlock.php',
                data: { sn: snID, ttl: 0 },
                type: "GET",
                dataType: 'text',
                success: resolve,
                error: reject
            });
        });
    };
    let checklock = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'ajax/checklock.php',
                data: { device: deviceID, sn: snID },
                type: "GET",
                dataType: 'text',
                success: resolve,
                error: reject
            });
        });
    };
    let CastVishuEnd = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: 'ajax/videoCastcishu.php',
                data: { sn: snID, s: adID, ad: 'end' },
                type: "GET",
                dataType: 'html',
                success: resolve,
                error: reject
            });
        });
    };
    let getM3u8Lists = () => {
        return new Promise(function(resolve, reject) {
            $.ajax({
                url: listSrc,
                type: "GET",
                dataType: 'text',
                success: resolve,
                error: reject
            });
        });
    };

    function control() {
        if(Info.time===1){
            getM3u8s().then(function(msg) {
                if(msg.src.length>0){
                    show('取得getM3u8Lists');
                    listSrc = msg.src;
                    getM3u8Lists().then(function(msg) {
                        Origin=msg.split('\n');
                        if(Origin.length<20){
                            stringPlus();
                            show('成功m3u8');
                            token();
                        }
                    }).catch(function(xhr, ajaxOptions, thrownError) {
                        show('取得getM3u8Lists失敗');
                    });
                }
            }).catch(function(xhr, ajaxOptions, thrownError) {
                show('取得getM3u8s失敗');
            });
        }
        else{
            reGET( true );
        }
    }
    function reGET( lock = false){
        if(lock){
            CastVishu();
        }
        setTimeout(function() {
            checklock();
        },100);
        show('解鎖中...');
        setTimeout(function() {
            CastVishuEnd();
            getM3u8s().then(function(msg) {
                //console.log(msg.src.length);
                if(msg.src.length>0){
                    show('取得getM3u8Lists');
                    listSrc = msg.src;
                    getM3u8Lists().then(function(msg) {
                        Origin=msg.split('\n');
                        if(Origin.length<20){
                            stringPlus();
                            show('成功m3u8');
                        }
                    }).catch(function(xhr, ajaxOptions, thrownError) {
                        show('重新getM3u8Lists失敗');
                    });
                }
                else{
                    show('取得重新失敗');
                    setTimeout(function() {
                        reGET(false);
                    },500);
                }
            }).catch(function(xhr, ajaxOptions, thrownError) {
                show('取得重新getList失敗');
            });
        },2500);

    }
    function show(msg = false) {
        console.log(msg);
        $('#error_msg').remove();
        $('.sub_top').append('<span id="error_msg">' + msg + '</span>');
    }
    function stringPlus() {
        //console.log((Origin.length-3)/2+'種 解析度');
        for (let i in Origin) {
            if (Origin[i].length > 150) {
                Words.push(Origin[i]);
            }
        }
        Core();
    }

    function Core() {
        $('.m3u_bn').remove();
        $('.sub_top').html('<button class="m3u_bn" onclick="$(\'#m3u8\').slideToggle(\'slow\')" >選擇畫質</button>' + $('.sub_top').html());
        $('.sub_top').append('<div id="m3u8"></div>');
        $('#m3u8').append("<div class='m3u_ul'>" + ((Origin.length - 3) / 2) + "種 解析度</div>");
        for (let i in Words) {
            let m3u_name = Words[i].split('-video')[0];
            let m3u_url = Words[i].split('-video=')[1];
            let Link = "http://gamer-cds.cdn.hinet.net/vod/gamer/" + m3u_name + "/hls-ae-2s/" + Words[i];
            Player.push(Link);
            let id = 'link_' + i;
            $('#m3u8').append("<div class='m3u_li' title='點擊後複製' onclick=\"copy('" + Link + "');$('#m3u8').slideToggle('slow');show('複製成功')\">" + (!resolution[i] ? '' : resolution[i]) + "</div>");
        }
    }

    function ShowHide() {
        $('#m3u8').slideToggle("slow", function() {
            // Animation complete.
        });
    }
    $(window).load(function() {
        $('#fb_xdm_frame_https').eq(0).remove();
        $('iframe').eq(1).remove();
        $('.fb_ltr').remove();
        $('#facebook').remove();
        var block = setInterval(function() {
            //document.getElementById('ani_video_html5_api').currentTime+=30;
            if ($('.vast-skip-button').length === 1) {
                $('.vast-blocker').removeAttr('href');
                $('.vast-blocker').removeAttr('target');
                $('.vast-skip-button').attr("href", "#");
                $('.vast-skip-button').removeAttr("target");
                $('#ani_video').removeClass('vjs-ad-playing');
                if ($('.vast-skip-button')[0].text === '點此跳過廣告') {
                    //window.location.reload();
                    clearInterval(block);
                }
            }
        }, 500);
    });
    $('head').append(`
<script>
function copy(str){\
$('body').append('<textarea id=\"temp\">'+ str +'</textarea>');\
$('#temp').select();\
document.execCommand('Copy');\
$('#temp').remove();\}
function show(msg = false) {
$('#error_msg').remove();
$('.sub_top').append('<span id="error_msg">' + msg + '</span>');
}
</script>`);
    $('head').append(`<style>
.m3u_ul{
background: #aaaaaa;
color: #333;
padding-left: 1rem;
}
.m3u_li{
padding-left: 1rem;
background: #ffffff;
transition: .5s;
cursor: pointer;
}
.m3u_li:nth-child(even){
color:#333;
background: #ffffff;
}
.m3u_li:nth-child(odd){
background: #00b4d8;
color:#FFF;
}
.m3u_li:hover{
background: #666666;
color: #FFF;
}
#m3u8{
display:none;
box-shadow: 2px 2px 4px 0px #999;
border-radius: 0.5rem;
background: #fff;
position: relative;
width: 98%;
position: absolute;
}
.m3u_bn{
height: 30px;
argin: 5px;
border: 1px solid #888;
border-radius: 5px;
background: #fff;
cursor: pointer;
outline: none;
background: none;
font-size: 1.3rem;
line-height: 27px;
padding: 0 10px;
}
</style>`);
})();