1/* Light YouTube Embeds by @labnol */ 2/* Web: http://labnol.org/?p=27941 */ 3document.addEventListener("DOMContentLoaded", 4 function () { 5 var div, n, 6 v = document.getElementsByClassName("youtube-player"); 7 for (n = 0; n < v.length; n++) { 8 div = document.createElement("div"); 9 div.setAttribute("data-id", v[n].dataset.id); 10 div.innerHTML = labnolThumb(v[n].dataset.id); 11 div.onclick = labnolIframe; 12 v[n].appendChild(div); 13 } 14 }); 15 16function labnolThumb(id) { 17 var thumb = '<img src="https://i.ytimg.com/vi/ID/hqdefault.jpg">', 18 play = '<div class="play"></div>'; 19 return thumb.replace("ID", id) + play; 20} 21 22function labnolIframe() { 23 var iframe = document.createElement("iframe"); 24 var embed = "https://www.youtube.com/embed/ID?autoplay=1"; 25 iframe.setAttribute("src", embed.replace("ID", this.dataset.id)); 26 iframe.setAttribute("frameborder", "0"); 27 iframe.setAttribute("allowfullscreen", "1"); 28 this.parentNode.replaceChild(iframe, this); 29} 30
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.