Last active
October 12, 2017 12:59
-
-
Save Bewitchedyegor/c502e85ac4c0fa3b2039f40e74fd11be to your computer and use it in GitHub Desktop.
Copy direct link to post in newsfeed into clipboard on click
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
$('.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