Last active
August 29, 2015 14:22
-
-
Save RossRogers/73f84f6eaf2812598d58 to your computer and use it in GitHub Desktop.
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 StackOverflow Code Block Copy Link | |
// @description Shows a copy icon in top right of stackexchange code blocks | |
// @version 0.1 | |
// @author RossRogers | |
// @include http://stackoverflow.com/* | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_xmlhttpRequest | |
// @grant GM_setClipboard | |
// ==/UserScript== | |
'use strict'; | |
$( document ).ready(function(){ | |
$('<style type="text/css"> \n'+ | |
'.showme-abs { \n'+ | |
' opacity: 0; \n'+ | |
' transition: opacity 700ms;\n'+ | |
'} \n'+ | |
'.showhim:hover .showme-abs {\n'+ | |
' opacity: 1; \n'+ | |
'} \n'+ | |
'.clipboard { \n'+ | |
' margin-left: 80%; \n'+ | |
'} \n'+ | |
'</style>' | |
).appendTo('head'); | |
var code_blocks = $('pre code'); | |
code_blocks.addClass('showhim'); | |
code_blocks.prepend($( | |
'<div class="clipboard showme-abs">'+ | |
'<a href="javascript:void(0)" class="copy-the-code" title="Click to the code.">Copy</a>'+ | |
'</div>')); | |
$('.copy-the-code').on('click', function(event) { | |
GM_setClipboard($(event.target).closest('code').text().replace('Copy','')); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment