-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
72 lines (46 loc) · 2.08 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
65
66
67
68
69
70
71
72
// Rendering elements onto the popup window depending on the current web page
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTab = tabs[0];
if (currentTab.url.includes("https://chat.openai.com/c/")) {
document.getElementById("generate-pdf-button").classList.remove("display-hidden");
document.getElementById("generate-pdf-button").classList.add("display-button");
} else {
const other_webpage_message = document.getElementById("other-tab-message");
other_webpage_message.classList.remove("display-hidden");
other_webpage_message.classList.add("other-tab");
}
});
const displayMessage = document.getElementById("message");
const generatePDFbutton = document.getElementById("generate-pdf-button");
const downloadPDFbutton = document.getElementById("download-pdf-button");
generatePDFbutton.addEventListener("click", () => {
generatePDFbutton.classList.remove("display-button");
generatePDFbutton.classList.add("display-hidden");
displayMessage.classList.remove("display-hidden");
displayMessage.classList.add("message");
setTimeout(() => {
displayMessage.innerText = "Generating PDF..."
}
,1000)
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { action: "generatePDF" }, (response) => {
if (response && response.reply === "pdfGenerated") {
setTimeout(() => {
displayMessage.classList.remove("message");
displayMessage.classList.add("display-hidden");
downloadPDFbutton.classList.remove("display-hidden");
downloadPDFbutton.classList.add("display-button");
}, 2000)
} else if (response && response.reply === "error") {
setTimeout (() => {
displayMessage.innerText = "Conversation wasn't loaded properly. Try again!"
}, 1500);
}
});
});
});
downloadPDFbutton.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { action: "downloadPDF" });
});
})