mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Allow to use %h%m%s
for youtube t
param (#22299)
This commit is contained in:
@ -5,8 +5,8 @@ export default class LazyVideo extends Component {
|
||||
switch (this.args.providerName) {
|
||||
case "youtube":
|
||||
let url = `https://www.youtube.com/embed/${this.args.videoId}?autoplay=1`;
|
||||
if (this.args.startTime > 0) {
|
||||
url += `&start=${this.args.startTime}`;
|
||||
if (this.args.startTime) {
|
||||
url += `&start=${this.convertToSeconds(this.args.startTime)}`;
|
||||
}
|
||||
return url;
|
||||
case "vimeo":
|
||||
@ -17,4 +17,18 @@ export default class LazyVideo extends Component {
|
||||
return `https://www.tiktok.com/embed/v2/${this.args.videoId}`;
|
||||
}
|
||||
}
|
||||
|
||||
convertToSeconds(time) {
|
||||
const match = time.toString().match(/(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?/);
|
||||
const [hours, minutes, seconds] = match.slice(1);
|
||||
|
||||
if (hours || minutes || seconds) {
|
||||
const h = parseInt(hours, 10) || 0;
|
||||
const m = parseInt(minutes, 10) || 0;
|
||||
const s = parseInt(seconds, 10) || 0;
|
||||
|
||||
return h * 3600 + m * 60 + s;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ export default function getVideoAttributes(cooked) {
|
||||
const thumbnail = img?.getAttribute("src");
|
||||
const dominantColor = img?.dataset?.dominantColor;
|
||||
const title = cooked.dataset.videoTitle;
|
||||
const startTime = cooked.dataset.videoStartTime || 0;
|
||||
const startTime = cooked.dataset.videoStartTime;
|
||||
const providerName = cooked.dataset.providerName;
|
||||
const id = cooked.dataset.videoId;
|
||||
|
||||
|
Reference in New Issue
Block a user