Skip to content

Instantly share code, notes, and snippets.

@Dbof
Created August 4, 2017 22:46
Show Gist options
  • Save Dbof/b71e50a67c743a930385f0237bf50856 to your computer and use it in GitHub Desktop.
Save Dbof/b71e50a67c743a930385f0237bf50856 to your computer and use it in GitHub Desktop.
Properly copy names on click without spaces issue
// ==UserScript==
// @name BugMeNot ProperCopy
// @namespace com.davidebove.blog
// @description Properly copy names on click without spaces issue. See https://bugzilla.mozilla.org/show_bug.cgi?id=1298706
// @match http://bugmenot.com/view/*
// @version 1
// @grant none
// ==/UserScript==
function copyToClipboard(element) {
var target = $(element.target);
var $temp = $('<input>');
$('body').append($temp);
$temp.val(target.text()).select();
document.execCommand('copy');
$temp.remove();
var oldtext = target.text();
target.text('Copied to clipboard!');
setTimeout(function() {
target.text(oldtext);
}, 1000)
}
$('kbd').each(function (i, obj) {
$(obj).click(copyToClipboard);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment