Files
WhisperLive/Audio-Transcription-Firefox/popup.js
T
2023-06-16 19:46:56 +05:30

38 lines
1.3 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function() {
var startButton = document.getElementById("startCapture");
var stopButton = document.getElementById("stopCapture");
startButton.addEventListener("click", function() {
browser.tabs.query({ active: true, currentWindow: true })
.then(function(tabs) {
browser.tabs.sendMessage(tabs[0].id, { action: "startCapture" });
toggleCaptureButtons(true);
})
.catch(function(error) {
console.error("Error sending startCapture message:", error);
});
});
stopButton.addEventListener("click", function() {
browser.tabs.query({ active: true, currentWindow: true })
.then(function(tabs) {
browser.tabs.sendMessage(tabs[0].id, { action: "stopCapture" })
.then(function(response) {
console.log(response);
toggleCaptureButtons(false);
})
.catch(function(error) {
console.error("Error sending stopCapture message:", error);
});
})
.catch(function(error) {
console.error("Error querying active tab:", error);
});
});
// Function to toggle the capture buttons
function toggleCaptureButtons(isCapturing) {
startButton.disabled = isCapturing;
stopButton.disabled = !isCapturing;
}
});