-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
executable file
·41 lines (37 loc) · 1.25 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
function result(channel_id)
{
if (channel_id === "")
{
return alert("Please enter a Channel ID");
}
document.getElementById("channel_id").value = "";
//for the request
request_data(channel_id);
}
function request_data(channel_id)
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
var output = this.responseText;
output = JSON.parse(output);
document.getElementById("channel_name").innerHTML = output.items[0].snippet["title"];
document.getElementById("sub_count").style.display = "inline";
if(output.items[0].statistics["hiddenSubscriberCount"] === true)
{
console.log("Subscriber count is hidden by the channel");
return document.getElementById("sub_count").innerHTML = "N/A";
}
document.getElementById("sub_count").innerHTML = output.items[0].statistics["subscriberCount"];
}
else if(this.readyState == 4)
{
return console.log(JSON.parse(this.responseText)["error"]["message"]);
}
};
xhttp.open("GET", "https://www.googleapis.com/youtube/v3/channels?part=snippet,statistics&id="+channel_id+"&key=AIzaSyDO-b3pQ0HKP7QmK3h5F1GJgW6hseYxFL0", true);
xhttp.send();
setTimeout(request_data, 2500);
}