Keep ServiceNow alive

Simulates user activity on a webpage by refreshing the page to prevent it from logging out due to inactivity, with reset if user interacts

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         Keep ServiceNow alive
// @version      1
// @description  Simulates user activity on a webpage by refreshing the page to prevent it from logging out due to inactivity, with reset if user interacts
// @match        https://sparknz.service-now.com/now/nav/ui/classic/*
// @author       chaoscreater
// @grant        none
// @namespace    outlookalive.pureandapplied.com.au
// @license      GPL3
// ==/UserScript==

(function() {
    const timeOutMinutes = 5;
    var inactivityTimer;

    function resetInactivityTimer() {
        clearTimeout(inactivityTimer);
        inactivityTimer = setTimeout(function() {
            // Show popup
            const popup = document.createElement('div');
            popup.innerHTML = '<p>Reload is about to happen...</p>';
            popup.style.position = 'fixed';
            popup.style.top = '50%';
            popup.style.left = '50%';
            popup.style.transform = 'translate(-50%, -50%)';
            popup.style.backgroundColor = '#fff';
            popup.style.padding = '20px';
            popup.style.border = '1px solid #000';
            document.body.appendChild(popup);

            // Wait for 2 seconds
            setTimeout(function() {
                // Reload the page after 2 seconds
                console.log("Reloading due to inactivity");
                location.reload();
            }, 2000);
        }, timeOutMinutes * 60 * 1000); // Reload the page after 15 minutes of inactivity
    }

    // Reset the inactivity timer on user actions
    document.addEventListener("click", resetInactivityTimer);
    document.addEventListener("mousemove", resetInactivityTimer);
    document.addEventListener("keypress", resetInactivityTimer);

    // Initialize the timer
    resetInactivityTimer();
})();