Skip to content

Instantly share code, notes, and snippets.

@TheGP
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save TheGP/3f9eda061db17a2c75a7 to your computer and use it in GitHub Desktop.

Select an option

Save TheGP/3f9eda061db17a2c75a7 to your computer and use it in GitHub Desktop.
reloading trello if connection is lost
// ==UserScript==
// @name Trello reload
// @namespace http://use.homepage/
// @version 0.1
// @description Script will check if trello lost an internet connection and will reload it if connection exists
// @match https://trello.com/*
// @copyright 2015+, You
// ==/UserScript==
function check_for_lost_connection() {
return setInterval(function(){
console.log('check');
// #notification_connection:visible notification_AjaxQueueRetry
if (0 != $('#notification_connection:visible').length && 0 == $('textarea.list-card-composer-textarea:visible').length) {
//check_connection();
if (doesConnectionExist()) {
reaload_trello();
} else {
console.log('no connection');
}
} else {
}
}, 1000);
}
function doesConnectionExist() {
var xhr = new XMLHttpRequest();
var file = "https://trello.com/images/apple-touch-icon-precomposed.png";
var randomNum = Math.round(Math.random() * 10000);
xhr.open('HEAD', file + "?rand=" + randomNum, false);
try {
xhr.send();
if (xhr.status >= 200 && xhr.status < 304) {
return true;
} else {
return false;
}
} catch (e) {
return false;
}
}
function reaload_trello() {
location.reload();
clearInterval(check_for_disconnect);
}
if ('undefined' != typeof($)) {
var check_for_disconnect = check_for_lost_connection();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment