-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
86 lines (82 loc) · 3.25 KB
/
options.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
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
document.getElementById('save').addEventListener('click', function() {
const firecrawlKey = document.getElementById('firecrawlKey').value.trim();
const openaiKey = document.getElementById('openaiKey').value.trim();
const maxDepth = parseInt(document.getElementById('maxDepth').value.trim()) || 3;
const limit = parseInt(document.getElementById('limit').value.trim()) || 50;
const maxContentLength = parseInt(document.getElementById('maxContentLength').value.trim()) || 250000;
const timeout = parseInt(document.getElementById('timeout').value.trim()) || 20000;
const allowBackwardLinks = document.getElementById('allowBackwardLinks').value === 'true';
const waitFor = parseInt(document.getElementById('waitFor').value.trim()) || 2000;
const model = document.getElementById('model').value || 'gpt-4o-mini';
// validate inputs
if (isNaN(maxContentLength) || maxContentLength < 1 || maxContentLength > 500000) {
alert('Please enter a valid max characters value (1 - 500,000).');
return;
}
if (isNaN(timeout) || timeout < 1) {
alert('Please enter a valid timeout in milliseconds (minimum 1).');
return;
}
if (isNaN(waitFor) || waitFor < 0) {
alert('Please enter a valid wait time in milliseconds (minimum 0).');
return;
}
chrome.storage.local.set({
firecrawlKey: firecrawlKey,
openaiKey: openaiKey,
maxDepth: maxDepth,
limit: limit,
maxContentLength: maxContentLength,
timeout: timeout,
allowBackwardLinks: allowBackwardLinks,
waitFor: waitFor,
model: model
}, function() {
const successMessage = document.getElementById('successMessage');
successMessage.style.display = 'block';
setTimeout(() => {
successMessage.style.display = 'none';
}, 3000);
});
});
document.addEventListener('DOMContentLoaded', function() {
chrome.storage.local.get([
'firecrawlKey',
'openaiKey',
'maxDepth',
'limit',
'maxContentLength',
'timeout',
'allowBackwardLinks',
'waitFor',
'model'
], function(result) {
if (result.firecrawlKey) {
document.getElementById('firecrawlKey').value = result.firecrawlKey;
}
if (result.openaiKey) {
document.getElementById('openaiKey').value = result.openaiKey;
}
if (result.maxDepth) {
document.getElementById('maxDepth').value = result.maxDepth;
}
if (result.limit) {
document.getElementById('limit').value = result.limit;
}
if (result.maxContentLength) {
document.getElementById('maxContentLength').value = result.maxContentLength;
}
if (result.timeout) {
document.getElementById('timeout').value = result.timeout;
}
if (typeof result.allowBackwardLinks !== 'undefined') {
document.getElementById('allowBackwardLinks').value = result.allowBackwardLinks.toString();
}
if (result.waitFor) {
document.getElementById('waitFor').value = result.waitFor;
}
if (result.model) {
document.getElementById('model').value = result.model;
}
});
});