Last active
August 28, 2024 20:42
-
-
Save robertohuertasm/5654d094b6bfb2652133163314051557 to your computer and use it in GitHub Desktop.
Adding a view in Insiders button in Datadog UI
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 Datadog - Transform into Insiders | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-08-28 | |
// @description Add an insiders options into the View in IDE button | |
// @author Roberto Huertas | |
// @match https://app.datadoghq.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=datadoghq.com | |
// @grant none | |
// ==/UserScript== | |
let isAdding = false; | |
function addElement(time) { | |
if (isAdding) return; | |
isAdding = true; | |
setTimeout(() => { | |
try { | |
console.log('Trying to create the link'); | |
const element = document.querySelector('[aria-label="View in VS Code"]'); | |
if (!element) { | |
return; | |
} | |
const cloned = element.cloneNode(true); | |
// change the text | |
cloned.childNodes[1].textContent = 'View in Insiders'; | |
// change the icon | |
cloned.childNodes[0].childNodes[0].src = 'https://www.svgrepo.com/download/374174/vscode-insiders.svg'; | |
// change the url | |
cloned.href = cloned.href.replace('vscode://', 'vscode-insiders://'); | |
// add the element to the dom | |
element.insertAdjacentElement('afterend', cloned); | |
console.log('Element added!'); | |
} catch (e) { | |
console.error(e); | |
console.log('Trying to add the element again'); | |
addElement(time + 1000); | |
} finally { | |
isAdding = false; | |
} | |
}, time); | |
} | |
const originalPushState = history.pushState; | |
history.pushState = function() { | |
originalPushState.apply(history, arguments); | |
window.dispatchEvent(new Event('urlchange')); | |
}; | |
window.addEventListener('urlchange', function() { | |
console.log('URL changed to:', window.location.href); | |
addElement(5000); | |
}); | |
addElement(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment