Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luckycdev/dad8d47cad7a1dde890e495f19c13ef4 to your computer and use it in GitHub Desktop.
Save luckycdev/dad8d47cad7a1dde890e495f19c13ef4 to your computer and use it in GitHub Desktop.
Bookmarklet to copy the current video url with current time into the video.

Copies the current youtube video and the current timestamp.

Code:

javascript:
function copyYoutubeTime()
{
var a=document.getElementById("movie_player");
var b=a.getCurrentTime();
var c="https://youtu.be/";
var d="?t="+parseInt(b);
var e=c+location.search.split("v=")[1].split("&")+d;
var f=document.createElement("textarea");
document.body.appendChild(f);
f.value=e;
f.select();
document.execCommand("copy");
document.body.removeChild(f);
alert("copied "+e+" !");
}
if(location.hostname==="www.youtube.com")
{
copyYoutubeTime();
}
else if(location.hostname==="youtu.be")
{
copyYoutubeTime();
}
else if(location.hostname==="www.youtube-nocookie.com")
{
copyYoutubeTime();
}
else
{
alert("not on youtube");
}

Bookmarklet:

javascript:function copyYoutubeTime(){var a=document.getElementById("movie_player");var b=a.getCurrentTime();var c="https://youtu.be/";var d="?t="+parseInt(b);var e=c+location.search.split("v=")[1].split("&")+d;var f=document.createElement("textarea");document.body.appendChild(f);f.value=e;f.select();document.execCommand("copy");document.body.removeChild(f);alert("copied "+e+" !");}if(location.hostname==="www.youtube.com"){copyYoutubeTime();}else if(location.hostname==="youtu.be"){copyYoutubeTime();}else if(location.hostname==="www.youtube-nocookie.com"){copyYoutubeTime();}else{alert("not on youtube");}
javascript:function copyYoutubeTime(){var a=document.getElementById("movie_player");var b=a.getCurrentTime();var c="https://youtu.be/";var d="?t="+parseInt(b);var e=c+location.search.split("v=")[1].split("&")+d;var f=document.createElement("textarea");document.body.appendChild(f);f.value=e;f.select();document.execCommand("copy");document.body.removeChild(f);alert("copied "+e+" !");}if(location.hostname==="www.youtube.com"){copyYoutubeTime();}else if(location.hostname==="youtu.be"){copyYoutubeTime();}else if(location.hostname==="www.youtube-nocookie.com"){copyYoutubeTime();}else{alert("not on youtube");}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment