-
Notifications
You must be signed in to change notification settings - Fork 190
/
ThunderLixianExporterPatch.uc.js
126 lines (102 loc) · 3.6 KB
/
ThunderLixianExporterPatch.uc.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
// ==UserScript==
// @name ThunderLixianExporterPatch.uc.js
// @namespace [email protected]
// @author ywzhaiqi
// @description 迅雷离线直接导出IDM.ef2,需配合 ThunderLixianExporter.use.js 使用。
// @include main
// @charset UTF-8
// @version 0.0.2
// @note
// ==/UserScript==
/**
* ThunderLixianExporter.use.js 下载地址
* http://binux.github.io/ThunderLixianExporter/master/ThunderLixianExporter.user.js
*/
if(typeof window.thunderLixian != 'undefined'){
window.thunderLixian.uninit();
delete window.thunderLixian;
}
(function(){
// 导出名字
var idm_export_name = "idm.ef2";
// 导出路径为 config 中的 browser.download.dir
let { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
if (!window.Services) Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
var ns = window.thunderLixian = {
init: function(){
gBrowser.mPanelContainer.addEventListener('load', this, true);
},
uninit: function(){
gBrowser.mPanelContainer.removeEventListener('load', this, true);
},
handleEvent: function(event){
switch(event.type){
case 'load':
var doc = event.target;
var win = doc.defaultView;
if(win && win.location.hostname == "dynamic.cloud.vip.xunlei.com"){
ns.addListener(win);
}
break;
}
},
addListener: function(win){
var batch_getbtn = win.document.getElementById("TLE_batch_getbtn");
if(!batch_getbtn) return;
var link = win.document.createElement("a");
link.innerHTML = "直接导出IDM文件";
link.setAttribute("href", "javascript:void(0);");
batch_getbtn.insertBefore(link, batch_getbtn.children[1]);
link.addEventListener("click", function(){
var TLE = win.wrappedJSObject.TLE;
if(!TLE) return;
TLE.batch_down(null, function(todown){
var str = "";
for(var taskId in todown.tasklist){
var task = todown.tasklist[taskId];
task.filelist.forEach(function(file, l){
if (!file.downurl) return;
str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n';
});
}
saveFile(str);
});
}, false);
},
};
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
function initFile(){
try{
var download_dir = Services.prefs.getComplexValue("browser.download.dir", Ci.nsISupportsString).data;
var idm_export_path = download_dir + "\\" + idm_export_name;
file.initWithPath(idm_export_path);
}catch(ex){
file = FileUtils.getFile("DfltDwnld", [idm_export_name]);
}
}
function saveFile(data) {
initFile();
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
var suConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
suConverter.charset = 'UTF-8';
data = suConverter.ConvertFromUnicode(data);
var foStream = Cc['@mozilla.org/network/file-output-stream;1'].createInstance(Ci.nsIFileOutputStream);
foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0);
foStream.write(data, data.length);
foStream.close();
alerts("IDM导出文件路径", file.path);
}
function checkDoc(doc) {
if (!(doc instanceof HTMLDocument)) return false;
if (!window.mimeTypeIsTextBased(doc.contentType)) return false;
if (!doc.body || !doc.body.hasChildNodes()) return false;
if (doc.body instanceof HTMLFrameSetElement) return false;
return true;
}
function alerts(title, info){
Cc['@mozilla.org/alerts-service;1'].getService(Ci.nsIAlertsService)
.showAlertNotification(null, title, info, false, "", null, "");
}
})();
window.thunderLixian.init();