-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
147 lines (124 loc) · 5.3 KB
/
index.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
146
147
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twitch Channel Tracker</title>
<link rel="stylesheet" href="https://polyextended.github.io/nav.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</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">
<h1 class="center-align">Twitch Channel Information</h1>
<div class="row">
<div class="input-field col s12">
<input type="text" id="channelInput" class="validate">
<label for="channelInput">Enter Twitch Channel Name</label>
</div>
</div>
<div class="row">
<div class="col s12" id="channelInfo">
</div>
</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>
const clientId = `2oag632o0mp6n85h3mismr2ocsa1jip`;
const accessToken = '62ly1aqjnymr30sn6yga5xpxuo4yi9';
document.getElementById('channelInput').addEventListener('change', function() {
const channelName = this.value;
getChannelInfo(channelName);
});
// Call getBannedUsers every 3 minutes
setInterval(() => {
getBannedUsers();
}, 3 * 60 * 1000);
async function getChannelInfo(channelName) {
try {
const bannedUsers = await getBannedUsers();
if (bannedUsers.includes(channelName.toLowerCase())) {
displayBannedUserMessage();
return;
}
const [user, follows, stream] = await Promise.all([
getUserInfo(channelName),
getFollowers(channelName),
getStreamInfo(channelName),
]);
const isPartner = user && user.broadcaster_type === 'partner';
const isAffiliate = user && user.broadcaster_type === 'affiliate';
const joinDate = user ? new Date(user.created_at).toLocaleDateString() : 'N/A';
const isMature = user && user.mature;
const infoText = `
<p>Channel Name: ${channelName}</p>
<p>Is Partner: ${isPartner}</p>
<p>Is Affiliate: ${isAffiliate}</p>
<p>Join Date: ${joinDate}</p>
<p>Is Mature: ${isMature}</p>
<p>Followers: ${follows}</p>
<p>Is Live: ${stream}</p>
`;
document.getElementById('channelInfo').innerHTML = infoText;
} catch (error) {
console.error('Error fetching channel info:', error);
document.getElementById('channelInfo').innerHTML = `<p>Error: ${error.message}</p>`;
}
}
async function getUserInfo(channelName) {
const response = await fetch(`https://api.twitch.tv/helix/users?login=${channelName}`, {
headers: {
'Client-ID': clientId,
'Authorization': `Bearer ${accessToken}`,
},
});
const data = await response.json();
return data.data[0];
}
async function getFollowers(channelName) {
const response = await fetch(`https://api.twitch.tv/helix/users/follows?to_id=${channelName}`, {
headers: {
'Client-ID': clientId,
'Authorization': `Bearer ${accessToken}`,
},
});
const data = await response.json();
return data.total;
}
async function getStreamInfo(channelName) {
const response = await fetch(`https://api.twitch.tv/helix/streams?user_id=${channelName}`, {
headers: {
'Client-ID': clientId,
'Authorization': `Bearer ${accessToken}`,
},
});
const data = await response.json();
return data.data.length > 0 ? 'Yes' : 'No';
}
async function getBannedUsers() {
try {
const response = await fetch('https://polyextended.github.io/banned.json');
const data = await response.json();
return data.BannedUsers.map(user => user.toLowerCase()) || [];
} catch (error) {
console.error('Error fetching banned users:', error);
return [];
}
}
function displayBannedUserMessage() {
document.getElementById('channelInfo').innerHTML = '<p>User is banned</p>';
}
</script>
</body>
</html>