forked from buildspace/gpt3-writer-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (37 loc) · 1.24 KB
/
index.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
const checkForKey = () => {
return new Promise((resolve, reject) => {
chrome.storage.local.get(['openai-key'], (result) => {
resolve(result['openai-key']);
});
});
};
const encode = (input) => {
return btoa(input);
};
const saveKey = () => {
const input = document.getElementById('key_input');
if (input) {
const { value } = input;
// Encode String
const encodedValue = encode(value);
// Save to google storage
chrome.storage.local.set({ 'openai-key': encodedValue }, () => {
document.getElementById('key_needed').style.display = 'none';
document.getElementById('key_entered').style.display = 'block';
});
}
};
const changeKey = () => {
document.getElementById('key_needed').style.display = 'block';
document.getElementById('key_entered').style.display = 'none';
};
document.getElementById('save_key_button').addEventListener('click', saveKey);
document
.getElementById('change_key_button')
.addEventListener('click', changeKey);
checkForKey().then((response) => {
if (response) {
document.getElementById('key_needed').style.display = 'none';
document.getElementById('key_entered').style.display = 'block';
}
});