Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
172 lines (147 loc) · 6.37 KB
/
Copy pathindex.html
File metadata and controls
172 lines (147 loc) · 6.37 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twitch Featured List</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<!-- Materialize CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Materialize Icons -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Custom Styles -->
<link rel="stylesheet" href="https://polyextended.github.io/nav.css">
<style>
.col.s12.m6 {
flex: 0 0 calc(33.33% - 20px);
margin: 10px;
max-width: calc(33.33% - 20px);
}
.badge-live {
background-color: #28a745;
}
.badge-offline {
background-color: #6c757d;
border-radius: 15px;
}
#jsonData {
margin-top: 20px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
</style>
</head>
<body>
<header class="z-depth-1">
<nav class="z-depth-0 backer-dark">
<div class="nav-wrapper container">
<ul class="left">
<li><a href="https://polyextended.github.io/">Home</a></li>
<li><a href="https://polyextended.github.io/live/">PolyLive</a></li>
<li><a href="https://polyextended.github.io/streamlookup/">PolyLookup</a></li>
</ul>
</div>
</nav>
</header>
<div class="container">
<h4>Twitch Featured List</h4>
<ul class="collection" id="featuredList"></ul>
<div id="jsonData"></div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script>
const clientId = '2oag632o0mp6n85h3mismr2ocsa1jip';
const accessToken = '62ly1aqjnymr30sn6yga5xpxuo4yi9';
const featuredList = document.getElementById('featuredList');
const jsonDataDiv = document.getElementById('jsonData');
const rotateInterval = 3 * 60 * 1000; // Rotate every 3 minutes
let isRendered = false;
let currentIndex = 0;
async function getTwitchStreams(username) {
try {
const response = await fetch(`https://api.twitch.tv/helix/streams?user_login=${username}`, {
method: 'GET',
headers: {
'Client-ID': clientId,
'Authorization': `Bearer ${accessToken}`
}
});
const data = await response.json();
return data.data;
} catch (error) {
console.error(`Error fetching Twitch API for ${username}:`, error);
return null;
}
}
async function getTwitchUsernames() {
try {
const response = await fetch('twitch.json');
const data = await response.json();
jsonDataDiv.innerHTML += '<p>Twitch usernames: ' + (data.Users || []).join(', ') + '</p>';
return data.Users || [];
} catch (error) {
console.error('Error fetching Twitch usernames:', error);
return [];
}
}
async function getBannedUsers() {
try {
const response = await fetch('banned.json');
const data = await response.json();
return data.BannedUsers || [];
} catch (error) {
console.error('Error fetching banned users:', error);
return [];
}
}
async function isUserBanned(username) {
const bannedUsers = await getBannedUsers();
return bannedUsers.includes(username);
}
async function renderFeaturedList() {
const twitchUsernames = await getTwitchUsernames();
for (let i = 0; i < twitchUsernames.length; i++) {
const username = twitchUsernames[currentIndex];
if (await isUserBanned(username)) {
console.log(`${username} is banned and will not be featured.`);
currentIndex = (currentIndex + 1) % twitchUsernames.length;
continue;
}
const streams = await getTwitchStreams(username);
if (streams && streams.length > 0) {
const randomIndex = Math.floor(Math.random() * streams.length);
const randomStreamer = streams[randomIndex];
const displayName = randomStreamer.user_name;
const listItem = document.createElement('li');
listItem.classList.add('collection-item');
// Check if the streamer is live
const isLive = randomStreamer.type === 'live';
const badgeClass = isLive ? 'badge-live' : 'badge-offline';
const badgeText = isLive ? 'Live' : 'Offline';
listItem.innerHTML = `
<span class="title">${displayName}</span>
<p>${randomStreamer.title || ''}</p>
<span class="badge ${badgeClass}">${badgeText}</span>
`;
featuredList.innerHTML = ''; // Clear the list before adding the new name
featuredList.appendChild(listItem);
isRendered = true;
currentIndex = (currentIndex + 1) % twitchUsernames.length;
break; // Show only one name
} else {
currentIndex = (currentIndex + 1) % twitchUsernames.length;
}
}
}
document.addEventListener('DOMContentLoaded', function () {
renderFeaturedList();
setInterval(renderFeaturedList, rotateInterval);
});
</script>
</body>
</html>