JavaScript function that runs in a closed window

Viewed 30

I'm trying to make a chronometer extension in Firefox. I have a function to count minutes and seconds, and it run backwards. The problem is: I call the function with a window.setInterval() method. So when the Firefox extension window is closed, the function stops. When the extension window is opened, it starts again.
I want to call the function so it will run even if the extension window is closed. This way I can use several tabs in Firefox and the chronometer will run along them.
Is there a way I can do this?

Here is my code, in JS:

let m = 25;
let s = 0;

let dm = 0;
let ds = 0;

function tomato() {

    if (s === 0) {
        m--;
        s = 59;
    }

    s--;

    if (s < 10) {
        ds = "0" + s.toString();
    } else {
        ds = s;
    }
    if (m < 10) {
        dm = "0" + m.toString();
    } else {
        dm = m;
    }
    document.getElementById("clock").innerHTML = dm + ":" + ds;
}

window.setInterval(tomato, 1000);
0 Answers
Related