You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
763 B
JavaScript
25 lines
763 B
JavaScript
2 years ago
|
import srtParser2 from 'https://cdn.skypack.dev/srt-parser-2';
|
||
|
const player = document.querySelector('#player')
|
||
|
|
||
|
const readSRT = (srt) => {
|
||
|
let parser = new srtParser2();
|
||
|
let srt_array = parser.fromSrt(srt)
|
||
|
console.log(srt_array)
|
||
|
|
||
|
let currentId = 0
|
||
|
player.addEventListener('timeupdate', (e)=>{
|
||
|
let current = srt_array.find(
|
||
|
caption =>
|
||
|
caption.startSeconds <= e.target.currentTime &&
|
||
|
caption.endSeconds >= e.target.currentTime
|
||
|
)
|
||
|
if (current != undefined && currentId != parseInt(current.id)){
|
||
|
currentId = parseInt(current.id)
|
||
|
console.log(current.text)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
fetch('jeetee.srt').then(res=>res.text()).then(data=>readSRT(data))
|
||
|
|