UTAS auto extend session

prevent session timeout in UTAS

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
})();