Greasy Fork is available in English.

Fineco: Refresh periodically the currrent page

This script refreshes periodically the current page in order to avoid (after 4 min.) the warning modal popup and (after 5 min.) the disconnection.

// ==UserScript==
// @name           Fineco: Refresh periodically the currrent page
// @name:it        Fineco: Aggiorna periodicamente la pagina corrente
// @description    This script refreshes periodically the current page in order to avoid (after 4 min.) the warning modal popup and (after 5 min.) the disconnection.
// @description:it Questo script aggiorna periodicamente la pagina corrente per evitare che (dopo 4 min.) venga visualizzato il popup modale di avviso e che (dopo 5 min.) venga eseguita la disconnessione.
// @match          https://finecobank.com/*
// @grant          none
//// @run-at         document-start
// @version        1.0.5
// @author         Cyrano68
// @license        MIT
// @namespace https://greasyfork.org/users/788550
// ==/UserScript==

(function()
{
    "use strict";

    function console_log(text)
    {
        //let now = new Date().toISOString();
        let now = new Date().toLocaleString();
        console.log(`${now} ${text}`);
    }

    console_log("==> Fineco_RefreshPage: HELLO! Loading script...");

    document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
    window.addEventListener("load", onWindowLoaded);

    let timerId = 0;
    let interval_ms = 10000; // 10s
    let refreshInterval_ms = (3*60 + 45)*1000; // 3m45s ---> less than 4m, in order to avoid the modal popup.
    let startTime;

    function onDOMContentLoaded()
    {
        console_log(`==> Fineco_RefreshPage: onDOMContentLoaded - document.readyState=${document.readyState}`);
        // DO NOTHING!
    }

    function onWindowLoaded()
    {
        console_log(`==> Fineco_RefreshPage: onWindowLoaded - document.readyState=${document.readyState}`);
        // Start a timer that periodically checks if it's time to refresh the current page.
        console_log(`==> Fineco_RefreshPage: onWindowLoaded - STARTING TIMER 'checkRefreshPage' - interval_ms=${interval_ms}`);
        timerId = setInterval(checkRefreshPage, interval_ms);
        console_log(`==> Fineco_RefreshPage: onWindowLoaded - TIMER STARTED - timerId=${timerId}`);
        console_log(`==> Fineco_RefreshPage: onWindowLoaded - wait ${interval_ms/1e3} secs...`);
        startTime = new Date();
    }

    function checkRefreshPage()
    {
        let currTime = new Date();
        let elapsedTime_ms = currTime - startTime;
        console_log(`==> Fineco_RefreshPage: checkRefreshPage - elapsedTime_ms=${elapsedTime_ms} (${elapsedTime_ms/1e3} secs)`);
        if (elapsedTime_ms >= refreshInterval_ms)
        {
            clearInterval(timerId);
            console_log(`==> Fineco_RefreshPage: checkRefreshPage - TIMER STOPPED - timerId=${timerId}`);
            timerId = 0;
            console_log("==> Fineco_RefreshPage: checkRefreshPage - REFRESH PAGE");
            location.reload();  // Refresh the current page
        }
        else if (elapsedTime_ms > (refreshInterval_ms - interval_ms))
        {
            clearInterval(timerId);
            console_log(`==> Fineco_RefreshPage: checkRefreshPage - TIMER STOPPED - timerId=${timerId}`);
            timerId = 0;
            let shortInterval_ms = refreshInterval_ms - elapsedTime_ms;
            console_log(`==> Fineco_RefreshPage: checkRefreshPage - STARTING TIMER 'checkRefreshPage' - shortInterval_ms=${shortInterval_ms}`);
            timerId = setInterval(checkRefreshPage, shortInterval_ms);
            console_log(`==> Fineco_RefreshPage: checkRefreshPage - TIMER STARTED - timerId=${timerId}`);
            console_log(`==> Fineco_RefreshPage: checkRefreshPage - wait ${shortInterval_ms/1e3} secs...`);
        }
        else
        {
            console_log(`==> Fineco_RefreshPage: checkRefreshPage - wait ${interval_ms/1e3} secs...`);
            // DO NOTHING!
        }
    }

    console_log("==> Fineco_RefreshPage: Script loaded");
})();