-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
42 lines (40 loc) · 1.5 KB
/
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
33
34
35
36
37
38
39
40
41
42
document.addEventListener('DOMContentLoaded', function() {
const saveButton = document.getElementById('saveButton');
const appCodeInput = document.getElementById('appCodeInput');
const statusElement = document.getElementById('status');
// Load saved app code if it exists
try {
chrome.storage.local.get(['intercomAppCode'], function(result) {
if (chrome.runtime.lastError) {
console.error('Chrome runtime error:', chrome.runtime.lastError);
return;
}
if (result.intercomAppCode) {
appCodeInput.value = result.intercomAppCode;
}
});
} catch (error) {
console.error('Error accessing chrome API:', error);
}
saveButton.addEventListener('click', function() {
const appCode = appCodeInput.value.trim();
if (appCode) {
try {
chrome.storage.local.set({intercomAppCode: appCode}, function() {
if (chrome.runtime.lastError) {
statusElement.textContent = 'Error saving app code. Please try again.';
console.error('Chrome runtime error:', chrome.runtime.lastError);
} else {
statusElement.textContent = 'App code saved successfully!';
setTimeout(() => { window.close(); }, 1500);
}
});
} catch (error) {
console.error('Error accessing chrome API:', error);
statusElement.textContent = 'Error saving app code. Please try again.';
}
} else {
statusElement.textContent = 'Please enter a valid app code.';
}
});
});