-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathquark.js
More file actions
107 lines (93 loc) · 3.16 KB
/
quark.js
File metadata and controls
107 lines (93 loc) · 3.16 KB
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
/*
Fileball挂载夸克网盘
版本:2.2312
[General]
force-http-engine-hosts = %APPEND% quark.example.com:0
[Script]
夸克网盘 = type=http-request,pattern=^http:\/\/quark\.example\.com,requires-body=1,max-size=-1,script-path=https://raw.githubusercontent.com/githubdulong/Script/master/quark.js,debug=0
作者:@小白脸
使用方法:
夸克登录网页版抓包,路径https://drive.quark.cn/1/clouddrive/file
Fileball挂载图标:https://raw.githubusercontent.com/githubdulong/Script/master/Images/Fileball.json
*/
let url = $request.url;
let body = $request.body;
let ck =
$persistentStore.read("quark-ck") ||
((ck) => {
$persistentStore.write(ck, "quark-ck");
return ck;
})(decodeURIComponent(body.match(/passwd=([^&]+)/)[1]));
let req = {
url: "https://drive.quark.cn/1/clouddrive/file/sort?_fetch_total=1&_page=1&_size=100&fr=pc&pdir_fid=0&pr=ucpro",
headers: { cookie: ck, "content-type": "application/json" },
};
!(async () => {
switch (url.match(/(auth|entry)\.cgi$/)?.[0]) {
case "auth.cgi":
$done({ response: { status: 200, body: '{"success":true,"data":{"sid":""}}' } });
break;
case "entry.cgi":
if (body.match("Delete&")) {
//删除文件
req.url = "https://drive.quark.cn/1/clouddrive/file/delete?fr=pc&pr=ucpro";
req.body = `{"action_type":1,"exclude_fids":[],"filelist":["${body.match(/path=([^&]+)/)[1]}"]}`;
$done(req);
} else {
//加载目录
let path = body.match(/folder_path=([^&]+)/)?.[1];
let a = path ? ((req.url = req.url.replace(/pdir_fid=0/, `pdir_fid=${path}`)), "files") : "shares";
let items = (await http(req, "get", 1)).data.list;
let shares = JSON.stringify(
items.map((item) => {
return {
isdir: !item.file,
path: item.fid,
name: item.file_name,
additional: { size: item.size },
};
}),
);
$done({
response: { status: 200, body: `{"success":true,"data":{"total":0,"offset":0,"${a}":${shares}}}` },
});
}
break;
default:
//加载文件
let fids = url.match("fbdownload") ? hex2str(url.match(/dlink=%22(.*)%22/)[1]) : url.match(/path=(.*$)/)[1];
req.url = "http://drive.quark.cn/1/clouddrive/file/download?fr=pc&pr=ucpro";
req.body = `{"fids":["${fids}"]}`;
let link = (await http(req, "post")).data[0].download_url.replace(/https/, "http");
$request.url = link;
$request.headers.cookie = ck;
delete $request.headers.Host;
$done($request);
}
})();
function http(req, method = "get", set) {
return new Promise((res) => {
$httpClient[method](req, (err, resp, data) => {
//刷新ck
set &&
((set = resp.headers?.["Set-Cookie"]?.split(";")[0]), set) &&
$persistentStore.write(ck.replace(/[^;]+/, set), "quark-ck");
res(JSON.parse(data));
});
});
}
function hex2str(hex) {
var trimedStr = hex.trim();
var rawStr = trimedStr.substr(0, 2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr;
var len = rawStr.length;
if (len % 2 !== 0) {
return "";
}
var curCharCode;
var resultStr = [];
for (var i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16);
resultStr.push(String.fromCharCode(curCharCode));
}
return resultStr.join("");
}