UTAS auto extend session

prevent session timeout in UTAS

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

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

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.

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

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