tiziodcaio / Extend Cookie Expiry for Webeep

// ==UserScript==
// @name         Extend Cookie Expiry for Webeep
// @version      1.0
// @description  Estende la scadenza di un cookie chiamato per il sito webeep.polimi.it
// @author       tiziodcaio
// @match        *://webeep.polimi.it/*
// @grant        none
// @copyright 2025, tiziodcaio (https://openuserjs.org/users/tiziodcaio)
// @updateURL https://openuserjs.org/meta/tiziodcaio/Extend_Cookie_Expiry_for_Webeep.meta.js
// @downloadURL https://openuserjs.org/src/scripts/tiziodcaio/Extend_Cookie_Expiry_for_Webeep.user.js
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  const cookieName = "MoodleSession";
  const extendDays = 7;

  function getCookie(name) {
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2) return parts.pop().split(';').shift();
  }

  function setCookie(name, value, days) {
    let expires = "";
    if (days) {
      const date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
      expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "") + expires + "; path=/";
  }

  const cookieValue = getCookie(cookieName);
  if (cookieValue) {
    setCookie(cookieName, cookieValue, extendDays);
  }
  else {
    console.error("Cookie " + cookieName + " not found.");
  }
})();