2 // @name 115网盘aria2导出工具
4 // @description 一个方便把115网盘导出到Aria2rpc的脚本。
6 // @include http://*.115.com/*
7 // @run-at document-end
10 var pan_115 = function(cookies
) {
11 var version
= "0.1.4";
12 var update_date
= "2016/02/09";
13 var pan
= (function() {
15 var SetMessage = function(msg
, type
) {
16 Core
.MinMessage
.Show({
22 var auth
= null; //是否设置用户名密码验证 设置的话变为auth赋值
23 var HttpSendRead = function(info
) {
24 var http
= new XMLHttpRequest();
25 var contentType
= "\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0078\u002d\u0077\u0077\u0077\u002d\u0066\u006f\u0072\u006d\u002d\u0075\u0072\u006c\u0065\u006e\u0063\u006f\u0064\u0065\u0064\u003b\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003d\u0055\u0054\u0046\u002d\u0038";
27 var deferred
= jQuery
.Deferred();
28 if (info
.contentType
!= null) {
29 contentType
= info
.contentType
;
31 if (info
.timeout
!= null) {
32 timeout
= info
.timeout
;
34 var timeId
= setTimeout(httpclose
, timeout
);
35 function httpclose() {
38 deferred
.promise(http
);
39 http
.onreadystatechange = function() {
40 if (http
.readyState
== 4) {
41 if ((http
.status
== 200 && http
.status
< 300) || http
.status
== 304) {
43 if (info
.dataType
== "json") {
44 deferred
.resolve(JSON
.parse(http
.responseText
), http
.status
, http
);
46 else if (info
.dataType
== "SCRIPT") {
47 // eval(http.responseText);
48 deferred
.resolve(http
.responseText
, http
.status
, http
);
53 deferred
.reject(http
, http
.statusText
, http
.status
);
58 http
.open(info
.type
, info
.url
, true);
59 http
.setRequestHeader("Content-type", contentType
);
60 for (h
in info
.headers
) {
61 if (info
.headers
[h
]) {
62 http
.setRequestHeader(h
, info
.headers
[h
]);
65 if (info
.type
== "POST") {
73 //设置aria2c下载设置的Header信息
75 header: function(type
) {
77 var UA
= $("#setting_aria2_useragent_input").val() || "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 115Browser/5.1.3";
78 var headers
= $("#setting_aria2_headers").val();
79 var referer
= $("#setting_aria2_referer_input").val() || "http://115.com/";
80 addheader
.push("User-Agent: " + UA
);
81 // var baidu_cookies=JSON.parse(cookies);
82 // var format_cookies=[];
83 // for(var i=0;i<baidu_cookies.length;i++){
84 // for(var key in baidu_cookies[i]){
85 // // addheader.push("Cookie: " + key +"=" +baidu_cookies[i][key]);
86 // format_cookies.push(key +"=" +baidu_cookies[i][key]);
89 // addheader.push("Cookie: " + format_cookies.join(";"));
90 addheader
.push("Referer: " + referer
);
92 var text
= headers
.split("\n");
93 for (var i
= 0; i
< text
.length
; i
++) {
94 addheader
.push(text
[i
]);
98 if (type
== "aria2c_line") {
99 for (var i
= 0; i
< addheader
.length
; i
++) {
100 header
+= " --header " + JSON
.stringify(addheader
[i
]) + " ";
103 } else if (type
== "aria2c_txt") {
104 for (var i
= 0; i
< addheader
.length
; i
++) {
105 header
+= " header=" + (addheader
[i
]) + " \n";
108 } else if (type
== "idm_txt") {
109 for (var i
= 0; i
< addheader
.length
; i
++) {
110 header
+= " header=" + (addheader
[i
]) + " \n";
119 var css = function() {/*
126 padding: 0 10px 0 10px;
140 padding: 0 10px 0 10px;
150 li[rel="item"]:hover .show-export-button {
156 }.toString().slice(15, -4);
157 var url
= (localStorage
.getItem("rpc_url") || "http://localhost:6800/jsonrpc") + "?tm=" + (new Date().getTime().toString());
164 self
.set_config_ui();
166 SetMessage("载入成功!", "inf");
169 //设置导出按钮的触发 js_top_panel_box
172 document
.querySelector("iframe[rel='wangpan']").addEventListener('load',function(){
175 main_page_setting_btn();
176 function main_page_setting_btn(){
177 var setting_div
=$("<a>").text("插件设置").attr("href","javascript:;");
178 var main_setting_div
=$("<a>").text("插件设置").attr("href","javascript:;");
179 main_setting_div
.attr("id","main_setting_div");
180 if(!document
.querySelector("a[id='main_setting_div']")){
181 main_setting_div
.appendTo($(document
.querySelector("div[id='js_main_container']")).find(".tup-logout"));
182 main_setting_div
.on('click',function(){
183 $("#setting_div").show();
184 $("#setting_divtopmsg").html("");
185 self
.set_center($("#setting_div"));
189 function top_panel_box_btn(){
190 var root
=document
.querySelector("iframe[rel='wangpan']").contentDocument
;
191 var setting_div
=$("<a>").text("插件设置").attr("href","javascript:;");
192 var main_setting_div
=$("<a>").text("插件设置").attr("href","javascript:;");
193 main_setting_div
.attr("id","main_setting_div");
194 setting_div
.appendTo($(root
).find(".tup-logout"));
195 if(!document
.querySelector("a[id='main_setting_div']")){
196 main_setting_div
.appendTo($(document
.querySelector("div[id='js_main_container']")).find(".tup-logout"));
197 main_setting_div
.on('click',function(){
198 $("#setting_div").show();
199 $("#setting_divtopmsg").html("");
200 self
.set_center($("#setting_div"));
203 setting_div
.on('click',function(){
204 $("#setting_div").show();
205 $("#setting_divtopmsg").html("");
206 self
.set_center($("#setting_div"));
208 $(root
).find(".file-path").after($("<div>").text("RPC下载").addClass("btn-aria2c").on('click',function(){
209 self
.aria2_export(true);
211 $(root
).find(".file-path").after($("<div>").text("导出下载").addClass("btn-txt").on('click',function(){
212 self
.aria2_download();
213 self
.aria2_export(false);
215 var style
= document
.createElement('style');
216 style
.setAttribute('type', 'text/css');
217 style
.textContent
= css
;
218 root
.head
.appendChild(style
);
221 set_config_ui:function(){
223 var setting_div
= document
.createElement("div");
224 setting_div
.className
= "download-mgr-dialog dialog-box";
225 setting_div
.id
= "setting_div";
227 '<h2 class="dialog-title" ><span rel="base_title">导出设置</span><div class="dialog-handle"><a href="javascript:;" class="diag-close" btn="close">关闭</a></div></h2>',
228 '<div style=" margin: 20px 10px 10px 10px; ">',
229 '<div id="setting_divtopmsg" style="position:absolute; margin-top: -18px; margin-left: 10px; color: #E15F00;"></div>',
230 '<table id="setting_div_table" >',
232 '<tr><td width="100"><label>ARIA2 RPC:</label></td><td><input id="rpc_input" type="text" class="input-large"></td></tr>',
233 '<tr><td><label>RPC访问设置</label></td><td><input id="rpc_distinguish" type="checkbox"></td></tr>',
234 '<tr><td><label >RPC 用户名:</label></td><td><input type="text" id="rpc_user" disabled="disabled" class="input-small"></td></tr>',
235 '<tr><td><label>RPC 密码:</label></td><td><input type="text" id="rpc_pass" disabled="disabled" class="input-small"></td></tr>',
236 '<tr><td><label>Secret Token:</label></td><td><input type="text" id="rpc_token" class="input-small"><div style="position:absolute; margin-top: -20px; right: 20px;"><a id="send_test" type="0" href="javascript:;" >测试连接,成功显示版本号。</a></div></td></tr>',
237 '<tr><td><label>下载路径:</label></td><td><input type="text" placeholder="只能设置为绝对路径" id="setting_aria2_dir" class="input-large"></td></tr>',
238 '<tr><td><label>User-Agent :</label></td><td><input type="text" id="setting_aria2_useragent_input" class="input-large"></td></tr>',
239 '<tr><td><label>Referer :</label></td><td><input type="text" id="setting_aria2_referer_input" class="input-large"></td></tr>',
240 '<tr><td colspan="2"><div style="color: #656565;">Headers<label style="margin-left: 65px;">※使用回车分隔每个headers。</label></div><li class="b-list-item separator-1"></li></td></tr>',
241 '<tr><td><label>headers :</label></td><td><textarea id="setting_aria2_headers" ></textarea></td></tr>',
244 '<div style="margin-top:10px;">',
245 '<div id="copyright">© Copyright <a href="https://github.com/acgotaku/115">雪月秋水 </a> Version:' + version
+ ' 更新日期: ' + update_date
+ ' </div>',
246 '<div style="margin-left:20px; display:inline-block"><a href="javascript:;" id="apply" class="button" ><b>应用</b></a></div>',
250 setting_div
.innerHTML
= html_
.join("");
251 document
.body
.appendChild(setting_div
);
252 $(".diag-close").click(function() {
253 $("#setting_div").hide();
255 $("#apply").click(function() {
257 $("#setting_divtopmsg").html("设置已保存.");
259 $("#send_test").click(function() {
262 $("#rpc_distinguish").change(function() {
263 if ($(this).is(":checked")) {
264 $("#rpc_user").removeAttr("disabled").css("background-color", "#FFF");
265 $("#rpc_pass").removeAttr("disabled").css("background-color", "#FFF");
267 $("#rpc_user").attr({"disabled": "disabled"}).css("background-color", "#eee");
268 $("#rpc_pass").attr({"disabled": "disabled"}).css("background-color", "#eee");
274 set_config: function() {
275 $("#rpc_input").val((localStorage
.getItem("rpc_url") || "http://localhost:6800/jsonrpc"));
276 $("#rpc_token").val(localStorage
.getItem("rpc_token"));
277 $("#setting_aria2_dir").val(localStorage
.getItem("rpc_dir"));
278 $("#setting_aria2_useragent_input").val(localStorage
.getItem("UA") || "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 115Browser/5.1.3");
279 $("#setting_aria2_referer_input").val(localStorage
.getItem("referer") || "http://115.com/");
280 $("#setting_aria2_headers").val(localStorage
.getItem("rpc_headers"));
282 if (localStorage
.getItem("auth") == "true") {
283 var rpc_user
= localStorage
.getItem("rpc_user");
284 var rpc_pass
= localStorage
.getItem("rpc_pass");
285 $("#rpc_user").val(rpc_user
);
286 $("#rpc_pass").val(rpc_pass
);
287 $("#rpc_distinguish").prop('checked', true).trigger("change");
288 auth
= "Basic " + btoa(rpc_user
+ ":" + rpc_pass
);
291 $("#rpc_user, #rpc_pass").val("");
295 get_config: function() {
296 var rpc_url
= $("#rpc_input").val();
298 localStorage
.setItem("rpc_url", rpc_url
);
299 url
= rpc_url
+ "?tm=" + (new Date().getTime().toString());
301 localStorage
.setItem("UA", document
.getElementById("setting_aria2_useragent_input").value
|| "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 115Browser/5.1.3");
302 if ($("#rpc_distinguish").prop('checked') == true) {
303 localStorage
.setItem("rpc_user", $("#rpc_user").attr("value"));
304 localStorage
.setItem("rpc_pass", $("#rpc_pass").attr("value"));
305 localStorage
.setItem("auth", true);
306 auth
= "Basic " + btoa($("#rpc_user").attr("value") + ":" + $("#rpc_pass").attr("value"));
308 localStorage
.setItem("auth", false);
309 localStorage
.setItem("rpc_user", null);
310 localStorage
.setItem("rpc_pass", null);
312 localStorage
.setItem("rpc_token", $("#rpc_token").val());
313 localStorage
.setItem("rpc_dir", $("#setting_aria2_dir").val());
314 localStorage
.setItem("rpc_headers", $("#setting_aria2_headers").val());
315 localStorage
.setItem("referer", $("#setting_aria2_referer_input").val());
317 set_center:function(obj
){
318 var screenWidth
= $(window
).width(), screenHeight
= $(window
).height();
319 var scrolltop
= $(document
).scrollTop();
320 var objLeft
= (screenWidth
- obj
.width())/2 ;
321 var objTop
= (screenHeight
- obj
.height())/2 + scrolltop
;
322 obj
.css({left
: objLeft
+ 'px', top
: objTop
+ 'px'});
324 getFileInfo:function(pick_code
,method
,path
){
327 DownBridge
.getFileUrl(pick_code
,function(data
){
329 file_list
.push({"name": (path
||"")+$('<textarea />').html(data
.file_name
).text(), "link": data
.file_url
});
331 self
.aria2_rpc(file_list
);
333 $("#download_ui").show();
334 self
.aria2_data(file_list
);
340 aria2_export:function(method
){
342 var root
=document
.querySelector("iframe[rel='wangpan']").contentDocument
;
343 $(root
).find('li[rel="item"][file_type="1"]').each(function(){
344 if($(this).children().eq(3).prop('checked') == true){
345 var pick_code
= $(this).attr('pick_code');
346 self
.getFileInfo(pick_code
,method
);
349 $(root
).find('li[rel="item"][file_type="0"]').each(function(){
350 if($(this).children().eq(2).prop('checked') == true){
351 var cate_id
= $(this).attr('cate_id');
352 DownBridge
.getFileList(cate_id
,function(data
){
354 for(var i
=0;i
<list
.length
;i
++){
356 self
.getFileInfo(list
[i
].pc
,method
,data
.path
[data
.path
.length
-1].name
+"/");
358 var dir_level
=data
.path
.length
-1;
359 self
.get_all_dir(list
[i
].cid
,dir_level
,method
);
367 get_all_dir:function(cid
,dir_level
,method
){
369 DownBridge
.getFileList(cid
,function(data
){
372 for(var i
=dir_level
;i
<data
.path
.length
;i
++){
373 path
+=data
.path
[i
].name
+"/";
375 for(var i
=0;i
<list
.length
;i
++){
377 self
.getFileInfo(list
[i
].pc
,method
,path
);
379 self
.get_all_dir(list
[i
].cid
,dir_level
,method
);
385 aria2_download: function() {
386 if ($("#download_ui").length
== 0) {
387 var download_ui
= $("<div>").attr("id", "download_ui").addClass("download-mgr-dialog dialog-box").html('<h2 class="dialog-title" ><span rel="base_title">ARIA2导出</span><div class="dialog-handle"><a href="javascript:;" class="diag-close" btn="close">关闭</a></div></h2>');
388 var content_ui
= $("<div>").addClass("content").attr("id", "content_ui").appendTo(download_ui
);
389 download_ui
.appendTo($("body"));
391 var download_menu
= $("<div>").css({"display": "block", "margin-bottom": "10px"}).appendTo(content_ui
);
392 var aria2c_btn
= $("<a>").attr("id", "aria2c_btn").attr({"href": "data:text/plain;charset=utf-8,", "download": "aria2c.down", "target": "_blank"}).addClass("new-btn").html('<b>存为aria2文件</b>').appendTo(download_menu
);
393 var idm_btn
= $("<a>").attr("id", "idm_btn").attr({"href": "data:text/plain;charset=utf-8,", "download": "idm.txt", "target": "_blank"}).addClass("new-btn").html('<b>存为IDM文件</b>').appendTo(download_menu
);
394 var download_txt_btn
= $("<a>").attr("id", "download_txt_btn").attr({"href": "data:text/plain;charset=utf-8,", "download": "download_link.down", "target": "_blank"}).addClass("new-btn").html('<b>保存下载链接</b>').appendTo(download_menu
);
395 var download_link
= $("<textarea>").attr("wrap", "off").attr("id", "download_link").css({"white-space": "nowrap", "width": "100%", "overflow": "scroll", "height": "180px"});
396 download_link
.appendTo(content_ui
);
397 $(".diag-close").click(function() {
401 $("#aria2c_btn, #idm_btn, #download_txt_btn").attr("href", "data:text/plain;charset=utf-8,");
402 $("#download_link").val("");
406 aria2_data: function(file_list
) {
411 if (file_list
.length
> 0) {
412 var length
= file_list
.length
;
413 for (var i
= 0; i
< length
; i
++) {
414 files
.push("aria2c -c -s10 -k1M -x10 -o " + JSON
.stringify(file_list
[i
].name
) + combination
.header('aria2c_line') + " " + JSON
.stringify(file_list
[i
].link
) + "\n");
417 combination
.header("aria2c_txt"),
418 ' out=' + file_list
[i
].name
,
420 ' max-connection-per-server=10',
427 ' cookie: ' + cookies
,
428 ' out=' + file_list
[i
].name
,
431 down_txt
.push([file_list
[i
].link
, ' '].join('\n'));
433 $("#aria2c_btn").attr("href", $("#aria2c_btn").attr("href") + encodeURIComponent(aria2c_txt
.join("")));
434 $("#idm_btn").attr("href", $("#idm_btn").attr("href") + encodeURIComponent(idm_txt
.join("")));
435 $("#download_txt_btn").attr("href", $("#download_txt_btn").attr("href") + encodeURIComponent(down_txt
.join("")));
436 $("#download_link").val($("#download_link").val() + files
.join(""));
437 $("#download_ui").show();
438 this.set_center($("#download_ui"));
442 set_down_url:function(){
445 $('<iframe>').attr('src', '//webapi.115.com/bridge_2.0.html?namespace=DownBridge&api=jQuery').css({
451 position
: 'absolute',
453 }).one('load',function(){
454 window
.DownBridge
.getFileUrl=function(pickcode
,callback
){
455 this.jQuery
.get('//webapi.115.com/files/download?pickcode=' + pickcode
, function (data
) {
459 window
.DownBridge
.getFileList=function(cate_id
,callback
){
460 this.jQuery
.get('//webapi.115.com/files?aid=1&limit=1000&show_dir=1&cid=' + cate_id
, function (data
) {
467 get_version: function() {
470 "method": "aria2.getVersion",
474 if ($("#rpc_token").val()) {
475 data
.params
.unshift("token:" + $("#rpc_token").val());
477 var parameter
= {'url': url
, 'dataType': 'json', type
: 'POST', data
: JSON
.stringify(data
), 'headers': {'Authorization': auth
}};
478 HttpSendRead(parameter
)
479 .done(function(xml
, textStatus
, jqXHR
) {
480 $("#send_test").html("ARIA2\u7248\u672c\u4e3a\uff1a\u0020" + xml
.result
.version
);
482 .fail(function(jqXHR
, textStatus
, errorThrown
) {
483 $("#send_test").html("错误,请查看是否开启Aria2");
487 aria2_rpc: function(file_list
) {
489 if (file_list
.length
> 0) {
490 var length
= file_list
.length
;
491 for (var i
= 0; i
< length
; i
++) {
494 "method": "aria2.addUri",
495 "id": new Date().getTime(),
496 "params": [[file_list
[i
].link
], {
497 "out": file_list
[i
].name
,
498 "dir":$("#setting_aria2_dir").val()||null,
499 "header": combination
.header()
503 if ($("#rpc_token").val()) {
504 rpc_data
.params
.unshift("token:" + $("#rpc_token").val());
506 self
.aria2send_data(rpc_data
);
511 aria2send_data: function(data
) {
512 var parameter
= {'url': url
, 'dataType': 'json', type
: 'POST', data
: JSON
.stringify(data
), 'headers': {'Authorization': auth
}};
513 HttpSendRead(parameter
)
514 .done(function(json
, textStatus
, jqXHR
) {
515 SetMessage("下载成功!赶紧去看看吧~", "inf");
518 .fail(function(jqXHR
, textStatus
, errorThrown
) {
519 SetMessage("下载失败!是不是没有开启aria2?", "err");
527 var setting_css= function() {/*
528 .download-mgr-dialog{
534 font-family: tahoma, arial, 宋体, 'Microsoft Yahei', Simsun;
536 #setting_div_table input{
537 border: 1px solid #C6C6C6;
538 box-shadow: 0 0 3px #C6C6C6;
539 -webkit-box-shadow: 0 0 3px #C6C6C6;
550 display: inline-block;
552 padding: 0 10px 0 10px;
564 text-decoration: none;
567 #setting_div_table input[disabled]{
569 background-color: #eee;
572 display:inline-block;
573 border:1px solid #D1D1D1;
574 background-color: #F7F7F7;
575 text-align: center; text-decoration: none;
579 display:inline-block;
581 #setting_aria2_headers{
586 border: 1px solid #C6C6C6;
587 box-shadow: 0 0 3px #C6C6C6;
588 -webkit-box-shadow: 0 0 3px #C6C6C6;
591 display:inline-block;
595 text-decoration: none;
597 background: -webkit-linear-gradient(top, #52C035, #4BAC32);
598 background: -moz-linear-gradient(top, #52C035, #4BAC32);
599 background: -o-linear-gradient(top, #52C035, #4BAC32);
600 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#52C035', endColorstr='#4BAC32');
606 .download-mgr-dialog .content {
614 border-collapse:separate;
617 background-color: rgb(250, 250, 250);
620 }.toString().slice(15, -4);
622 if(document
.querySelector("iframe[rel='wangpan']")&&top
.location
==location
){
623 if(document
.querySelector("iframe[rel='wangpan']").contentDocument
.readyState
=="complete"){
624 var root
=document
.querySelector("iframe[rel='wangpan']").contentDocument
;
625 var script
= document
.createElement('script');
626 script
.id
= "pan_115_script";
627 script
.appendChild(document
.createTextNode('(' + pan_115
+ ')();'));
628 if(document
.querySelector("#pan_115_script") == null){
629 (document
.body
|| document
.head
|| document
.documentElement
).appendChild(script
);
630 var style
= document
.createElement('style');
631 style
.setAttribute('type', 'text/css');
632 style
.textContent
= setting_css
;
633 document
.head
.appendChild(style
);