Japonx 字幕&视频 下载(不要用迅雷下载)

下载 japonx 的字幕和视频。

Versión del día 10/10/2018. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         Japonx 字幕&视频 下载(不要用迅雷下载)
// @homepage    https://greasyfork.org/zh-CN/users/122964
// @version      3.2.2
// @description  下载 japonx 的字幕和视频。
// @author       ThisAV
// @connect     *.japonx.net
// @connect     *.japonx.vip
// @include     https://japonx.net/portal/index/detail/id/*
// @include     https://japonx.vip/portal/index/detail/id/*
// @include     https://www.japonx.net/portal/index/detail/id/*
// @include     https://www.japonx.vip/portal/index/detail/id/*
// @run-at      document-idle
// require			http://code.jquery.com/jquery-2.1.4.min.js
// @require			http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
// @feedback        https://greasyfork.org/en/scripts/372676/feedback
// @icon            https://www.japonx.net/favicon.ico
// @grant       GM_addStyle
// @namespace https://greasyfork.org/users/122964
// ==/UserScript==
(function(){
    'use strict';
    //内嵌字幕:
    //VTT字母:103、277
    //MP4:277,632
    //MP4HD: 250
    //M3U8 & MP4: 3573
    var host=location.hostname,
        PageId=location.href.replace(/.+\/id\/(\d+).html/i,'$1'),
        VideoID=$('dt:contains(番號)').next().text(), //番号
        VideoUrl, VideoUrlm3u8,
        VideoSubUrl;

    var $btnDiv = $('#d-btn');
    if(0) $btnDiv.append('<a class="d-btn sub" target="_blank" href="https://'+host+'/portal/index/ajax_get_js.html?id='+PageId+'">Ajax</a>');
    $.ajax({
        'url':'/portal/index/ajax_get_js.html',
        'data' : {'id':PageId},
        'responseType':'text',
        'success' : function(s, t, e){
            GM_addStyle("dl.desc {width:400px;} #contents-inline dl a:hover{border:1px solid #00aaff;margin:1px!important;} .play{margin-right:0px!important;} .PotPlayer, .sub{width:130px;}");


            console.log(t,e, s);
            //视频
            if(s.search(/\|(mp4|m3u8)\|/im)>-1) {
                if(s.search(/\d+HD/im)>-1) VideoID+="HD";
                if(s.search(/\d_hd/im)>-1) VideoID=VideoID.toLowerCase().replace('-','')+'_hd';
                VideoUrl="https://player."+host.replace(/(?:[\w.]+\.)?(\w+\.\w+)$/ig,'$1')+"/Stream/"+VideoID+".mp4";
                VideoUrlm3u8="https://player."+host.replace(/(?:[\w.]+\.)?(\w+\.\w+)$/ig,'$1')+"/Stream/"+VideoID+".m3u8";
            }
            $('.d-btn.download').text('暂无法下载').css('width','130px');
            /*
            if(VideoUrl) {
              $('.d-btn.download').attr({'href':VideoUrl, 'target':'blank', 'download':VideoID}).css({'color':'black'});
              $btnDiv.append($('<a class="d-btn PotPlayer">').attr({'href':'potplayer://'+VideoUrlm3u8, 'target':'blank'}).css({'color':'black'}).text('Potplayer'));
            }
*/
            //字幕
            if(s.search(/\|vtt\|/im)===-1) $zmBtn = $('<a class="d-btn sub" style="color:#ccc;" href="javascript:void(0);">无字幕文件</a>');
            else {
                var Arr=s.match(/\|vtt\|(\w+)\|(\w+)\|/im),
                    Arry=s.split('|'),
                    uSubDate=Arr[2],  //上传日期
                    uSubKey=Arr[1],   //文件名
                    $zmBtn;
                console.log(Arr,Arry);
                if(uSubKey.length===32) VideoSubUrl='https://'+host+'/upload/admin/'+uSubDate+'/'+uSubKey+'.vtt';
                else {
                    //如果无法直接提取到文件名,则遍历返回的内容
                    console.log('uSubKey 不是文件名:', uSubKey);
                    $.each(Arry,function(index,val){
                        if(val.length===32) {
                            uSubKey=val;
                            uSubDate=Arry[index+1];
                            return false;
                        }
                    });
                    VideoSubUrl='https://'+host+'/upload/admin/'+uSubDate+'/'+uSubKey+'.vtt';
                }
            }

            if(VideoSubUrl && VideoSubUrl != 'undefined'){
                $zmBtn = $('<a class="d-btn sub" target="_blank">下載字幕</a>').attr({'download':VideoID+'.vtt', 'href':VideoSubUrl});
            };
            $btnDiv.append($zmBtn);
        },
        'error' : function(){

        }
    });

})();