Last active
March 3, 2021 03:03
-
-
Save MartinLoeper/c138cbb564d0dcc1cd5a35b73f72c088 to your computer and use it in GitHub Desktop.
This is a Tampermonkey script for Chrome which sets the desired refresh interval for MongoDB charts since the webapp lacks the functionality to specify it via URL parameter.
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 Change MongoDB Atlas Charts Public Dashboard Refresh Interval | |
// @namespace https://nesto-software.de/ | |
// @version 0.1 | |
// @description We implement a workaround for the following issue: https://feedback.mongodb.com/forums/923524-charts/suggestions/39964576-ability-to-set-refresh-rate-via-url-param | |
// @author Martin Löper <martin.loeper@nesto-software.de> | |
// @match https://charts.mongodb.com/*/public/dashboards/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
const KEY = "persist:mongodb-charts:refresh-entities"; | |
const DESIRED_REFRESH_INTERVAL = 60000; | |
(function() { | |
var check = function() { | |
console.log("Checking if refresh settings match desired value."); | |
var refreshSettings = localStorage.getItem(KEY); | |
if(!refreshSettings) { | |
console.log("Local storage key '" + KEY + "' is not set. Cancelling."); | |
return; | |
} | |
var refreshSettingsParsed = JSON.parse(refreshSettings); | |
var ids = JSON.parse(refreshSettingsParsed.ids); | |
var refreshEntitiesParsed = JSON.parse(refreshSettingsParsed.entities); | |
var hasChanges = false; | |
for (var i = 0; i < ids.length; i++) { | |
var id = ids[i]; | |
console.log("We inspect refresh entity with id: " + id); | |
var refreshEntityParsed = refreshEntitiesParsed[id]; | |
var refreshInterval = refreshEntityParsed.refreshInterval; | |
// change the value if not already desired value | |
if (refreshInterval != DESIRED_REFRESH_INTERVAL) { | |
if(!refreshInterval) { | |
console.log("No original value found. Cancelling."); | |
return; | |
} | |
refreshEntityParsed.refreshInterval = DESIRED_REFRESH_INTERVAL; | |
refreshEntitiesParsed[id] = refreshEntityParsed; | |
hasChanges = true; | |
console.log("We changed the MongoDB Charts refresh interval to: " + DESIRED_REFRESH_INTERVAL + ". Was: " + refreshInterval); | |
} else { | |
console.log("Refresh Interval already " + DESIRED_REFRESH_INTERVAL + ". Thus doing nothing."); | |
} | |
} | |
refreshSettingsParsed.entities = JSON.stringify(refreshEntitiesParsed); | |
refreshSettings = JSON.stringify(refreshSettingsParsed); | |
localStorage.setItem(KEY, refreshSettings); | |
if (hasChanges) { | |
console.log("Reloading the page to make sure the change propagates..."); | |
window.location.reload(); | |
} | |
} | |
// since the storage event is only triggered from other windows, we also check periodically | |
window.setInterval(check, 60000); | |
window.setTimeout(check, 10000); | |
check(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment