Skip to content

Instantly share code, notes, and snippets.

@schu
Created January 19, 2021 15:42
Show Gist options
  • Select an option

  • Save schu/55a89e539a9e146ecee21110f3c7d7e2 to your computer and use it in GitHub Desktop.

Select an option

Save schu/55a89e539a9e146ecee21110f3c7d7e2 to your computer and use it in GitHub Desktop.

Revisions

  1. schu renamed this gist Jan 19, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. schu created this gist Jan 19, 2021.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // ==UserScript==
    // @name Stay logged in
    // @version 1
    // @grant none
    // @include https://www.example.com/*
    // ==/UserScript==

    function keepalive() {
    //console.log('Sending HTTP HEAD request to: ' + location.href);
    var req = new XMLHttpRequest();
    req.open('HEAD', location.href);
    req.onreadystatechange = function() {
    if (req.readyState === XMLHttpRequest.DONE) {
    var status = req.status;
    if (status === 0 || (status >= 200 && status < 400)) {
    //console.log('Success: ' + status);
    } else {
    console.log('HTTP Error: ' + status);
    }
    }
    };
    req.onerror = function() {
    console.log('Network Error: request failed');
    };
    req.send();
    };

    setInterval(keepalive, 10 * 60 * 1000);