// ==UserScript==
// @name Japonx 字幕&视频 下载(不要用迅雷下载,支持PotPlayer播放)
// @description 下载 japonx 的字幕和视频。
// @version 3.5.4
// @author ThisAV
// @homepage https://greasyfork.org/zh-CN/users/122964
// @namespace https://greasyfork.org/users/122964
// @feedback https://greasyfork.org/en/scripts/372676/feedback
// @connect japronx.com
// @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://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
// @require https://greasyfork.org/scripts/373130/code/ProtocolCheck.js?version=635816
// @icon https://www.japonx.vip/favicon.ico
// @grant GM_addStyle
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// ==/UserScript==
(function(){
'use strict';
var host=location.hostname,
PageId=location.href.replace(/.+\/id\/(\d+).html/i,'$1'),
VideoID=$('dt:contains(番號)').next().text(), //番号
VideoUrl, VideoDownload=false, VideoUrlMP4,
VideoSubUrl,
webTitle=document.title='【'+VideoID+'】'+document.title;
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>');
$('<a>').attr({'class':'d-btn','href':"https://www.japonx.vip/portal/index/detail/id/"+(Number(PageId)+1)+".html"}).text('下一页').css({'display':'inline-block'}).insertAfter($('h2:contains(熱門推薦)').css({'display':'inline'}));
var JaPronX={
CheckUrl : function(url, callback){
GM_xmlhttpRequest({
url:url,
/*
headers: {
'Host':'japronx.com',
'Content-Type': 'application/x-www-form-urlencoded'
},*/
method:'head',
async:true,
ontimeout:10000,
onload:callback,
onerror:function(e){
console.log('error',url, e);
}
});
}
}
$.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(/\d+HD/im)>-1) VideoID+="HD";
else if(s.search(/\d_hd/im)>-1) VideoID=VideoID.toLowerCase().replace('-','')+'_hd';
else if(s.search(/\|[a-z]{3,5}-?\d{2,4}(?:_C)?\|/im)>-1) VideoID=s.match(/\|([a-z]{3,5}-?\d{2,4}(?:_C)?)\|/i)[1];
//适用网址:310、3786、3789、3791
if(s.search(/\|?(mp4)\|?/im)>-1) {
VideoUrl="https://player.japronx.com/Stream/"+VideoID+".mp4";
VideoDownload=true;
} else if(s.search(/\|?(m3u8)\|?/im)>-1) {
VideoUrl="https://play.japronx.com/"+VideoID+"/"+VideoID+".m3u8";
VideoUrlMP4="https://player.japronx.com/Stream/"+VideoID+".mp4";
}
JaPronX.CheckUrl(VideoUrl, function(e){
//console.log('load', e);
switch(e.status){
case 200:
if(VideoDownload) $('.d-btn.download').attr({'href':VideoUrl, 'target':'blank', 'download':VideoID}).css({'color':'black'});
else {
JaPronX.CheckUrl(VideoUrlMP4, function(e){
switch(e.status){
case 200:
$('.d-btn.download').attr({'href':VideoUrlMP4, 'target':'blank', 'download':VideoID}).css({'color':'black'});
break;
case 404:
$('.d-btn.download').attr({'href':VideoUrl, 'target':'blank', 'download':VideoID}).text('M3U8').css({'color':'black'});
break;
}
});
}
$btnDiv.append($('<a class="d-btn PotPlayer">').attr({'href':'potplayer://'+VideoUrl}).css({'color':'black'}).text('Potplayer').click(function(){
window.protocolCheck(this.href, function(){
if(confirm("协议未注册,现在去注册程序协议?")) GM_openInTab("https://greasyfork.org/zh-CN/scripts/372676/#potplayer");
});
}));
break;
case 404:
$('.d-btn.download').text('404').attr({'href':VideoUrl, 'target':'blank', 'download':VideoID});
break;
default:
$('.d-btn.download').text('获取失败');
break;
}
});
//$('.d-btn.download').text('暂无法下载').css('width','130px');
//字幕
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(e){
console.log('$ error:',e);
}
});
})();