Skip to content

Instantly share code, notes, and snippets.

@schu
Created January 19, 2021 15:42
Show Gist options
  • Save schu/55a89e539a9e146ecee21110f3c7d7e2 to your computer and use it in GitHub Desktop.
Save schu/55a89e539a9e146ecee21110f3c7d7e2 to your computer and use it in GitHub Desktop.
// ==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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment