-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
272 lines (233 loc) · 7.71 KB
/
Copy pathscript.js
File metadata and controls
272 lines (233 loc) · 7.71 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// 密码验证
const CORRECT_PASSWORD = 'F435261ox';
// API列表
const API_LIST = [
'AIzaSyD9YYMuYSjA94yvfzMxHIyrY8I2yUtDEes',
'AIzaSyAO4rIlFAtKLS42Fo1_UGZDf6AtPm9uZPA',
'AIzaSyA4DGWXOx3FIVOX6oN19Lekho13Wp-RzdY',
'AIzaSyBsO-PDuSJyl5ps1EsR5jKkGy1HWLrJ8wQ',
'AIzaSyDRPqOyzZ3hLg1t3yi9pUnhD-C_D3wtZoo',
'AIzaSyDSp1KHMoVRdzUR617QS9nfCVIRrxKyahQ',
'AIzaSyAAuizNRoBpx85UEJFb85ZWu3wdmjfLe1w',
'AIzaSyB17xQxtb1tiId7-3i_1rz_jpIjPLW2A-g',
'AIzaSyDu8ilySHdX4pw8tEWDmcoJa4eLEvEuefc',
'AIzaSyC1o7f8hkEyeG2UBLpAA1tavBwi_N1zo7c'
];
// 选择历史
let selectionHistory = [];
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
// 检查是否已经通过验证
if (localStorage.getItem('authenticated') === 'true') {
showMainScreen();
}
// 添加回车键支持
document.getElementById('passwordInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
checkPassword();
}
});
// 加载历史记录
loadHistory();
// 添加触摸反馈
addTouchFeedback();
});
// 检查密码
function checkPassword() {
const passwordInput = document.getElementById('passwordInput');
const errorMsg = document.getElementById('errorMsg');
const password = passwordInput.value.trim();
if (password === '') {
showError('请输入密码');
return;
}
if (password === CORRECT_PASSWORD) {
// 密码正确,保存验证状态
localStorage.setItem('authenticated', 'true');
showMainScreen();
// 清空输入框和错误信息
passwordInput.value = '';
errorMsg.textContent = '';
} else {
showError('密码错误,请重试');
passwordInput.value = '';
passwordInput.focus();
}
}
// 显示错误信息
function showError(message) {
const errorMsg = document.getElementById('errorMsg');
errorMsg.textContent = message;
errorMsg.style.display = 'block';
}
// 显示主界面
function showMainScreen() {
document.getElementById('passwordScreen').classList.add('hidden');
document.getElementById('mainScreen').classList.remove('hidden');
}
// 退出登录
function logout() {
if (confirm('确定要退出登录吗?')) {
// 清除验证状态
localStorage.removeItem('authenticated');
// 返回登录界面
document.getElementById('mainScreen').classList.add('hidden');
document.getElementById('passwordScreen').classList.remove('hidden');
// 清空密码输入框
document.getElementById('passwordInput').value = '';
document.getElementById('errorMsg').textContent = '';
// 清空结果显示
document.getElementById('result').classList.add('hidden');
}
}
// 随机选择API
function selectRandomAPI() {
const randomIndex = Math.floor(Math.random() * API_LIST.length);
const selectedAPI = API_LIST[randomIndex];
// 显示结果
document.getElementById('selectedAPI').textContent = selectedAPI;
document.getElementById('result').classList.remove('hidden');
// 添加到历史记录
addToHistory(selectedAPI);
// 按钮动画效果
const selectBtn = document.getElementById('selectBtn');
selectBtn.classList.add('success');
selectBtn.textContent = '✅ 已选择';
setTimeout(() => {
selectBtn.classList.remove('success');
selectBtn.textContent = '🎲 随机选择';
}, 2000);
}
// 添加到历史记录
function addToHistory(api) {
const timestamp = new Date().toLocaleString('zh-CN');
const historyItem = {
api: api,
time: timestamp
};
selectionHistory.unshift(historyItem);
// 只保留最近10条记录
if (selectionHistory.length > 10) {
selectionHistory = selectionHistory.slice(0, 10);
}
// 保存到本地存储
localStorage.setItem('apiHistory', JSON.stringify(selectionHistory));
// 更新显示
updateHistoryDisplay();
}
// 更新历史记录显示
function updateHistoryDisplay() {
const historyList = document.getElementById('historyList');
historyList.innerHTML = '';
if (selectionHistory.length === 0) {
historyList.innerHTML = '<p style="color: #999; text-align: center;">暂无选择记录</p>';
return;
}
selectionHistory.forEach(item => {
const historyItem = document.createElement('div');
historyItem.className = 'history-item';
historyItem.innerHTML = `
<div class="history-time">${item.time}</div>
<div class="history-api">${item.api}</div>
`;
historyList.appendChild(historyItem);
});
}
// 加载历史记录
function loadHistory() {
const savedHistory = localStorage.getItem('apiHistory');
if (savedHistory) {
try {
selectionHistory = JSON.parse(savedHistory);
updateHistoryDisplay();
} catch (e) {
console.error('加载历史记录失败:', e);
selectionHistory = [];
}
}
}
// 复制到剪贴板
function copyToClipboard() {
const selectedAPI = document.getElementById('selectedAPI').textContent;
if (navigator.clipboard && window.isSecureContext) {
// 使用现代 Clipboard API
navigator.clipboard.writeText(selectedAPI).then(() => {
showCopySuccess();
}).catch(() => {
fallbackCopy(selectedAPI);
});
} else {
// 降级方案
fallbackCopy(selectedAPI);
}
}
// 降级复制方案
function fallbackCopy(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed';
textArea.style.left = '-999999px';
textArea.style.top = '-999999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
showCopySuccess();
} catch (err) {
console.error('复制失败:', err);
alert('复制失败,请手动复制');
}
document.body.removeChild(textArea);
}
// 显示复制成功提示
function showCopySuccess() {
const copyBtn = document.getElementById('copyBtn');
const originalText = copyBtn.textContent;
copyBtn.textContent = '✅ 已复制';
copyBtn.classList.add('success');
setTimeout(() => {
copyBtn.textContent = originalText;
copyBtn.classList.remove('success');
}, 2000);
}
// 清除历史记录
function clearHistory() {
if (confirm('确定要清除所有历史记录吗?')) {
selectionHistory = [];
localStorage.removeItem('apiHistory');
updateHistoryDisplay();
}
}
// 添加触摸反馈
function addTouchFeedback() {
// 触摸反馈(移动端优化)
document.addEventListener('touchstart', function() {}, {passive: true});
// 防止双击缩放(移动端优化)
let lastTouchEnd = 0;
document.addEventListener('touchend', function(event) {
const now = (new Date()).getTime();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
}
// 添加键盘快捷键支持
document.addEventListener('keydown', function(e) {
// Ctrl/Cmd + Enter 快速选择
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
if (document.getElementById('mainScreen').classList.contains('hidden')) {
checkPassword();
} else {
selectRandomAPI();
}
}
// ESC 键退出
if (e.key === 'Escape') {
if (!document.getElementById('mainScreen').classList.contains('hidden')) {
logout();
}
}
});