-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScripts.js
More file actions
188 lines (168 loc) · 5.14 KB
/
Scripts.js
File metadata and controls
188 lines (168 loc) · 5.14 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// 1. ytplayer code: https://developers.google.com/youtube/player_parameters#IFrame_Player_API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
FocusedOn = 0;
//Replaces video
function ReplaceVid() {
temp = document.getElementById("YoutubeURL").value;
if (temp.indexOf("?") != -1 && temp.indexOf("v=") != -1) {
player.loadVideoById(temp.substring(temp.indexOf("v=")+2));
} else if (temp.indexOf("/") != -1) {
player.loadVideoById(temp.substring(temp.lastIndexOf("/")+1));
} else {
player.loadVideoById(document.getElementById("YoutubeURL").value);
}
//document.getElementById('EndTime').placeholder = "End loop (default: " + player.playerInfo.duration + ")";
}
//Handles all resizings
function reSizes() {
document.getElementById('ytplayer').height = 9/16* document.getElementById('ytplayer').clientWidth;
}
window.addEventListener('resize', reSizes);
//Handles Buttons Under the loop inputs
function clearNum(startOrEnd) {
if (startOrEnd == 0) {
document.getElementById('StartTime').value = '';
} else {
document.getElementById("EndTime").value = '';
}
}
function currentTimeSetTo(startOrEnd) {
/* https://youtu.be/3MF4-KGwBz8 */
ez = player.playerInfo.currentTime;
days = Math.floor(ez/86400);
hours = Math.floor((ez%86400)/3600);
if (days != 0 && hours < 10) { hours = "0" + hours; }
minutes = Math.floor((ez%3600)/60);
if (hours != 0 && minutes < 10) { minutes = "0" + minutes; }
seconds = Math.floor(ez%60);
if (minutes != 0 && seconds < 10) { seconds = "0" + seconds; }
fullPrint = days + ":" + hours + ":" + minutes + ":" + seconds;
while (true) {
if (fullPrint.substring(0, fullPrint.indexOf(":")) == "00" || fullPrint.substring(0, fullPrint.indexOf(":")) == "0") {
fullPrint = fullPrint.substring(fullPrint.indexOf(":")+1);
} else {
break
}
}
if (startOrEnd == 0) {
document.getElementById("StartTime").value = fullPrint;
} else {
document.getElementById("EndTime").value = fullPrint;
}
}
//handles moving video forward/backward a set amount
function move(amt) {
player.seekTo(player.playerInfo.currentTime + amt, true);
}
//Handles Keyboard Navigation
document.addEventListener("keydown", function(event) {
if (event.code === 'Enter') {
if (FocusedOn == 1) { ReplaceVid(); }
if (FocusedOn == 2) { clearNum(0); }
if (FocusedOn == 3) { currentTimeSetTo(0); }
if (FocusedOn == 4) { clearNum(1); }
if (FocusedOn == 5) { currentTimeSetTo(1); }
if (FocusedOn == 6) { move(-15); }
if (FocusedOn == 7) { move(-10); }
if (FocusedOn == 8) { move(-5); }
if (FocusedOn == 9) { move(5); }
if (FocusedOn == 10) { move(10); }
if (FocusedOn == 11) { move(15); }
}
});
function focusChange(changeTo, doReset) {
if (doReset == 1 && FocusedOn == changeTo) {
FocusedOn = 0;
} else {
FocusedOn = changeTo;
}
}
//Forces video to start at user inputted time
//Forces video to go back to user inputted time
setInterval(function() {
curTime = player.playerInfo.currentTime;
dur = player.playerInfo.duration;
startTime = 0;
if (document.getElementById('StartTime').value != "") {
temp = document.getElementById('StartTime').value.split(":");
for (let i = 0; i < temp.length; i++) {
try {
if (i != 3) {
startTime += temp[temp.length-1-i]*Math.pow(60, i);
} else {
startTime += temp[temp.length-1-i]*86400;
}
} catch (error) {
startTime = null;
break;
}
}
}
endTime = dur;
if (document.getElementById('EndTime').value != "") {
endTime = 0;
temp = document.getElementById('EndTime').value.split(":");
for (let i = 0; i < temp.length; i++) {
try {
if (i != 3) {
endTime += temp[temp.length-1-i]*Math.pow(60, i);
} else {
endTime += temp[temp.length-1-i]*86400;
}
} catch (error) {
endTime = null;
break;
}
}
}
//console.log(startTime + " " + endTime);
if (curTime == dur) {
try {
player.seekTo(startTime, true);
} catch (error) {
player.seekTo(0, true);
}
}
if (startTime != null) {
if (curTime < startTime) {
player.seekTo(startTime, true);
}
if (endTime != null) {
if (curTime >= endTime) {
player.seekTo(startTime,true);
}
}
}
},1000);
//Makes initial Video
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '360',
width: '100%',
videoId: 'M7lc1UVf-VE',
playerVars: {
playlist: 'M7lc1UVf-VE',
loop: 1,
}
});
reSizes();
}
/*
<div class = "ButtonTemplate ButtonTop" id = "YoutubeURL2" tabindex="0" onclick="clicked(this)">
Click to Replace Video
</div>
function clicked(thisThing) {
console.log(thisThing.id)
}
const form = document.getElementById('form');
form.addEventListener('focus', (event) => {
event.target.style.background = 'pink';
}, true);
form.addEventListener('blur', (event) => {
event.target.style.background = '';
}, true);
*/