-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
132 lines (112 loc) · 4.69 KB
/
script.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
function convertLinks() {
const inputText = document.getElementById('inputLinks').value;
const links = inputText.split('\n');
const outputElement = document.getElementById('outputLinks');
// 显示加载动画
showLoading();
// 使用 setTimeout 模拟异步处理
setTimeout(() => {
const convertedLinks = links.map(link => {
link = link.trim();
if (!link) return ''; // 跳过空行
const match = link.match(/objectId=([^&]+)/);
if (match) {
return `https://sharewh.chaoxing.com/share/download/${match[1]}`;
} else {
return `无效链接: ${link}`;
}
});
outputElement.value = convertedLinks.filter(link => link).join('\n');
// 隐藏加载动画
hideLoading();
}, 100);
}
function copyOutput() {
const outputElement = document.getElementById('outputLinks');
outputElement.select();
document.execCommand('copy');
alert('结果已复制!');
}
function showLoading() {
document.getElementById('loadingIndicator').style.display = 'block';
}
function hideLoading() {
document.getElementById('loadingIndicator').style.display = 'none';
}
async function extractFileInfo() {
const inputUrl = document.getElementById('inputUrl').value.trim();
const outputElement = document.getElementById('linkInfo');
console.log("输入的链接是:", inputUrl);
if (!inputUrl) {
outputElement.textContent = "请输入链接!";
return;
}
showLoading();
try {
let fileInfo;
if (inputUrl.includes('pan-yz.cldisk.com')) {
try {
// 从 URL 中解析信息
const url = new URL(inputUrl);
const fileId = url.pathname.split('/').pop(); // 获取文件ID
const encodedFileName = url.searchParams.get('name');
if (!encodedFileName || !fileId) {
throw new Error("无效的文件链接");
}
const fileName = decodeURIComponent(encodedFileName);
const fileExtension = fileName.split('.').pop().toUpperCase();
fileInfo = {
name: fileName,
type: fileExtension,
id: fileId,
originalUrl: inputUrl,
// 构建可能的下载链接
downloadUrls: [
inputUrl,
`https://pan-yz.cldisk.com/api/v1/share/download/${fileId}`,
`https://pan-yz.cldisk.com/external/d/file/${fileId}/${encodedFileName}`
]
};
} catch (e) {
console.error("解析链接时出错:", e);
throw new Error("无法解析文件链接,请确保链接格式正确");
}
} else if (inputUrl.includes('chaoxing.com')) {
const match = inputUrl.match(/objectId=([^&]+)/);
if (!match) {
throw new Error("无法识别的超星链接格式");
}
const objectId = match[1];
fileInfo = {
name: '超星文件',
type: '未知',
id: objectId,
downloadUrls: [`https://sharewh.chaoxing.com/share/download/${objectId}`]
};
} else {
throw new Error("不支持的链接格式");
}
// 构建显示内容
let displayContent = `
<div class="file-info">
<p><strong>文件名:</strong>${fileInfo.name}</p>
<p><strong>文件类型:</strong>${fileInfo.type}</p>
<p><strong>文件ID:</strong>${fileInfo.id}</p>
<p><strong>下载链接:</strong></p>
<ul>
${fileInfo.downloadUrls.map((url, index) =>
`<li><a href="${url}" target="_blank" class="download-link">下载链接 ${index + 1}</a></li>`
).join('')}
</ul>
${fileInfo.originalUrl ?
`<p><strong>原始链接:</strong><a href="${fileInfo.originalUrl}" target="_blank">点击访问</a></p>`
: ''}
</div>`;
outputElement.innerHTML = displayContent;
} catch (error) {
console.error("处理链接时出错:", error);
outputElement.textContent = error.message || "处理链接时发生错误!";
} finally {
hideLoading();
}
}