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