Ubik Academy - automatically extend lab time

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

  1. // ==UserScript==
  2. // @name Ubik Academy - automatically extend lab time
  3. // @version 0.3
  4. // @namespace nil
  5. // @author nil
  6. // @grant none
  7. // @description [EN] Extend the time the lab is usable when the timer is below 10 minutes
  8. // @include https://cyberkube.app/?token=*
  9. // @license GPLv3
  10. // ==/UserScript==
  11.  
  12. (function nil_greasemonkey_ubik_extendlab() {
  13. "use strict";
  14. function checkTimerAndPotentiallyExtendLab() {
  15. let elt = document.getElementById("timer");
  16. // "01h : 53m : 35s"
  17. if (!elt || 9 >= elt.innerText.length) return;
  18. let remaining_seconds = elt.innerText
  19. .replace(/[hms\s]/g, "")
  20. .split(':')
  21. .map(Number)
  22. .reverse()
  23. .reduce((acc, elt, idx) => acc + elt * 60**idx, 0);
  24. // do nothing if more than 10 minutes left (600 seconds)
  25. if (600 <= remaining_seconds) return;
  26.  
  27. let extendBtn = document.getElementById("extend-btn");
  28. if (!extendBtn) { console.log("#extend-btn element not found"); return; }
  29.  
  30. console.log("clicked the extend lab button!");
  31. extendBtn.click();
  32.  
  33. // wait 20 s then refresh the page
  34. window.setTimeout(() => location.reload(), 20000);
  35. }
  36. window.setInterval(checkTimerAndPotentiallyExtendLab, 60000);
  37. })();