-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
50 lines (46 loc) · 1.89 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
document.getElementById('options-form').addEventListener('submit', (event) => {
event.preventDefault();
const pattern = document.getElementById('pattern').value;
const apiKey = document.getElementById('apiKey').value;
const serviceName = document.getElementById('serviceName').value;
const enabled = document.getElementById('enabled').checked;
chrome.storage.sync.set({ pattern, apiKey, serviceName, enabled }, () => {
alert('Options saved!');
});
});
document.addEventListener('DOMContentLoaded', () => {
chrome.storage.sync.get(['pattern', 'apiKey', 'serviceName', 'enabled'], (items) => {
if (items.pattern) {
document.getElementById('pattern').value = items.pattern;
}
if (items.apiKey) {
document.getElementById('apiKey').value = items.apiKey;
}
if (items.serviceName) {
document.getElementById('serviceName').value = items.serviceName;
}
if (items.enabled !== undefined) {
document.getElementById('enabled').checked = items.enabled;
}
});
// Fetch current span counts
chrome.runtime.sendMessage({type: 'GET_CURRENT_SPAN_COUNTS'}, (response) => {
if (response) {
updateSpanCounts(response.spans, response.events);
}
});
});
function updateSpanCounts(spans, events) {
document.getElementById('span-count-display').textContent = `Spans: ${spans}`;
document.getElementById('span-event-count-display').textContent = `Span Events: ${events}`;
const engagements = Math.ceil((spans + events) / 100);
document.getElementById('engagements-display').textContent = `Engagements: ${engagements}`;
}
document.getElementById('start-new-session').addEventListener('click', () => {
chrome.runtime.sendMessage({ type: 'START_NEW_SESSION' });
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'UPDATE_SPAN_COUNT') {
updateSpanCounts(message.spans, message.events);
}
});