UTAS auto extend session

prevent session timeout in UTAS

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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