this repo has no description

improve youtube embed time range

12Me21 6b9fbd28 2741477e

+42 -3
+42 -3
runtime.js
··· 46 if (this._query) 47 src += `&${this._query}` 48 this.$iframe.src = src 49 this.$link.replaceWith(this.$iframe) 50 } else { 51 this.$iframe.replaceWith(this.$link) ··· 63 if (!url) 64 return // todo: allow setting back to unloaded state? 65 url = url.replace("/shorts/", "/watch?v=") // 🤮 66 if (this._href == url) 67 return 68 this._href = url ··· 72 73 let [, id, query] = /^https?:[/][/](?:www[.])?(?:youtube.com[/]watch[?]v=|youtu[.]be[/])([\w-]{11,})([&?].*)?$/.exec(url) 74 if (query) { 75 let time = /[&?](?:t|start)=([^&?]+)/.exec(query) 76 let end = /[&?]end=([^&?]+)/.exec(query) 77 let loop = /[&?]loop(?:=|&|$)/.exec(query) 78 query = "" 79 - if (time) query += "&start="+time[1] 80 - if (end) query += "&end="+end[1] 81 - if (loop) query += "&loop=1&playlist="+id 82 } 83 this._query = query 84 ··· 124 <span id=author></span> 125 </cite> 126 </a> 127 <button hidden id=close>❌ close</button> 128 <style> 129 :host { ··· 170 #author { 171 font-style: normal; 172 font-weight: bold; 173 } 174 </style> 175 `
··· 46 if (this._query) 47 src += `&${this._query}` 48 this.$iframe.src = src 49 + this.$iframe.allowFullscreen = true 50 this.$link.replaceWith(this.$iframe) 51 } else { 52 this.$iframe.replaceWith(this.$link) ··· 64 if (!url) 65 return // todo: allow setting back to unloaded state? 66 url = url.replace("/shorts/", "/watch?v=") // 🤮 67 + url = url.replace("://music.", "://www.") // i hope this works 68 if (this._href == url) 69 return 70 this._href = url ··· 74 75 let [, id, query] = /^https?:[/][/](?:www[.])?(?:youtube.com[/]watch[?]v=|youtu[.]be[/])([\w-]{11,})([&?].*)?$/.exec(url) 76 if (query) { 77 + function parse_time(str) { 78 + let r = /^(?:([0-9.]+)h)?(?:([0-9.]+)m)?([0-9.]+)s?$/.exec(str) 79 + if (r) { 80 + let [_, h=0, m=0, s=0] = r 81 + return +h*3600 + +m*60 + +s 82 + } 83 + return str 84 + } 85 + function render_time(n) { 86 + if (!n) 87 + return "x" 88 + let s = n % 60 | 0 89 + n /= 60 90 + let m = n % 60 | 0 91 + n /= 60 92 + let h = n % 60 | 0 93 + if (h) 94 + return h+":"+m+":"+s 95 + return m+":"+s 96 + } 97 let time = /[&?](?:t|start)=([^&?]+)/.exec(query) 98 let end = /[&?]end=([^&?]+)/.exec(query) 99 let loop = /[&?]loop(?:=|&|$)/.exec(query) 100 query = "" 101 + if (time) { 102 + time = parse_time(time[1]) 103 + query += "&start="+time 104 + } 105 + if (end) { 106 + end = parse_time(end[1]) 107 + query += "&end="+end 108 + } 109 + //if (loop) query += "&loop=1&playlist="+id // this is broken now.. 110 + let info = "" 111 + if (time && end) 112 + info = "at "+render_time(time)+" – "+render_time(end) 113 + else if (time) 114 + info = "at "+render_time(time) 115 + this.$how.textContent = info 116 } 117 this._query = query 118 ··· 158 <span id=author></span> 159 </cite> 160 </a> 161 + <div id=how></div> 162 <button hidden id=close>❌ close</button> 163 <style> 164 :host { ··· 205 #author { 206 font-style: normal; 207 font-weight: bold; 208 + } 209 + #how { 210 + padding-left: 2px; 211 + font-family: monospace; 212 } 213 </style> 214 `