forked from qunash/gpt-3_chrome_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
32 lines (25 loc) · 1021 Bytes
/
popup.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
document.addEventListener('DOMContentLoaded', function() {
var open_api_keys = document.getElementById('open_api_keys');
open_api_keys.addEventListener('click', function() {
chrome.tabs.create({url: 'https://beta.openai.com/account/api-keys'});
});
var saveButton = document.getElementById('save');
saveButton.addEventListener('click', function() {
var api_key = document.getElementById('api_key').value;
chrome.storage.sync.set({
api_key: api_key
});
window.close();
});
document.getElementById('api_key').focus();
// on ctrl+enter, click save button
document.addEventListener('keydown', function(e) {
if(e.ctrlKey && e.key == "Enter") {
saveButton.click();
}
});
});
// restore settings on page load:
chrome.storage.sync.get(['api_key', 'temperature', 'max_tokens'], function(result) {
document.getElementById('api_key').value = result.api_key === undefined ? '' : result.api_key;
});