-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.js
More file actions
169 lines (142 loc) · 6.14 KB
/
Copy pathsettings.js
File metadata and controls
169 lines (142 loc) · 6.14 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
document.addEventListener('DOMContentLoaded', () => {
// Load saved settings
loadSettings();
// Save button handler
document.getElementById('saveSettings').addEventListener('click', saveSettings);
// Toggle advanced settings
const showAdvancedCheckbox = document.getElementById('showAdvanced');
const advancedSettings = document.getElementById('advancedSettings');
showAdvancedCheckbox.addEventListener('change', () => {
advancedSettings.style.display = showAdvancedCheckbox.checked ? 'block' : 'none';
});
// Update temperature display value
const temperatureInput = document.getElementById('temperature');
const temperatureValue = document.getElementById('temperatureValue');
temperatureInput.addEventListener('input', () => {
temperatureValue.textContent = temperatureInput.value;
});
// Toggle control for checkboxes
const includeFramesCheckbox = document.getElementById('includeFrames');
const toggleLabel = includeFramesCheckbox.nextElementSibling;
includeFramesCheckbox.addEventListener('change', () => {
toggleLabel.textContent = includeFramesCheckbox.checked ? 'Enabled' : 'Disabled';
});
});
// Load saved settings from Chrome storage
async function loadSettings() {
const apiKeyInput = document.getElementById('groqApiKey');
const modelSelect = document.getElementById('defaultModel');
const maxTokensInput = document.getElementById('maxTokens');
const temperatureInput = document.getElementById('temperature');
const temperatureValue = document.getElementById('temperatureValue');
const fetchLimitInput = document.getElementById('fetchLimit');
const timeRangeSelect = document.getElementById('timeRange');
const includeFramesCheckbox = document.getElementById('includeFrames');
const defaultContentTypeSelect = document.getElementById('defaultContentType');
const showAdvancedCheckbox = document.getElementById('showAdvanced');
const advancedSettings = document.getElementById('advancedSettings');
const toggleLabel = includeFramesCheckbox.nextElementSibling;
try {
const { groqApiKey, defaultModel, maxTokens, temperature, fetchLimit, timeRange, includeFrames, defaultContentType, showAdvanced } =
await chrome.storage.sync.get(['groqApiKey', 'defaultModel', 'maxTokens', 'temperature', 'fetchLimit', 'timeRange', 'includeFrames', 'defaultContentType', 'showAdvanced']);
if (groqApiKey) {
// Mask API key for display
apiKeyInput.value = groqApiKey.substring(0, 4) + '...' + groqApiKey.substring(groqApiKey.length - 4);
apiKeyInput.dataset.original = groqApiKey;
// When input is focused, show the real API key
apiKeyInput.addEventListener('focus', function() {
if (this.dataset.original) {
this.value = this.dataset.original;
}
});
}
if (defaultModel) {
modelSelect.value = defaultModel;
}
if (maxTokens) {
maxTokensInput.value = maxTokens;
}
if (temperature !== undefined) {
temperatureInput.value = temperature;
temperatureValue.textContent = temperature;
}
if (fetchLimit) {
fetchLimitInput.value = fetchLimit;
}
if (timeRange) {
timeRangeSelect.value = timeRange;
}
if (includeFrames !== undefined) {
includeFramesCheckbox.checked = includeFrames;
toggleLabel.textContent = includeFrames ? 'Enabled' : 'Disabled';
}
if (defaultContentType) {
defaultContentTypeSelect.value = defaultContentType;
}
if (showAdvanced) {
showAdvancedCheckbox.checked = showAdvanced;
advancedSettings.style.display = showAdvanced ? 'block' : 'none';
}
} catch (error) {
console.error('Failed to load settings:', error);
showStatus('Failed to load settings: ' + error.message, 'error');
}
}
// Save settings to Chrome storage
async function saveSettings() {
const apiKeyInput = document.getElementById('groqApiKey');
const modelSelect = document.getElementById('defaultModel');
const maxTokensInput = document.getElementById('maxTokens');
const temperatureInput = document.getElementById('temperature');
const fetchLimitInput = document.getElementById('fetchLimit');
const timeRangeSelect = document.getElementById('timeRange');
const includeFramesCheckbox = document.getElementById('includeFrames');
const defaultContentTypeSelect = document.getElementById('defaultContentType');
const showAdvancedCheckbox = document.getElementById('showAdvanced');
const apiKey = apiKeyInput.dataset.original || apiKeyInput.value;
const model = modelSelect.value;
const maxTokens = parseInt(maxTokensInput.value);
const temperature = parseFloat(temperatureInput.value);
const fetchLimit = parseInt(fetchLimitInput.value);
const timeRange = timeRangeSelect.value;
const includeFrames = includeFramesCheckbox.checked;
const defaultContentType = defaultContentTypeSelect.value;
const showAdvanced = showAdvancedCheckbox.checked;
// Simple validation
if (!apiKey) {
showStatus('Please enter your Groq API key', 'error');
return;
}
if (isNaN(fetchLimit) || fetchLimit < 5 || fetchLimit > 100) {
showStatus('Please enter a valid fetch limit between 5 and 100', 'error');
return;
}
try {
await chrome.storage.sync.set({
groqApiKey: apiKey,
defaultModel: model,
maxTokens: maxTokens,
temperature: temperature,
fetchLimit,
timeRange,
includeFrames,
defaultContentType,
showAdvanced
});
showStatus('Settings saved successfully!', 'success');
} catch (error) {
console.error('Failed to save settings:', error);
showStatus('Failed to save settings: ' + error.message, 'error');
}
}
// Display status message
function showStatus(message, type = 'success') {
const statusDiv = document.getElementById('status');
statusDiv.textContent = message;
statusDiv.className = 'status ' + type;
// Clear status after 3 seconds
setTimeout(() => {
statusDiv.textContent = '';
statusDiv.className = 'status';
}, 3000);
}