mirror of
https://github.com/michivonah/click-guide.git
synced 2025-12-22 22:16:28 +01:00
adding start/stop/pause/resume functionality
This commit is contained in:
parent
b1c9b26e23
commit
cd2de15b2b
5 changed files with 104 additions and 49 deletions
|
|
@ -1,11 +1,22 @@
|
|||
// Script for Popup
|
||||
|
||||
// load recording status
|
||||
let isRecording = false;
|
||||
chrome.storage.local.get("recording", (data) => {
|
||||
isRecording = data.recording || false;
|
||||
console.log(data);
|
||||
updateRecordingLabel(isRecording);
|
||||
});
|
||||
|
||||
// define buttons
|
||||
const toggleRecordingBtn = document.getElementById("toggleRecording");
|
||||
const exportBtn = document.getElementById("exportBtn");
|
||||
|
||||
toggleRecordingBtn.addEventListener('click', () => {
|
||||
console.log("Button clicked");
|
||||
chrome.runtime.sendMessage({action: 'triggerName'});
|
||||
//if(isRecording) chrome.runtime.sendMessage({action: "clearGuide"});
|
||||
isRecording = !isRecording; // toggle status
|
||||
updateRecordingLabel(isRecording); // update label
|
||||
chrome.storage.local.set({ recording: isRecording }); // save status
|
||||
});
|
||||
|
||||
exportBtn.addEventListener('click', () => {
|
||||
|
|
@ -18,6 +29,24 @@ exportBtn.addEventListener('click', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// update button label
|
||||
function updateRecordingLabel(bool){
|
||||
let startLabel = "Start recording";
|
||||
|
||||
try{
|
||||
chrome.runtime.sendMessage({
|
||||
action: "guideLenght"
|
||||
}, (response) => {
|
||||
if(response.stepCount !== 0) startLabel = "Resume";
|
||||
toggleRecordingBtn.textContent = bool ? "Pause/Stop" : startLabel;
|
||||
});
|
||||
}
|
||||
catch(error){
|
||||
console.error(`Error while updating recording button label: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// export guide as json
|
||||
function exportJSON(object, filename){
|
||||
const json = JSON.stringify(object, null, 2);
|
||||
|
||||
|
|
@ -30,4 +59,7 @@ function exportJSON(object, filename){
|
|||
link.click();
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
// clear guide
|
||||
chrome.runtime.sendMessage({action: "clearGuide"});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue