-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreams.js
139 lines (124 loc) · 5.77 KB
/
streams.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
import dateConverter from './date_converter';
import { timeGreaterThan, timeGreaterThan2, timestamp, timestamp2 } from './search_utilities';
export const displayStreams = (events, videos, gtag) => {
const first = document.getElementsByClassName("first")[0];
first.style.display = "none";
const splash = document.getElementsByClassName("splash-content")[0];
splash.style.display = "none";
const logo = document.getElementsByClassName("logo")[0];
logo.style.display = "none";
const fp = document.getElementsByClassName("load")[0];
fp.style.display = "none";
let clips = [];
let videoHasEvents = {};
// debugger
for(let j = 0; j < videos.length; j++) {
for(let i = 0; i < events.length; i++) {
if(timeGreaterThan(events[i]._D, videos[j].created_at) && timeGreaterThan2(events[i]._D, videos[j].created_at, videos[j].length)) {
videoHasEvents[videos[j]._id] = true;
clips.push({"video_id": videos[j]._id, "url": videos[j].url, "seek": timestamp2(events[i]._D, videos[j].created_at, videos[j].length), "timestampInSeconds": timestamp(events[i]._D, videos[j].created_at, videos[j].length), "event": events[i], "vod": videos[j]})
}
}
}
const parent = document.createElement("section")
const button = document.createElement("span");
button.innerHTML = '←';
button.classList.add("back");
parent.appendChild(button);
const container = document.createElement("section");
parent.classList.add("parent-container");
const plyr = document.createElement("div");
plyr.innerHTML = `<h2>${ gtag }</h2>`;
container.appendChild(plyr);
const listOfVids = document.createElement("ul");
listOfVids.classList.add("list-of-vids");
for(let i = 0; i < videos.length; i++) {
if(videoHasEvents[videos[i]._id]) {
const ul = document.createElement("ul");
ul.innerHTML = `<h3>${ videos[i].title }</h3><span>${ dateConverter(videos[i].created_at) }</span>`;
ul.classList.add("streamsBox", `streamsBox${ i }`);
const modal = document.createElement("section");
modal.classList.add("modal2", `modal2-${ i }`);
const modal_content = document.createElement("div");
modal_content.classList.add("modal-content", `modal-content${ i }`);
for(let j = 0; j < clips.length; j++) {
if(clips[j].video_id === videos[i]._id) {
const li = document.createElement("li");
// debugger
li.innerHTML = `Killer:${ clips[j].event.killer ? (clips[j].event.killer.name) : "Environment" } Victim:${ clips[j].event.victim.name }`;
li.classList.add(`${ clips[j].event.killer ? (clips[j].event.killer.name === gtag ? "gr" : "re") : "re" }`, "nostylist");
li.setAttribute("id", `${ clips[j].seek }`)
modal_content.appendChild(li);
}
}
modal.appendChild(modal_content);
const div = document.createElement("div");
div.setAttribute("id", `${ i }`);
div.classList.add("vframe");
const btn = document.createElement("span");
btn.innerHTML = '✖';
btn.classList.add("close2", `close2-${ i }`);
div.appendChild(btn);
modal.appendChild(div);
ul.appendChild(modal);
listOfVids.appendChild(ul);
}
}
// const btn = document.createElement("span");
// btn.innerHTML = '✖';
// btn.classList.add("close2");
container.appendChild(listOfVids)
parent.appendChild(container);
// parent.appendChild(btn);
document.body.appendChild(parent);
let names = [];
for(let j = 0; j < videos.length; j++) {
names.push("player" + j)
}
for(let i = 0; i < videos.length; i++) {
if(videoHasEvents[videos[i]._id]) {
var options = {
width: 970,
height: 540,
autoplay: false,
video: `${ videos[i]._id }`,
parent: ["clipd.herokuapp.com"]
};
names[i] = new Twitch.Player(`${ i }`, options);
names[i].setVolume(0.5);
document.querySelectorAll('.nostylist').forEach(event => {
event.addEventListener('click', () => {
names[i].seek(Number(event.id));
})
})
document.getElementsByClassName(`close2-${ i }`)[0].addEventListener('click', () => {
names[i].pause();
document.getElementsByClassName(`modal2-${ i }`)[0].style.display = "none";
document.getElementsByClassName(`close2-${ i }`)[0].style.display = "none";
// console.log("clicked");
})
}
}
document.querySelectorAll('.streamsBox').forEach((item, idx) => {
const frm = item.querySelector(`.modal2-${ idx }`);
const btn = document.querySelector(`.close2-${ idx }`);
item.addEventListener('click', e => {
if(e.target === item) {
frm.style.display = "flex";
btn.style.display = "block";
// console.log("clicked box")
}
})
})
// document.querySelectorAll('.close2').forEach(x => {
// x.addEventListener('click', e => {
// document.querySelectorAll('.modal2').forEach(frm => {
// frm.style.display = "none";
// x.style.display = "none";
// })
// })
// })
button.onclick = function() {
window.location = '/';
}
}