cf-worker-api/public/index.html

144 lines
5.2 KiB
HTML
Raw Normal View History

2025-06-12 00:13:57 +08:00
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2025-06-12 13:01:25 +08:00
<title>OpenList Token获取工具</title>
2025-06-12 00:13:57 +08:00
<link href="static/style-all.css" rel="stylesheet">
<link href="static/bootstrap.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<style>
</style>
</head>
<body>
<div class="container">
<div class="form-container" style="max-width: 1600px;">
2025-06-12 13:01:25 +08:00
<h1>OpenList Token获取工具</h1>
2025-06-12 00:13:57 +08:00
<div class="input-group">
2025-06-12 13:01:25 +08:00
<label for="site-select">网盘名称</label>
2025-06-12 00:13:57 +08:00
<select id="site-select">
<option value="official" selected>OneDrive 官方站点</option>
<!-- <option value="cn">OneDrive 世纪互联</option>-->
</select>
</div>
<div class="input-group">
2025-06-12 13:01:25 +08:00
<label for="client-id">客户端ID(Client ID)</label>
2025-06-12 00:13:57 +08:00
<input type="text" id="client-id" name="client-id">
</div>
<div class="input-group">
2025-06-12 13:01:25 +08:00
<label for="app-secret">应用机密(App Secret)</label>
2025-06-12 00:13:57 +08:00
<input type="text" id="app-secret" name="app-secret">
</div>
<div class="input-group">
2025-06-12 13:01:25 +08:00
<label for="callback-url">回调地址(Callback URL)</label>
<input type="text" id="callback-url" name="callback-url" value="https://api.oplist.org/onedrive/callback"
readonly onclick="autoCopy(this)">
2025-06-12 00:13:57 +08:00
</div>
<div class="input-group">
<button class="btn btn-success" onclick="getLogin()">获取Token</button>
</div>
<div class="input-group">
2025-06-12 13:01:25 +08:00
<label for="access-token">访问秘钥(Access Token)</label>
<textarea type="text" id="access-token" name="access-token" readonly onclick="autoCopy(this)"></textarea>
2025-06-12 00:13:57 +08:00
</div>
<div class="input-group">
<label for="refresh-token">刷新秘钥(Refresh Token)</label>
2025-06-12 13:01:25 +08:00
<textarea type="text" id="refresh-token" name="refresh-token" readonly onclick="autoCopy(this)"></textarea>
2025-06-12 00:13:57 +08:00
</div>
</div>
</div>
</body>
<script>
let intervalId;
2025-06-12 13:01:25 +08:00
// 获取登录秘钥 #######################################################
2025-06-12 00:13:57 +08:00
async function getLogin() {
let apps_uuid = document.getElementById("client-id").value;
let apps_keys = document.getElementById("app-secret").value;
2025-06-12 13:01:25 +08:00
if (apps_uuid === "" || apps_keys === "") {
Swal.fire({
position: 'top',
icon: 'info',
title: '获取失败',
text: '请先填写客户端ID和应用机密',
showConfirmButton: true,
});
return;
}
let post_urls = "/onedrive/requests?client_uid=" + apps_uuid
+ "&client_key=" + apps_keys;
2025-06-12 00:13:57 +08:00
try {
const response = await fetch(post_urls, {
method: 'GET', headers: {'Content-Type': 'application/json'}
});
// 解析响应内容 ===============================================
const response_data = await response.json();
if (response.status === 200) {
2025-06-12 13:01:25 +08:00
// window.open(response_data.text)
window.location.href = response_data.text;
2025-06-12 00:13:57 +08:00
} else Swal.fire({
icon: 'error',
title: "获取秘钥失败: " + response_data.text,
showConfirmButton: true,
timer: 1000
});
} catch (error) {
Swal.fire({
icon: 'error',
title: '获取秘钥失败: ' + error,
showConfirmButton: true,
timer: 1000
});
}
}
2025-06-12 13:01:25 +08:00
// 自动复制内容 #####################################################
function autoCopy(on_element) {
// if (on_element.innerText === "") return;
navigator.clipboard.writeText(on_element.value).then(() => {
// 显示复制成功的提示
Swal.fire({
position: 'top',
icon: 'success',
title: '内容已复制',
showConfirmButton: false,
timer: 700
});
}).catch(err => {
// 复制失败时的处理
console.error('无法复制文本:', err);
2025-06-12 00:13:57 +08:00
Swal.fire({
2025-06-12 13:01:25 +08:00
position: 'top',
2025-06-12 00:13:57 +08:00
icon: 'error',
2025-06-12 13:01:25 +08:00
title: '复制失败',
text: '请手动复制',
2025-06-12 00:13:57 +08:00
showConfirmButton: true,
});
2025-06-12 13:01:25 +08:00
})
}
2025-06-12 00:13:57 +08:00
2025-06-12 13:01:25 +08:00
async function getToken() {
const strSearch = window.location.search;
const urlParams = new URLSearchParams(strSearch);
const client_uid = urlParams.get("client_uid");
const client_key = urlParams.get("client_key");
const access_token = urlParams.get("access_token");
const refresh_token = urlParams.get("refresh_token");
document.getElementById("client-id").value = client_uid;
document.getElementById("app-secret").value = client_key;
document.getElementById("access-token").value = access_token;
document.getElementById("refresh-token").value = refresh_token;
2025-06-12 00:13:57 +08:00
}
2025-06-12 13:01:25 +08:00
getToken();
2025-06-12 00:13:57 +08:00
</script>
</html>