-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.html
More file actions
120 lines (109 loc) · 4.2 KB
/
callback.html
File metadata and controls
120 lines (109 loc) · 4.2 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
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SCrypt Authentication</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.container {
text-align: center;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
border-radius: 12px;
backdrop-filter: blur(10px);
}
.spinner {
width: 50px;
height: 50px;
border: 4px solid rgba(255, 255, 255, 0.3);
border-top-color: white;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 1rem;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.success { color: #4ade80; }
.error { color: #f87171; }
h2 { margin: 0 0 1rem; }
p { margin: 0.5rem 0; opacity: 0.9; }
</style>
</head>
<body>
<div class="container">
<div class="spinner" id="spinner"></div>
<h2 id="title">正在处理认证...</h2>
<p id="message">请稍候</p>
</div>
<script>
(function() {
const CHANNEL_NAME = 'scrypt-auth';
// 解析 URL 参数
function getUrlParams() {
const params = new URLSearchParams(window.location.search);
const data = {};
// 检查是否有 data 参数 (Base64 编码的 JSON)
const encodedData = params.get('data');
if (encodedData) {
try {
const jsonStr = atob(encodedData);
return JSON.parse(jsonStr);
} catch (e) {
console.error('Failed to decode data:', e);
return { error: 'Failed to decode authentication data' };
}
}
// 检查是否有错误
const error = params.get('error');
if (error) {
data.error = error;
data.reason = params.get('reason') || '';
return data;
}
return { error: 'No authentication data received' };
}
// 更新 UI
function updateUI(success, title, message) {
document.getElementById('spinner').style.display = 'none';
document.getElementById('title').textContent = title;
document.getElementById('title').className = success ? 'success' : 'error';
document.getElementById('message').textContent = message;
}
// 主逻辑
function main() {
const data = getUrlParams();
// 使用 BroadcastChannel 发送数据到主页面
try {
//const channel = new BroadcastChannel(CHANNEL_NAME);
//channel.postMessage(data);
//channel.close();
localStorage.setItem('scrypt-auth-result', JSON.stringify(data));
if (data.success) {
updateUI(true, '认证成功!', '窗口即将关闭...');
} else if (data.error) {
updateUI(false, '认证失败', data.error + (data.reason ? ': ' + data.reason : ''));
}
} catch (e) {
console.error('BroadcastChannel error:', e);
updateUI(false, '通信错误', '无法与主页面通信: ' + e.message);
}
// 延迟关闭窗口
setTimeout(() => {
window.close();
}, data.success ? 1000 : 3000);
}
main();
})();
</script>
</body>
</html>