-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
185 lines (150 loc) · 5.67 KB
/
script.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
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
var connection = new WebSocket('ws://34.74.119.87:9995');
connection.onopen = function () {
connection.send('Ping'); // Send the message 'Ping' to the server
};
// Log errors
connection.onerror = function (error) {
console.log('WebSocket Error ' + error);
};
// Log messages from the server
connection.onmessage = function (e) {
console.log('Server: ' + e.data);
window.times = e.data.split();
showVideo();
};
//Add fade in animations
$( document ).ready(function() {
$("#input").delay(700).animate({"opacity": "1"}, 800);
$("#desc").delay(800).animate({"opacity": "1"}, 800);
});
//if given improper url
function urlError() {
if($("#errorMsg").length == 0) {
let p = document.createElement("p");
let text = document.createTextNode("Incorrect URL");
p.setAttribute("id","errorMsg")
p.style.opacity = 1;
p.style.color = "red";
p.appendChild(text);
$("#urlBox").prepend(p);
}
}
//get the url
function getData() {
let url = document.getElementById("clip_url").value;
if(!url.includes("twitch.tv/videos/")) {
urlError();
return;
}
window.urlId = url.split('videos/')[1];
//send this url
// while(!(connection.readyState == connection.OPEN)) {
// }
//connection.send(String(urlId));
$("#input").delay(100).animate({"opacity": "0"}, 500);
$("#desc").delay(100).animate({"opacity": "0"}, 500);
// <div class="spinner-border text-primary" role="status">
// <span class="sr-only">Loading...</span>
// </div>
// let div = document.createElement("div");
// div.setAttribute("class", "spinner-border text-primary text-center");
// div.setAttribute("role", "spinner-border text-primary");
// let span = document.createElement("span");
setTimeout(function(){
document.getElementById("input").remove();
document.getElementById("desc").remove();
}, 650);
}
//go to that timestamp
function toTime(str) {
iframe.setAttribute("src", "https://player.twitch.tv/?video=v" + String(urlId) + "&time=" + str);
}
//refresh the page to clip it again
function reclip() {
window.location.reload(false);
}
//load video and buttons
function showVideo() {
let rowDiv;
let colDiv;
let button;
let div;
let text;
let h3;
//create new div for buttons
div = document.createElement("div");
div.setAttribute("class", "container");
div.style.paddingBottom = "52px";
//get the times
//window.times = ["01h30m42s", "02h40m22s", "03h25m03s"];
let counter = 0;
let str;
for(let x = 0; x < Math.ceil(times.length/5); x++) {
rowDiv = document.createElement("div");
rowDiv.setAttribute("class", "row");
rowDiv.style.paddingTop = "25px";
div.appendChild(rowDiv);
for(let y = 0; y < 5 && counter<times.length; y++) {
colDiv = document.createElement("div");
colDiv.setAttribute("class", "col text-center");
str = times[counter].replace(/[a-r]/g, ':');
str = str.replace('s', "");
button = document.createElement("button");
button.setAttribute("class", "btn btn-primary btn-lg clipit-button");
button.setAttribute("onclick", "toTime(\""+times[counter]+"\")");
button.setAttribute("id", "timestamp");
button.style.opacity = 0;
rowDiv.appendChild(colDiv);
colDiv.appendChild(button);
text = document.createTextNode(str);
button.appendChild(text);
counter++;
colDiv = document.createElement("div");
colDiv.setAttribute("class", "col text-center");
}
rowDiv = document.createElement("div");
rowDiv.setAttribute("class", "row");
rowDiv.style.paddingTop = "25px";
}
$("footer").prepend(div);
$("button").delay(300).animate({"opacity": "1"}, 800);
//create new div for the highlights
div = document.createElement("div");
div.setAttribute("class", "row justify-content-center");
div.style.paddingTop = "25px";
div.style.paddingLeft = "25px";
div.style.paddingRight = "25px";
h3 = document.createElement('h3');
text = document.createTextNode("Highlights");
h3.setAttribute("class", "display-7 text-dark text-center font-weight-normal");
h3.appendChild(text);
div.appendChild(h3);
$("footer").prepend(div);
//create new div
div = document.createElement("div");
div.setAttribute("class", "row justify-content-center");
div.setAttribute("id", "vidPlayer");
div.style.paddingTop = "25px";
div.style.paddingLeft = "25px";
div.style.paddingRight = "25px";
div.style.opacity = 0;
//create the iframe
window.iframe = document.createElement('iframe');
iframe.setAttribute("src", "https://player.twitch.tv/?video=v" + String(urlId) + "&time=0h0m0s");
iframe.setAttribute("height", "450");
iframe.setAttribute("width", "800");
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("scrolling", "no");
iframe.setAttribute("allowfullscreen", "true");
div.appendChild(iframe);
$("footer").prepend(div);
$("#vidPlayer").delay(100).animate({"opacity": "1"}, 500);
button = document.createElement("button");
button.setAttribute("class", "btn btn-primary btn-lg");
button.setAttribute("onclick", "reclip()");
button.setAttribute("id", "reclip");
text = document.createTextNode("ReClip!");
button.style.opacity = 1;
button.append(text);
$("#topDec").append(button);
}