-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeep_link.js
52 lines (41 loc) · 1.38 KB
/
deep_link.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
42
43
44
45
46
47
48
49
50
51
52
function string_to_seconds(s) {
var returnvalue = 0;
if (s.match(/^\s*(\d\d?):(\d\d):(\d\d)\s*$/)) {
returnvalue= (parseInt(RegExp.$1)*3600 + parseInt(RegExp.$2)*60 + parseInt(RegExp.$3));
} else if (s.match(/^\s*(\d\d):(\d\d)\s*$/)) {
returnvalue= (parseInt(RegExp.$1)*60 + parseInt(RegExp.$2));
} else {
returnvalue= parseInt(s);
}
if (isNaN(returnvalue)) { returnvalue = 0; }
return returnvalue;
}
function check_deeplink() {
if (window.location.hash) {
if (window.location.hash.length > 1) {
//#t=12456,15:30
if (window.location.hash.match(/(^|#|&)t=(\d\d?:\d\d:\d\d|\d\d:\d\d|\d+)?(,(\d\d?:\d\d:\d\d|\d\d:\d\d|\d+))?($|&)/)) {
if (document.getElementsByClassName("tellingink_audioplayer").length > 0) {
var player_element = document.getElementsByClassName("tellingink_audioplayer")[0];
var starttime = RegExp.$2;
var stoptime = RegExp.$4;
starttime = string_to_seconds(starttime);
stoptime = string_to_seconds(stoptime);
if(starttime>stoptime) {
stoptime = player_element.duration;
}
player_element.currentTime = starttime;
player_element.play();
global_stoptime = stoptime;
player_element.addEventListener("timeupdate",function(){
if (this.currentTime >= global_stoptime) {
this.pause();
global_stoptime = this.duration;
}
});
}
}
}
}
}
window.addEventListener("load",function() { check_deeplink(); });