-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
112 lines (97 loc) · 4.26 KB
/
popup.js
File metadata and controls
112 lines (97 loc) · 4.26 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
document.addEventListener('DOMContentLoaded', function() {
const statusDiv = document.getElementById('status');
const statusText = document.getElementById('statusText');
const browserAPI = typeof browser !== 'undefined' ? browser : chrome;
loadConfiguration();
setupToggleListeners();
browserAPI.tabs.query({active: true, currentWindow: true}, function(tabs) {
const currentTab = tabs[0];
const url = currentTab.url;
if (url.includes('wise.com')) {
statusText.textContent = 'Active on Wise';
statusDiv.className = 'status active';
} else {
statusText.textContent = 'Not on a Wise page';
statusDiv.className = 'status inactive';
}
}); function loadConfiguration() {
browserAPI.storage.sync.get(['wiseToolsConfig'], function(result) {
const config = result.wiseToolsConfig || {
copyId: true,
searchById: true,
hcbSearch: false,
airtable: false,
airtableUrl: ''
};
document.getElementById('copyIdToggle').checked = config.copyId;
document.getElementById('searchByIdToggle').checked = config.searchById;
document.getElementById('hcbSearchToggle').checked = config.hcbSearch;
document.getElementById('airtableToggle').checked = config.airtable;
document.getElementById('airtableUrl').value = config.airtableUrl || '';
// Show/hide Airtable config based on toggle state
toggleAirtableConfig(config.airtable);
});
} function setupToggleListeners() {
const copyIdToggle = document.getElementById('copyIdToggle');
const searchByIdToggle = document.getElementById('searchByIdToggle');
const hcbSearchToggle = document.getElementById('hcbSearchToggle');
const airtableToggle = document.getElementById('airtableToggle');
const saveAirtableConfig = document.getElementById('saveAirtableConfig');
copyIdToggle.addEventListener('change', function() {
saveConfiguration();
notifyContentScript();
});
searchByIdToggle.addEventListener('change', function() {
saveConfiguration();
notifyContentScript();
});
hcbSearchToggle.addEventListener('change', function() {
saveConfiguration();
notifyContentScript();
});
airtableToggle.addEventListener('change', function() {
toggleAirtableConfig(this.checked);
saveConfiguration();
notifyContentScript();
});
saveAirtableConfig.addEventListener('click', function() {
saveConfiguration();
showSaveSuccess();
});
} function saveConfiguration() {
const config = {
copyId: document.getElementById('copyIdToggle').checked,
searchById: document.getElementById('searchByIdToggle').checked,
hcbSearch: document.getElementById('hcbSearchToggle').checked,
airtable: document.getElementById('airtableToggle').checked,
airtableUrl: document.getElementById('airtableUrl').value
};
browserAPI.storage.sync.set({ wiseToolsConfig: config });
} function notifyContentScript() {
browserAPI.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0] && tabs[0].url.includes('wise.com')) {
browserAPI.tabs.sendMessage(tabs[0].id, {
action: 'configurationChanged'
});
}
});
}
function toggleAirtableConfig(show) {
const configDiv = document.getElementById('airtableConfig');
if (show) {
configDiv.classList.remove('hidden');
} else {
configDiv.classList.add('hidden');
}
}
function showSaveSuccess() {
const saveBtn = document.getElementById('saveAirtableConfig');
const originalText = saveBtn.textContent;
saveBtn.textContent = 'Saved!';
saveBtn.style.background = '#28a745';
setTimeout(() => {
saveBtn.textContent = originalText;
saveBtn.style.background = '#00b9ff';
}, 2000);
}
});