Skip to content

Instantly share code, notes, and snippets.

@Bewitchedyegor
Last active October 12, 2017 12:59
Show Gist options
  • Save Bewitchedyegor/c502e85ac4c0fa3b2039f40e74fd11be to your computer and use it in GitHub Desktop.
Save Bewitchedyegor/c502e85ac4c0fa3b2039f40e74fd11be to your computer and use it in GitHub Desktop.
Copy direct link to post in newsfeed into clipboard on click
$('.copyLink').click( function(e) {
let currenturl = 'http://'; //your domain
let userid = $('html').find('.profileImage a').attr('href'); //get user ID
let postid = $(e.target).parent().attr('id'); //get post ID
let urlcopy = currenturl + userid + '#' + postid; //get the full link
let $temp = $("<input>"); //create fake input
$("body").append($temp); //add fake input to HTML
$temp.val(urlcopy).select(); //insert full link to fake input
document.execCommand("copy"); //copy full link from fake input to clipboard
$temp.remove(); //remove fake input from HTML
});
//Pressing Ctrl + V will paste the full link anywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment