Skip to content

Instantly share code, notes, and snippets.

@thehig
Last active August 1, 2018 14:30
Show Gist options
  • Save thehig/2d754ff238d096f3e983bd62e5a94154 to your computer and use it in GitHub Desktop.
Save thehig/2d754ff238d096f3e983bd62e5a94154 to your computer and use it in GitHub Desktop.
Show Scripts
// Show Script Bodies
javascript: (function() {
fetch(
"https://cdn.rawgit.com/thehig/2d754ff238d096f3e983bd62e5a94154/raw/showScriptBodies.js"
)
.then(response => response.text())
.then(text => eval(text));
})();
// Show Script Sources
javascript: (function() {
fetch(
"https://cdn.rawgit.com/thehig/2d754ff238d096f3e983bd62e5a94154/raw/showScriptSources.js"
)
.then(response => response.text())
.then(text => eval(text));
})();
(function(){
/* https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f */
const copyToClipboard = str => {
const el = document.createElement('textarea'); /* Create a <textarea> element */
el.value = str; /* Set its value to the string that you want copied */
el.setAttribute('readonly', ''); /* Make it readonly to be tamper-proof */
el.style.position = 'absolute';
el.style.left = '-9999px'; /* Move outside the screen to make it invisible */
document.body.appendChild(el); /* Append the <textarea> element to the HTML document */
const selected =
document.getSelection().rangeCount > 0 /* Check if there is any content selected previously */
? document.getSelection().getRangeAt(0) /* Store selection if found */
: false; /* Mark as false to know no selection existed before */
el.select(); /* Select the <textarea> content */
document.execCommand('copy'); /* Copy - only works as a result of a user action (e.g. click events) */
document.body.removeChild(el); /* Remove the <textarea> element */
if (selected) { /* If a selection existed before copying */
document.getSelection().removeAllRanges(); /* Unselect everything on the HTML document */
document.getSelection().addRange(selected); /* Restore the original selection */
}
};
const scripts = [].slice.call(document.getElementsByTagName('script')).filter(f => !f.src).map(f => f.text).join('\n\n\n');
copyToClipboard(scripts);
window.alert('Copied to clipboard:\n\n' + scripts);
})();
(function(){
/* https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f */
const copyToClipboard = str => {
const el = document.createElement('textarea'); /* Create a <textarea> element */
el.value = str; /* Set its value to the string that you want copied */
el.setAttribute('readonly', ''); /* Make it readonly to be tamper-proof */
el.style.position = 'absolute';
el.style.left = '-9999px'; /* Move outside the screen to make it invisible */
document.body.appendChild(el); /* Append the <textarea> element to the HTML document */
const selected =
document.getSelection().rangeCount > 0 /* Check if there is any content selected previously */
? document.getSelection().getRangeAt(0) /* Store selection if found */
: false; /* Mark as false to know no selection existed before */
el.select(); /* Select the <textarea> content */
document.execCommand('copy'); /* Copy - only works as a result of a user action (e.g. click events) */
document.body.removeChild(el); /* Remove the <textarea> element */
if (selected) { /* If a selection existed before copying */
document.getSelection().removeAllRanges(); /* Unselect everything on the HTML document */
document.getSelection().addRange(selected); /* Restore the original selection */
}
};
const scripts = [].slice.call(document.getElementsByTagName('script')).filter(f => f.src).map(f => f.src).join('\n');
copyToClipboard(scripts);
window.alert('Copied to clipboard:\n\n' + scripts);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment