Created
June 1, 2018 03:54
-
-
Save skatsuta/767e8e1df51b2ea7cc1570053c24ebd8 to your computer and use it in GitHub Desktop.
Bookmarklet to copy a link of an embeddable chart on New Relic quickly
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
javascript: (() => { | |
const copyToClipboard = text => { | |
const copyListener = event => { | |
document.removeEventListener('copy', copyListener, true); | |
event.preventDefault(); | |
event.clipboardData.clearData(); | |
event.clipboardData.setData('text/plain', text); | |
}; | |
document.addEventListener('copy', copyListener, true); | |
const result = document.execCommand('copy'); | |
if (!result) { | |
alert('Oops! Failed to copy to clipboard...'); | |
} | |
}; | |
const codeSnippetSelector = '#cboxLoadedContent textarea.embed-snippet'; | |
const snippet = document.querySelector(codeSnippetSelector); | |
if (!snippet) { | |
alert('Oops! No embeddable code found...'); | |
return; | |
} | |
const match = snippet.textContent.match(/ src="(.*?)" /); | |
if (match.length < 2) { | |
alert('Oops! No chart link found...'); | |
return; | |
} | |
copyToClipboard(match[1]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment