Skip to content

Commit

Permalink
Battle-log: Support seeking to a timestamp in <youtube> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Jan 10, 2024
1 parent 17eef20 commit 2cca9bc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion play.pokemonshowdown.com/src/battle-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,13 +929,15 @@ export class BattleLog {
this.players.push(null);
const idx = this.players.length;
this.initYoutubePlayer(idx);
console.log(src, time);
return {
tagName: 'iframe',
attribs: [
'id', `youtube-iframe-${idx}`,
'width', width, 'height', height,
'src', `https://www.youtube.com/embed/${videoId}?enablejsapi=1&playsinline=1${time ? `&start=${time}` : ''}`,
'frameborder', '0', 'allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture', 'allowfullscreen', 'allowfullscreen',
'time', (time || 0) + "",
],
};
} else if (tagName === 'formatselect') {
Expand Down Expand Up @@ -1069,7 +1071,8 @@ export class BattleLog {
static initYoutubePlayer(idx: number) {
const id = `youtube-iframe-${idx}`;
const loadPlayer = () => {
if (!$(`#${id}`).length) return;
const el = $(`#${id}`);
if (!el.length) return;
const player = new window.YT.Player(id, {
events: {
onStateChange: (event: any) => {
Expand All @@ -1082,7 +1085,12 @@ export class BattleLog {
},
},
});
const time = Number(el.attr('time'));
if (time) {
player.seekTo(time);
}
this.players[idx - 1] = player;

};
// wait for html element to be in DOM
this.ensureYoutube().then(() => {
Expand Down

0 comments on commit 2cca9bc

Please sign in to comment.