-
Notifications
You must be signed in to change notification settings - Fork 3
/
xf.user.js
272 lines (260 loc) · 10.1 KB
/
xf.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// ==UserScript==
// @name web QQ旋风/xuanfeng
// @namespace web QQ旋风/xuanfeng
// @description 旋风离线链接导出
// @include http://lixian.qq.com/main.html*
// @version 0.9.1
// @Author: maplebeats
// @mail: maplebeats@gmail.com
// @run-at document-end
// ==/UserScript==
/*
* BUG:文件重名无法正常下载.....
* TIPS:$是tencent自己的一个function,不是$
* TODO:aria2-rpc状态检查等
*/
function contentEval(source) {
// Check for function input.
if ('function' == typeof source) {
// Execute this function with no arguments, by adding parentheses.
// One set around the function, required for valid syntax, and a
// second empty set calls the surrounded function.
source = '(' + source + ')();'
}
// Create a script node holding this source code.
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = source;
// Insert the script node into the page, so it will run, and immediately
// remove it to clean up.
document.body.appendChild(script);
document.body.removeChild(script);
}
var $ = unsafeWindow.jQuery;
function clear() {
var context = '<progress id="re-pro" value=0 style="width:280px;"></progress>'+
'<font color="red"></font>'+
'<div id="messager" style="border:1px solid;margin-top:5px;padding:5px;width:280px;">Welcome</div>';
$("#share_opt").html(context).css('float','left').css('width','250px').css('margin','20px');
$('.main').css('width','80%');
$('#cont_wrap').css('width','100%');
$("#down_box").remove();
$(".mod_copyright").remove();
$(".top").remove();
$(".search_box").remove();
$("#task_dl_local em").html("Aria2导出");
$("#task_share_multi em").html('一键RPC');
};
clear();
function run() {
EF = {};
var mode = 1;
var t_count = 0;
var task_info = [];
var add_task_info = function(j){
if(j){
task_info.push(j);
}
var count = task_info.length;
$('#re-pro').attr('max',t_count).attr('value',count);
if(count == t_count){
if(mode === 1){
EF.init_pop();
}else if(mode === 2){
EF.rpc();
}
$('#share_opt font').html('Success!');
t_count = 0;
}else{
return false;
}
};
EF.get_url = function (code) {
$.ajax({
type: "post",
url: "/handler/lixian/get_http_url.php",
data: code,
cache: false,
timeout: 10000,
dataType: "json",
async: true, //TvT
success: function (data) {
if (data && data.ret == 0) {
var url = data["data"];
var temp_json = { "name": code.filename, "url": url.com_url, "cookie": url.com_cookie };
add_task_info(temp_json);
}
else {
XF.widget.msgbox.show("请求url失败", 2, 2000);
t_count--;
add_task_info();
}
},
error: function () {
XF.widget.msgbox.show("请求url失败", 2, 2000);
t_count--;
add_task_info();
}
});
}
EF.rpc = function (data) {
var data = task_info;
var url = $("#rpc-url").val();
if(url == undefined){
url = localStorage.rpc;
}else{
localStorage.rpc = url;
}
var count = data.length;
for (var i=0;i<count;i++) {
var tmp = data[i];
var uri = { 'jsonrpc': '2.0', 'id': (new Date()).getTime().toString(), 'method': 'aria2.addUri', 'params': [[tmp.url, ], { 'out': tmp.name, 'header': 'Cookie: FTN5K=' + tmp.cookie}] }; /*,'split':'10','continue':'true','max-conection-per-server':'5','parameterized-uri':'true'}]};*/
var xhr = new XMLHttpRequest();
xhr.open("POST", url + "?tm=" + (new Date()).getTime().toString(), true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xhr.send(JSON.stringify(uri));
}
XF.widget.msgbox.hide();
XF.widget.msgbox.show("任务已经添加至aria2-rpc,请自行查看", 0, 1000, false)
}
EF.get_rpc = function(){
if(localStorage.rpc)
return localStorage.rpc;
else
return 'http://localhost:6800/jsonrpc';
}
EF.init_pop = function () {
var html = '<div class="choose_start" style="height:150px;width:100%;">'+
'<div style="margin-bottom: 20px;">'+
'<select id="choose" style="background:rgba(255,255,255,0.5);"><option value=1>aria2文件</option><option value=2>aria2命令</option><option value=3>wget命令</option><option value=4>aria2 json-rpc</option><option value=5>IDM导出</option></select>'+
'</div>'+
'<div id="show-export">'+
'<a id="save-as" class="icon_file" target="_blank" title="右键另存为" download="aria2.down">点击或右键另存为</a>'+
'<p>运行<code>aria2c -c -s10 -x10 -i aria2.down</code>进行下载</p>'+
'</div>'+
'<pre id="show-cmd" stlye="overflow-x: scroll;padding: 4px;border: 1px solid #CCC;">'+
'</pre>'+
'<div id="show-rpc">'+
'<p>确保后台已运行aria2 <code>aria2c -c -s10 -x10 --enable-rpc</code></p>'+
'<div><input id="rpc-url" type="text" style="width:200px;background:rgba(0,0,0,0);" value="'+EF.get_rpc()+'"></input></div><div id="rpc" class="com_opt_btn"><span><em>RPC</em></span></div>'+
'</div>'+
'<div id="show-idm">'+
'<a id="idm-save-as" class="icon_file" target="_blank" title="右键另存为" download="idm.ef2">点击或右键另存为</a>'+
'</div>'+
'</div>';
$('#messager').html(html);
$("#rpc").bind("click", function () {
EF.rpc();
});
$("#choose").bind("change", function () {
var data = EF.create_data($(this).val());
$('#show-export, #show-cmd, #show-rpc, #show-idm').hide();
switch (parseInt(this.value)) {
case 1 : //export file
var href = "data:text/plain;charset=utf-8," + encodeURIComponent(data);
$("#save-as").attr("href", href);
$('#show-export').show();
break;
case 2 : //show command code
case 3 :
$('#show-cmd').show().text(data);
break;
case 4 : //json rpc
$('#show-rpc').show();
break;
case 5: //IDM
var href = "data:text/plain;charset=utf-8," + encodeURIComponent(data);
$("#idm-save-as").attr("href", href);
$('#show-idm').show();
break;
}
}).change();//init
}
EF.create_data = function (value) {
var url = task_info;
var html = '';
var count = url.length;
for (var i=0;i<count;i++) {
var data = url[i];
var cookie = data.cookie;
var http = data.url;
var name = data.name;
switch (value) {
case '1':
html += http + "\n header=Cookie: FTN5K=" + cookie + "\n"+
" out=" + name + "\n" +
" continue=true\n";
//html += " parameterized-uri=true\n";
//html += " max-conection-per-server=5\n";
//html += " split=10\n"; //谁能告诉我为什么这个设置了完全无效????
break;
case '2':
html += "aria2c -c -s10 -x10 -o '" + name + "' --header 'Cookie: FTN5K=" + cookie + "' " + http + "\n";
break;
case '3':
html += "wget -c -O '" + name + "' --header Cookie:FTN5K=" + cookie + " " + http + "\n";
break;
case '5':
html += '<\r\n' + http + '\r\n' + 'cookie: FTN5K=' + cookie +'\r\n>\r\n\r\n';
break;
defalut:
break;
}
}
return html
}
EF.get_choice = function(){
var dl_tasks = [];
var tmp_taskid_str = '';
var tasks_count = 0;
for (var task_id in g_task_op.last_task_info) {
var tmp_obj = g_task_op.last_task_info[task_id];
if (check_failed_task(task_id)) continue;
var checkbox_elem = $('task_sel_' + task_id);
if (checkbox_elem && !checkbox_elem.checked) continue;
if (tmp_obj == null || tmp_obj.file_size != tmp_obj.comp_size) continue;
if (tmp_obj.dl_status != TASK_STATUS['ST_UL_OK']) continue;
var json_temp = { "filename": tmp_obj.file_name, "hash": tmp_obj.code, "browser": "other" };
dl_tasks.push(json_temp);
tmp_taskid_str = task_id;
tasks_count++;
}
if(tasks_count == 0){
return false;
}else{
return dl_tasks;
}
}
EF.hander_tasks = function(){
$('#share_opt font').html('......');
task_info = [];
var data = EF.get_choice();
console.log(data);
t_count = data.length;
for (var i=0;i<t_count;i++) {
EF.get_url(data[i]);
}
}
};
run();
contentEval(function(){
EventHandler.task_batch2local = function (e) {
var disabled = jQuery(e).hasClass("disabled_btn");
if (disabled) {
return false;
}
XF.widget.msgbox.show("后台开始请求下载连接...", 0, 1000, false);
EF.hander_tasks();
mode = 1;
}
EventHandler.task_share = function(e){
var disabled = jQuery(e).hasClass("disabled_btn");
if (disabled) {
return false;
}
$('#messager').html('RPC...');
XF.widget.msgbox.show('后台添加任务中', 0, 1000, false);
EF.hander_tasks();
mode = 2;
}
});