-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
78 lines (68 loc) · 2.93 KB
/
Copy pathpopup.js
File metadata and controls
78 lines (68 loc) · 2.93 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
document.addEventListener("DOMContentLoaded", () => {
const apiKeyInput = document.getElementById("apiKey");
const convertButton = document.getElementById("convertCaptions");
const startApplyButton = document.getElementById("startApply");
const endApplyButton = document.getElementById("endApply");
// Load saved API key if exists
chrome.storage.local.get("geminiApiKey", (data) => {
if (data.geminiApiKey) {
apiKeyInput.value = data.geminiApiKey;
console.log("Loaded API Key from storage:", data.geminiApiKey);
}
});
// Save API key when input changes
apiKeyInput.addEventListener("change", () => {
const key = apiKeyInput.value.trim();
if (key) {
chrome.storage.local.set({ geminiApiKey: key });
console.log("API Key saved:", key);
}
});
// Convert captions button
convertButton.addEventListener("click", () => {
// Save the API key first
const key = apiKeyInput.value.trim();
if (!key) {
alert("Please enter a Gemini API Key first!");
return;
}
chrome.storage.local.set({ geminiApiKey: key }, () => {
console.log("API Key set for conversion:", key);
// Send message to convert captions
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (!tabs[0].url.includes("app.submagic.co")) {
alert("⚠️ Please open Submagic first!");
console.error("Submagic not open in active tab");
return;
}
console.log("Sending message to convert captions");
chrome.tabs.sendMessage(tabs[0].id, { action: "convertCaptions" });
});
});
});
// Start applying captions
startApplyButton.addEventListener("click", () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (!tabs[0].url.includes("app.submagic.co")) {
alert("⚠️ Please open Submagic first!");
console.error("Submagic not open in active tab");
return;
}
// Hide start button, show end button
startApplyButton.style.display = "none";
endApplyButton.style.display = "block";
console.log("Start applying captions");
chrome.tabs.sendMessage(tabs[0].id, { action: "startApplyCaptions" });
});
});
// End applying captions
endApplyButton.addEventListener("click", () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
// Show start button, hide end button
startApplyButton.style.display = "block";
endApplyButton.style.display = "none";
console.log("End applying captions");
chrome.tabs.sendMessage(tabs[0].id, { action: "endApplyCaptions" });
});
});
});