Timer[works when entering the game]

Fain!

// ==UserScript==
// @name         Timer[works when entering the game]
// @namespace    http://tampermonkey.net/
// @version      2.0.0
// @description  Fain!
// @author       You
// @match        https://skap.io/*
// @grant        skap.io
// ==/UserScript==

document.addEventListener('keydown', e => {
  if (e.code === 'KeyD') {
    startTimer();
  }
});
let seconds = 0,
    mins = 0;

const timer = document.createElement('div');
timer.innerHTML = `00:00`;
timer.style.color = '#FE9400'
timer.style.position = 'fixed';
timer.style.left = '45%';
timer.style.top = '860px';
timer.style.fontSize = '70px';
document.body.appendChild(timer);

document.addEventListener('keydown', e => {
  if (e.code === 'KeyD') {
    startTimer();
  }
});
setInterval(updateTimer, 1000);

function updateTimer() {
    seconds += 1;
    if (seconds === 60) {
        mins += 1;
        seconds = 0;
    }

    timer.innerHTML = `${mins < 10 ? `0${mins}` : mins}:${seconds < 10 ? `0${seconds}` : seconds}`;
}