UTAS auto extend session

prevent session timeout in UTAS

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         UTAS auto extend session
// @namespace    https://fuwa.dev
// @version      0.1
// @description  prevent session timeout in UTAS
// @author       fuwa
// @match        https://utas.adm.u-tokyo.ac.jp/campusweb/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=u-tokyo.ac.jp
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  if (!document.getElementById('portaltimer')) return;
  if (typeof extendSession !== 'function') return;
  if (typeof session_time_out !== 'string') return;

  const timeout = parseFloat(session_time_out) * 60 * 1000;

  const chk = document.createElement('input');
  chk.type = 'checkbox';
  chk.checked = true;
  chk.onclick = (e) => { e.stopPropagation(); };
  // chk.onchange = update;

  const targ = document.querySelector('#portaltimer li.txt');
  targ.insertBefore(chk, targ.firstChild);

  const update = () => {
    if (!chk.checked) return;

    const t = timeout - (new Date().getTime() - session_last_acc_time.getTime());
    console.log(t / 1000);
    if (t < 10 * 60 * 1000) { // 10 min
      extendSession();
    }
  };
  setInterval(update, 10000);
  console.log(chk);
})();