Created
November 22, 2017 14:13
-
-
Save WebReflection/c14040f2b8c7f7d23ea9a770017269cd to your computer and use it in GitHub Desktop.
Try to execute a Gist pre content and it copies it to clipboard.
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
document.documentElement.appendChild( | |
document.createElement('style') | |
).textContent = ` | |
.executable { | |
transition: all .3s; | |
} | |
.executable:hover { | |
cursor: pointer; | |
background: #fff !important; | |
}`; | |
document.querySelectorAll('pre').forEach(pre => { | |
try { | |
const text = pre.textContent + '\n'; | |
const fn = Function(text); | |
pre.onclick = () => { | |
try { fn.call(window); } catch(meh) {} | |
const ta = document.createElement('textarea'); | |
pre.parentNode.insertBefore(ta, pre); | |
ta.value = text; | |
ta.focus(); | |
ta.setSelectionRange(0, text.length); | |
document.execCommand('copy'); | |
pre.parentNode.removeChild(ta); | |
}; | |
pre.classList.add('executable'); | |
} finally {} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment