Hi,
I’m developing a basic timer popup and I want the user to be able to set a time and the popup to countdown from that time. I’ve been using this but without much success:
function timeInMinutesLeft(time){
let timeSetByUser=(time*60);//converting to seconds
let start=Date.now();
let elapsed = (Date.now() - start)/1000;//time elapsed in seconds
let timeLeft = Math.round(timeSetByUser - elapsed)
document.getElementById(“timeLeft”).innerHTML = timeLeft;
return timeLeft;
}
function timer(tabs) {
let timesUp=False;
let timeInput=document.getElementById(‘timerValue’);
let timeInputValue=timeInput.value();
timeLeft=timeInputValue;
while(timeLeft!=0){
x=timeInMinutesLeft(timeLeft);
timeLeft=x;
}
if(timeLeft==0){
timesUp=True;
}
if(timesUp==True){
browser.tabs.sendMessage(tabs[0].id, {
command: “timesup”
});
}
}
Any help is appreciated.