Ubik Academy - automatically extend lab time

[EN] Extend the time the lab is usable when the timer is below 10 minutes

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           Ubik Academy - automatically extend lab time
// @version        0.3
// @namespace      nil
// @author         nil
// @grant          none
// @description    [EN] Extend the time the lab is usable when the timer is below 10 minutes
// @include        https://cyberkube.app/?token=*
// @license        GPLv3
// ==/UserScript==

(function nil_greasemonkey_ubik_extendlab() {
  "use strict";
  function checkTimerAndPotentiallyExtendLab() {
    let elt = document.getElementById("timer");
    // "01h : 53m : 35s"
    if (!elt || 9 >= elt.innerText.length) return;
    let remaining_seconds = elt.innerText
				.replace(/[hms\s]/g, "")
         		        .split(':')
    				.map(Number)
    				.reverse()
    				.reduce((acc, elt, idx) => acc + elt * 60**idx, 0);
    // do nothing if more than 10 minutes left (600 seconds)
    if (600 <= remaining_seconds) return;

    let extendBtn = document.getElementById("extend-btn");
    if (!extendBtn) { console.log("#extend-btn element not found"); return; }

    console.log("clicked the extend lab button!");
    extendBtn.click();

    // wait 20 s then refresh the page
    window.setTimeout(() => location.reload(), 20000);
  }
  
  window.setInterval(checkTimerAndPotentiallyExtendLab, 60000);
})();