Skip to content

Instantly share code, notes, and snippets.

@awendt
Last active October 28, 2024 11:51
Show Gist options
  • Save awendt/c4b6772c86d48df90ffbd0790f5d4edb to your computer and use it in GitHub Desktop.
Save awendt/c4b6772c86d48df90ffbd0790f5d4edb to your computer and use it in GitHub Desktop.
Lambda Console: Rewrite links to Lambda monitoring tab
// ==UserScript==
// @name Lambda Console: Rewrite links to Lambda monitoring tab
// @description When listing Lambda functions, this rewrites all function links to go straight to the "Monitoring" tab
// @version 6
// @grant none
// @match https://*.console.aws.amazon.com/lambda/home*
// ==/UserScript==
// Copied from https://stackoverflow.com/a/61511955/473467
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
waitForElm('#lambda-listFunctions').then((listFunctionsElem) => {
console.log('List of Lambda functions is ready');
// Callback function to execute when mutations are observed
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
if (mutation.type === "childList") {
const functionLinks = document.querySelectorAll("a[href^='#/functions/']");
functionLinks.forEach(functionLink => { functionLink.href = functionLink.href + "?tab=monitoring"; });
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(listFunctionsElem, { childList: true, subtree: true });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment