Created
March 3, 2018 13:09
-
-
Save gregsonar/3298359a54ed0f7261e79e8f3c6ce273 to your computer and use it in GitHub Desktop.
Page refreshing userscript for Greasemonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Reload on error message | |
// @namespace http://userscripts.org/users/23652 | |
// @description Reload the page on an error message you set yourself | |
// @version 0.5 | |
// @author JoeSimmons, Nickel | |
// @grant none | |
// @include * | |
// ==/UserScript== | |
// Add your errors here to the pattern /////////////// | |
var errors = []; | |
errors[0] = /Too many connections. Please try again later./i; | |
errors[1] = /Mysql error, could not connect Too many connections/i; | |
errors[2] = /max_user_connections/i; | |
errors[3] = /502 Bad Gateway/i; | |
errors[4] = /504 Gateway Time-out/i; | |
errors[5] = /Something broke/i; | |
errors[6] = /Imgur is over capacity!/i; | |
errors[7] = /The database timed out running your query./i; | |
errors[8] = /we took too long to make this page for you/i; | |
////////////////////////////////////////////////////// | |
if ((typeof(sessionStorage.getItem('timer')) !== 'undefined' ) && (typeof(sessionStorage.getItem('timer')) !== null )) { | |
// the timer is defined | |
console.log('the timer is defined', sessionStorage.getItem('timer')); | |
var cooldown = parseInt(sessionStorage.getItem('timer')); | |
cooldown += 100; | |
} else if (sessionStorage.getItem('timer') == 'null') { | |
} | |
else { | |
var cooldown = 1000; | |
sessionStorage.setItem('timer', cooldown); // saving timer status in sessionStorage | |
console.log('define new timer'); | |
} | |
cooldown = parseInt(sessionStorage.getItem('timer')); // getting timer status from sessionStorage | |
console.log('cooldown is: ', parseInt(cooldown)); | |
//typeof() | |
function check() { | |
for(var i=0; i<errors.length; i++) { | |
if(errors[i].test(document.body.textContent)){ | |
console.log(cooldown); | |
//window.location.reload(); | |
} | |
} | |
} | |
if (cooldown < 1000) { | |
cooldown = 1000; | |
console.log('cooldown is too short. Resetting to default'); | |
} | |
setTimeout(check, cooldown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment