Skip to content

Instantly share code, notes, and snippets.

@dan-westall
Last active January 21, 2016 20:46
Show Gist options
  • Save dan-westall/ec07b51168dc58bb6f2a to your computer and use it in GitHub Desktop.
Save dan-westall/ec07b51168dc58bb6f2a to your computer and use it in GitHub Desktop.
Browser snippet to add a copy slug to clipboard link to wp plugin page. Handy for when working with dev sites and wp cli
( function($){
function copyToClipboard(text) {
const input = document.createElement('input');
input.style.position = 'fixed';
input.style.opacity = 0;
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('Copy');
document.body.removeChild(input);
};
$('[data-slug]').each( function(i, el ){
var $el = $(this);
var $link = $('<a />')
.attr('href', 'javascript:void(0);')
.attr('data-plugin-slug', $el.data('slug') )
.text('Copy Slug');
$el.find('.row-actions')
.append( $('<span> | </span>')
.append( $link ) );
$link.click( function(e){
e.preventDefault();
copyToClipboard( $(this).data('plugin-slug') );
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment