forked from morfah/html5-ass-subtitles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
41 lines (36 loc) · 1.3 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var captionLimit=10; // how many captions can be on screen at the same time.
var captionInUse=0;
function ASSCaptionsUpdate() {
if (!captions['lines']) { return; }
var v = document.querySelector('video');
var now = v.currentTime;
var text = "";
var captionSelect=0;
for (var i = 0; i < captions['lines'].length; i++) {
if (now >= captions['lines'][i]['start'] && now <= captions['lines'][i]['end']) {
if (captionSelect < captionLimit){
document.getElementById('caption'+captionSelect).innerHTML = captions['lines'][i]['text'];
document.getElementById('caption'+captionSelect).className = "subtitles_"+captions['lines'][i]['style'];
captionSelect++;
} else { alert('limit burst.'); }
}
else if (now < captions['lines'][i]['start'] && now < captions['lines'][i]['end']){
if (captionSelect <= captionInUse){
for (var x = captionSelect; x<captionInUse+1 && x < captionLimit;x++){
document.getElementById('caption'+x).innerHTML = "";
}
}
captionInUse=captionSelect;
return;
}
}
captionInUse=captionSelect;
}
function prepareCaptions(){
var ref = document.getElementsByTagName('video')[0];
for (var x=0; x < captionLimit; x++){
var caption = document.createElement('div');
caption.id = 'caption'+x;
ref.parentNode.insertBefore(caption, ref.nextSibling);
}
}