UTAS auto extend session

prevent session timeout in UTAS

  1. // ==UserScript==
  2. // @name UTAS auto extend session
  3. // @namespace https://fuwa.dev
  4. // @version 0.1
  5. // @description prevent session timeout in UTAS
  6. // @author fuwa
  7. // @match https://utas.adm.u-tokyo.ac.jp/campusweb/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=u-tokyo.ac.jp
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. if (!document.getElementById('portaltimer')) return;
  16. if (typeof extendSession !== 'function') return;
  17. if (typeof session_time_out !== 'string') return;
  18.  
  19. const timeout = parseFloat(session_time_out) * 60 * 1000;
  20.  
  21. const chk = document.createElement('input');
  22. chk.type = 'checkbox';
  23. chk.checked = true;
  24. chk.onclick = (e) => { e.stopPropagation(); };
  25. // chk.onchange = update;
  26.  
  27. const targ = document.querySelector('#portaltimer li.txt');
  28. targ.insertBefore(chk, targ.firstChild);
  29.  
  30. const update = () => {
  31. if (!chk.checked) return;
  32.  
  33. const t = timeout - (new Date().getTime() - session_last_acc_time.getTime());
  34. console.log(t / 1000);
  35. if (t < 10 * 60 * 1000) { // 10 min
  36. extendSession();
  37. }
  38. };
  39. setInterval(update, 10000);
  40. console.log(chk);
  41. })();