1class LiteYTEmbed extends HTMLElement { 2 connectedCallback() { 3 this.videoId = this.getAttribute('videoid'); 4 let playBtnEl = this.querySelector('.lty-playbtn'); 5 this.playLabel = (playBtnEl && playBtnEl.textContent.trim()) || this.getAttribute('playlabel') || 'Play'; 6 7 if (!this.style.backgroundImage) { 8 this.posterUrl = `https://img.youtube.com/vi/${this.videoId}/sddefault.jpg`; 9 10 LiteYTEmbed.addPrefetch('preload', this.posterUrl, 'image'); 11 this.style.backgroundImage = `url("${this.posterUrl}")`; 12 } 13 14 if (!playBtnEl) { 15 playBtnEl = document.createElement('button'); 16 playBtnEl.type = 'button'; 17 playBtnEl.classList.add('lty-playbtn'); 18 this.append(playBtnEl); 19 } 20 if (!playBtnEl.textContent) { 21 const playBtnLabelEl = document.createElement('span'); 22 playBtnLabelEl.className = 'lyt-visually-hidden'; 23 playBtnLabelEl.textContent = this.playLabel; 24 playBtnEl.append(playBtnLabelEl); 25 } 26 27 this.addEventListener('pointerover', LiteYTEmbed.warmConnections, {once: true}); 28 this.addEventListener('click', e => this.addIframe()); 29 } 30 31 static addPrefetch(kind, url, as) { 32 const linkEl = document.createElement('link'); 33 linkEl.rel = kind; 34 linkEl.href = url; 35 if (as) { 36 linkEl.as = as; 37 } 38 document.head.append(linkEl); 39 } 40 41 static warmConnections() { 42 if (LiteYTEmbed.preconnected) return; 43 44 LiteYTEmbed.addPrefetch('preconnect', 'https://www.youtube-nocookie.com'); 45 LiteYTEmbed.addPrefetch('preconnect', 'https://www.google.com'); 46 LiteYTEmbed.addPrefetch('preconnect', 'https://googleads.g.doubleclick.net'); 47 LiteYTEmbed.addPrefetch('preconnect', 'https://static.doubleclick.net'); 48 49 LiteYTEmbed.preconnected = true; 50 } 51 52 addIframe() { 53 const params = new URLSearchParams(this.getAttribute('params') || []); 54 params.append('autoplay', '1'); 55 params.append('showinfo', '0'); 56 params.append('rel', '0'); 57 58 const iframeEl = document.createElement('iframe'); 59 iframeEl.width = 800;//560 60 iframeEl.height = 450;//315 61 62 iframeEl.title = this.playLabel; 63 iframeEl.allow = 'autoplay; encrypted-media; picture-in-picture'; 64 iframeEl.allowFullscreen = true; 65 66 iframeEl.src = `https://www.youtube-nocookie.com/embed/${encodeURIComponent(this.videoId)}?${params.toString()}`; 67 68 this.append(iframeEl); 69 this.classList.add('lyt-activated'); 70 this.querySelector('iframe').focus(); 71 } 72} 73 74customElements.define('lite-youtube', LiteYTEmbed);
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.