Last active
August 29, 2015 14:16
-
-
Save TheGP/3f9eda061db17a2c75a7 to your computer and use it in GitHub Desktop.
reloading trello if connection is lost
This file contains hidden or 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 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