-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipplayer.html
145 lines (119 loc) · 3.97 KB
/
clipplayer.html
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
<html>
<!-- Clip player made by Witlock -->
<head>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@1,700&display=swap" rel="stylesheet">
<style>
body {
margin: 0;
background: black;
height: 100%;
font-family: 'Open Sans', sans-serif;
}
iframe {
width: 100%;
height: auto;
z-index: 1;
}
#clip-title {
text-align: center;
color: white;
font-size: large;
}
#clip-title h1 {
margin-top: 0;
}
#background-text {
position: absolute;
width: 300px;
height: 100px;
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -50px;
z-index: -1;
}
#background-text h1 {
font-size: 3em;
}
.container {
display: flex;
flex-flow: column;
height: 100%;
}
.container header {
flex: 0 1 auto;
}
.container .content {
flex: 1 1 auto;
display: flex;
}
</style>
</head>
<body>
<div id="background-text">
<h1>Loading Clip</h1>
</div>
<div class="container">
<header>
<div id="clip-title"></div>
</header>
<div class="content">
<iframe id="clip-iframe" frameborder='0' scrolling='no' allowfullscreen='true'>
</iframe>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.5.0.min.js"
integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
<script>
var twitchChannel = "witlock";
var apiKey = ""; // Get the Client Key from https://dev.twitch.tv/console
var clipLimit = 100;
var period = "all";
var playDelay = 2500;
var showTitle = true;
var showPlayingClipText = true;
var parent = "localhost" // where this will be hosted
videos = [];
skipClips = [
'ToughAdorableNewtFutureMan',
'ShySullenMallardDancingBaby']
var httpRequest = new XMLHttpRequest();
httpRequest.addEventListener('load', clipsLoaded);
httpRequest.open('GET', 'https://api.twitch.tv/kraken/clips/top?channel=' + twitchChannel + '&limit=' + clipLimit + '&period=' + period);
httpRequest.setRequestHeader('Client-ID', apiKey);
httpRequest.setRequestHeader('Accept', 'application/vnd.twitchtv.v5+json');
httpRequest.send();
function clipsLoaded() {
var clipsDisplay = document.getElementById('clips-display'),
clipList = JSON.parse(httpRequest.responseText);
clipList.clips.forEach(function (clip, index, array) {
if (!skipClips.includes(clip.slug))
videos.push({ clipContent: clip.embed_url, duration: clip.duration, title: clip.title });
});
shuffle(videos);
playClip(0);
}
function playClip(currentIndex) {
var currentClip = videos[currentIndex];
var clipContainer = document.getElementById('clip-iframe');
var clipTitle = document.getElementById('clip-title');
clipContainer.src = currentClip.clipContent + "&autoplay=true&parent=" + parent;
if (showTitle)
clipTitle.innerHTML =
(showPlayingClipText ? 'Playing Clip: ' : '') +
'<h1>' + currentClip.title + '</h1>';
currentIndex++
if (currentIndex >= videos.length)
currentIndex = 0;
clipContainer.onload = function () {
setTimeout(function () {
playClip(currentIndex);
}, currentClip.duration * 1000 + playDelay);
};
}
function shuffle(array) {
array.sort(() => Math.random() - 0.5);
}
</script>
</html>