Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Stopwatch chrome extension to work after clicking out of popup.html

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;
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda