Last active
October 11, 2020 17:59
-
-
Save bigethan/bf97845f620466422bdcc11830868fe0 to your computer and use it in GitHub Desktop.
The rails autoscale charts are great, but also you have to refresh them a lot, so this makes the refresh if you've been away for more than 30s. To install click the `Raw` button and your suserscript extension will take it from there.
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 Refresh Autoscaler Charts | |
// @namespace http://bigethan.com/ | |
// @version 0.1 | |
// @description Reload the Rails Autoscaler UI when coming back to it after 30s | |
// @author bigethan | |
// @match https://app.railsautoscale.com/*/dashboard/web | |
// @match https://app.railsautoscale.com/*/dashboard/critical_worker | |
// @match https://app.railsautoscale.com/*/dashboard/default_worker | |
// @match https://app.railsautoscale.com/*/dashboard/slow_worker | |
// @grant none | |
// ==/UserScript== | |
(function (document, window) { | |
"use strict"; | |
let lastReload = new Date(); | |
function handleVisibilityChange() { | |
if (document.visibilityState === "visible") { | |
debouncedReload(); | |
} | |
} | |
function debouncedReload() { | |
let now = new Date(); | |
if (now - lastReload > 30 * 1000) { | |
location.reload(); | |
lastReload = new Date(); | |
} | |
} | |
document.addEventListener("visibilitychange", handleVisibilityChange, false); | |
window.onfocus = debouncedReload; | |
})(document, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment