CleverTap session extender

Protects against irritating and dangerously short session inactivity timeouts, which can lead to losing progress when editing campaigns.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         CleverTap session extender
// @version      1.0
// @description  Protects against irritating and dangerously short session inactivity timeouts, which can lead to losing progress when editing campaigns.
// @author       Christopher Orr <chris@website>
// @website      https://klima.com/
// @namespace    https://klima.com/
// @license      MIT
// @match        https://*.dashboard.clevertap.com/*
// @icon         https://www.google.com/s2/favicons?sz=128&domain=clevertap.com
// @run-at       document-idle
// @grant        GM_xmlhttpRequest
// @connect      self
// ==/UserScript==

(function() {
    'use strict';

    const cleverTapRefresh = () => {
        console.log('UserScript: Keeping CleverTap session alive in the background…');

        // Fetch the top-level URL every 5–10 minutes, i.e. much more often than the ~45-minute session inactivity timeout.
        // This redirects to the main dashboard page, and so should prolong the current logged-in session
        GM_xmlhttpRequest({ url: '/' });

        // Repeat so long as this tab is open
        const intervalMs = 5 * 60 * 1000;
        return setTimeout(cleverTapRefresh, intervalMs + (intervalMs * Math.random()));
    };

    cleverTapRefresh();
})();