i've run into a problem that after i click out of my chrome extension popup it stops working. Its simple stopwatch which i want to still count the time after clicking out of window to do something in browser, i know that i have to execute the script somehow in the background.js but i just don't know how to so if anyone could help me with that issue and explain it to me i would be very greatful :) This is my popup.js file with working script.
var hours = 00;
var minutes = 00;
var seconds = 00;
var tens = 000;
var appendTens = document.getElementById("tens");
var appendSeconds = document.getElementById("seconds");
var appendMinutes = document.getElementById("minutes");
var appendHours = document.getElementById("hours");
var buttonStart = document.getElementById("start");
var buttonStop = document.getElementById("stop");
var buttonReset = document.getElementById("reset");
var interval;
function startTimer(){
tens++;
if (tens<9){
appendTens.innerHTML = "0" + tens;
}
if (tens>9){
appendTens.innerHTML = tens;
}
if (tens>99){
seconds++;
appendSeconds.innerHTML = "0" + seconds;
tens = 0;
appendTens.innerHTML = "0" + 0;
}
if (seconds>9){
appendSeconds.innerHTML = seconds;
}
if (seconds>59){
minutes++;
appendMinutes.innerHTML = "0" + minutes;
seconds = 0;
appendSeconds.innerHTML = "0" + 0;
}
if (minutes>9){
appendMinutes.innerHTML = minutes;
}
if (minutes>59){
hours++;
appendHours.innerHTML = "0" + hours;
minutes = 0;
appendMinutes.innerHTML = "0" + 0;
}
if (hours>9){
appendHours.innerHTML = hours;
}
}
buttonStart.onclick = function(){
if(interval) {
clearInterval(interval)
}
interval = setInterval(startTimer, 10);
}
buttonStop.onclick = function(){
clearInterval(interval);
}
buttonReset.onclick = function(){
clearInterval(interval);
tens = "00";
seconds = "00";
minutes = "00";
hours = "00";
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
appendMinutes.innerHTML = minutes;
appendHours.innerHTML = hours;
}