forked from qinlili23333/ctfileGet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctbtn.js
151 lines (151 loc) · 9.63 KB
/
ctbtn.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
window.ctfile = {
version: "2.6.1-button",
IconPack: {
load: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0iI2U4N2E5MCI+DQogICAgPHBhdGggb3BhY2l0eT0iLjI1IiBkPSJNMTYgMCBBMTYgMTYgMCAwIDAgMTYgMzIgQTE2IDE2IDAgMCAwIDE2IDAgTTE2IDQgQTEyIDEyIDAgMCAxIDE2IDI4IEExMiAxMiAwIDAgMSAxNiA0IiAvPg0KICAgIDxwYXRoIGQ9Ik0xNiAwIEExNiAxNiAwIDAgMSAzMiAxNiBMMjggMTYgQTEyIDEyIDAgMCAwIDE2IDR6Ij4NCiAgICAgICAgPGFuaW1hdGVUcmFuc2Zvcm0gYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIiB0eXBlPSJyb3RhdGUiIGZyb209IjAgMTYgMTYiIHRvPSIzNjAgMTYgMTYiIGR1cj0iMnMiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiAvPg0KICAgIDwvcGF0aD4NCjwvc3ZnPg==",
fail: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0i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R0aD0iMyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PC9zdmc+"
},
makeBtn: (fileid, password) => {
let btn = document.createElement("div");
btn.style = "user-select: none;-webkit-user-select: none;-webkit-tap-highlight-color: transparent;display: flex;flex-direction: row;margin: 4px;height: 32px;border: 1px solid #666;border-radius: 4px;background-color: #ffffff;cursor: wait;transition: background-color 0.5s;"
let dlicon = document.createElement("img");
dlicon.style = "margin: 2px;width: 28px;height: 28px;transition: filter 0.5s;"
btn.appendChild(dlicon);
let dltitle = document.createElement("h2");
dltitle.style = "font-size: 1.5em !important;margin:0px;text-align: center;width: 100%;transition: color 0.5s;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;";
dltitle.innerText = "请稍等";
btn.appendChild(dltitle);
dlicon.src = ctfile.IconPack.load;
let initBtn = async (btn, icon, title, fileid, password) => {
let fileInfo = await ctfile.getByID(fileid, password);
let isOutDate = false;
console.log(fileInfo);
if (fileInfo.success) {
icon.src = ctfile.IconPack.down;
btn.style.backgroundColor = "#A8D8B9";
btn.style.cursor = "pointer";
btn.title = fileInfo.name;
title.innerText = fileInfo.size;
btn.addEventListener("mouseenter", event => { event.path[0].style.backgroundColor = "#86C166"; })
btn.addEventListener("mouseleave", event => { event.path[0].style.backgroundColor = isOutDate ? "#EB7A77" : "#A8D8B9"; })
btn.addEventListener("click", () => {
if (isOutDate) {
btn.style.backgroundColor = "";
dlicon.src = ctfile.IconPack.load;
dltitle.innerText = "请稍等";
initBtn(btn, dlicon, dltitle, fileid, password);
} else {
let eleLink = document.createElement('a');
eleLink.download = fileInfo.name;
eleLink.style.display = 'none';
eleLink.href = fileInfo.link;
document.body.appendChild(eleLink);
eleLink.click();
document.body.removeChild(eleLink);
}
})
setTimeout(() => {
icon.src = ctfile.IconPack.fail;
title.innerText = "链接已过期";
btn.style.backgroundColor = "#EB7A77";
btn.style.cursor = "not-allowed";
isOutDate = true;
}, 18000000)
} else {
icon.src = ctfile.IconPack.fail;
title.innerText = "下载不可用";
btn.style.backgroundColor = "#EB7A77";
btn.style.cursor = "not-allowed";
btn.title = fileInfo.errormsg;
}
}
initBtn(btn, dlicon, dltitle, fileid, password);
return btn;
}, getByLink: (link, password, token, firstcallback) => {
return ctfile.getByID(link.substring(link.lastIndexOf("/") + 1, (link.lastIndexOf("?") == -1) ? undefined : link.lastIndexOf("?")), (link.lastIndexOf("p=") == -1) ? password : link.substring(link.lastIndexOf("p=") + 2), token, firstcallback);
},
getByID: async (fileid, password, token, firstcallback) => {
const origin = () => {
//兼容node.js
if (document && !(document.location.origin == 'file://')) {
return document.location.origin;
} else {
return "https://ctfile.qinlili.workers.dev";
}
};
const path = id => {
switch (id.split("-").length) {
case 2: {
return "file";
};
case 3:
default: {
return "f";
}
}
}
jsonText = JSON.parse(await (await fetch("https://webapi.ctfile.com/getfile.php?path=" + path(fileid) + "&f=" + fileid + "&passcode=" + password + "&token=" + token + "false&r=" + Math.random() + "&ref=" + origin(), {
"headers": {
"origin": origin(),
"referer": origin()
},
})).text());
if (jsonText.code == 200) {
if (firstcallback) {
firstcallback({
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
})
};
if (jsonText.file.is_vip == 1) {
return {
"success": true,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"link": jsonText.file.vip_dx_url
};
} else {
jsonText2 = JSON.parse(await (await fetch("https://webapi.ctfile.com/get_file_url.php?uid=" + jsonText.file.userid + "&fid=" + jsonText.file.file_id + "&file_chk=" + jsonText.file.file_chk + "&app=0&acheck=2&rd=" + Math.random(), {
"headers": {
"origin": origin(),
"referer": origin()
},
})).text());
if (jsonText2.code == 200) {
return {
"success": true,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"link": jsonText2.downurl
};
} else {
if (jsonText2.code == 302) {
return {
"success": false,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"errormsg": "需要登录!"
};
} else {
return {
"success": false,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"errormsg": jsonText2.message
};
}
}
}
} else {
return {
"success": false,
"errormsg": jsonText.file.message
};
}
}
}