-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
64 lines (58 loc) · 1.8 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
55
56
57
58
59
60
61
62
63
64
document.addEventListener("DOMContentLoaded", function () {
const dropzone = document.getElementById("dropzone");
const fileInput = document.getElementById("fileInput");
const statusDiv = document.getElementById("status");
// Function to handle the file
function handleFile(file) {
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
try {
const jsonConfig = JSON.parse(e.target.result);
chrome.runtime.sendMessage(
{ action: "importConfig", config: jsonConfig },
function (response) {
if (response.success) {
statusDiv.textContent = "Configuration imported successfully!";
} else {
statusDiv.textContent = "Error importing configuration.";
}
}
);
} catch (error) {
statusDiv.textContent = "Error parsing JSON file.";
}
};
reader.readAsText(file);
} else {
statusDiv.textContent = "No file selected.";
}
}
// Handle file selection
fileInput.addEventListener("change", function (e) {
const file = e.target.files[0];
handleFile(file);
});
// Handle drag and drop
dropzone.addEventListener("dragover", (e) => {
e.preventDefault();
e.stopPropagation();
dropzone.classList.add("highlight");
});
dropzone.addEventListener("dragleave", (e) => {
e.preventDefault();
e.stopPropagation();
dropzone.classList.remove("highlight");
});
dropzone.addEventListener("drop", (e) => {
e.preventDefault();
e.stopPropagation();
dropzone.classList.remove("highlight");
const file = e.dataTransfer.files[0];
handleFile(file);
});
// Handle click to select file
dropzone.addEventListener("click", () => {
fileInput.click();
});
});