-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
42 lines (35 loc) · 1.25 KB
/
init.js
File metadata and controls
42 lines (35 loc) · 1.25 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
document.addEventListener('DOMContentLoaded', function() {
loadState();
initializeUI();
initializeVariables();
AITerm.initState();
const keys = localStorage.getItem('keys');
if (keys) {
try {
const content = JSON.parse(keys);
KeyHub.setContent(content);
} catch (e) {
}
}
KeyHub.setOnUpdate(
() => localStorage.setItem('keys', JSON.stringify(KeyHub.keys))
)
// 添加到 HTML
// 如果url后面有?code=.... 那就是OpenRouter获取的新Key, 把他填入Bearer
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
fetch("https://openrouter.ai/api/v1/auth/keys", {
method: "POST",
body: JSON.stringify({
code: code,
})
}).then(response => response.json()).then(data => {
console.log(data);
state.bearer = data.key;
document.getElementById("bearer-input").value = state.bearer;
window.history.replaceState({}, document.title, window.location.pathname);
saveState();
})
}
})