-
Notifications
You must be signed in to change notification settings - Fork 7
/
popup.js
54 lines (48 loc) · 1.68 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
43
44
45
46
47
48
49
50
51
52
53
54
document.addEventListener('DOMContentLoaded', function() {
var openButton = document.getElementById('openButton');
var optionSelect = document.getElementById('optionSelect');
// Event listener for the Open button
openButton.addEventListener('click', function() {
var selectedOption = optionSelect.value;
const experiences = [
"/src/historymap/hm.html",
"/src/historymap/simple_html_tree/simple_tree.html"
]
activate_main_window(experiences[optionSelect.selectedIndex]);
});
// Event listener for the option select dropdown
optionSelect.addEventListener('change', function() {
var selectedOption = this.value;
console.log('Option changed to:', selectedOption);
// You can add more code here to handle the option change
});
});
function activate_main_window(main_window_filename){
// Construct the main_window URL
const targetURL = chrome.runtime.getURL(main_window_filename);
// Query tabs to find if any match the URL
chrome.tabs.query({}, (tabs) => {
let found = false;
for (const tab of tabs) {
if (tab.url === targetURL) {
found = true;
// Make the tab active within its window
chrome.tabs.update(tab.id, { active: true });
// Bring the window to the front
chrome.windows.update(tab.windowId, {
drawAttention: true,
focused: true,
});
break;
}
}
if (!found) {
// Create the main_window
chrome.windows.create({
url: chrome.runtime.getURL(main_window_filename),
//type: "panel", // As of 2023-10-31, panels are not supported and this creates a popup
type: "popup", // or panel
});
}
});
}