url embeder

by frogggeee McFrogggeee

HTML

URL of youtube video:
<input id  = "input" type="text" onkeydown = "keyPressed(this);" onfocus="this.value=''" onpaste="">
<button type="button" onclick="embedVideo();">GO</button>
<iframe id = "video" width="540" height="360" src="" frameborder="1" allowfullscreen ></iframe>

JavaScript

/*
sample link
https://www.youtube.com/watch?v=pZG_0nX5nEY
*/
//let link = (window.location.href);
function paste() {

}
function keyPressed(ele) {
 if (event.keyCode == 13) {
 	embedVideo();
 }
}
function embedVideo() {
  let link = document.getElementById("input").value;
  document.getElementById("input").blur();
  let id = link.split("=")[1].substr(0,11); // get ID of video
  document.getElementById("video").src = "https://www.youtube.com/embed/" + (id) + "?start=0&end=1.0E+21&rel=0&autoplay=1showsearch=0&modestbranding=1&enablejsapi=1&iv_load_policy=3&cc_load_policy=0";
}