-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (31 loc) · 1.04 KB
/
main.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
import Papa from "papaparse";
const loader = document.querySelector(".loader");
document
.querySelector(".csv-input")
.addEventListener("change", function (event) {
const file = event.target.files[0];
if (file) {
loader.style.display = "block";
Papa.parse(file, {
header: false, // Disable automatic header detection
complete: function (results) {
const parsedData = results.data;
// Remove the first element if it's empty (which can happen if the CSV file ends with a newline)
if (
parsedData.length > 0 &&
parsedData[0].length === 1 &&
parsedData[0][0] === ""
) {
parsedData.shift();
}
// Send the parsed data to the background script
chrome.runtime.sendMessage({ action: "uploadCSV", data: parsedData });
},
});
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "eventsCreated") {
loader.textContent = "Completed ✅";
}
});