-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpopup.js
78 lines (51 loc) · 2.13 KB
/
popup.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
chrome.runtime.sendMessage({ type: "getUID" }, function (uid) {
if (typeof uid == "undefined") {
let channelsContainer = document.getElementById("channels")
channelsContainer.innerHTML = '<p>Tienes que abrir el popup desde booyah.live!</p>';
} else {
console.log(uid);
var channels = []
let url = `https://booyah.live/api/v3/users/${uid}/followings?cursor=0&count=50`;
// fetch the user following channels
fetch(url)
.then((response) => response.json())
.then((json) => {
console.log(json);
channels = json["following_list"];
let channelsContainer = document.getElementById("channels")
var channelHTML = "";
channels.forEach((channel) => {
channelHTML += `
<div class="channel" title="${channel.name}" id="${channel.uid}">
<button id="goto_${channel.uid}">
<img class="icon" src="${channel.thumbnail}"></img>
<span class="nickname"> ${channel.nickname}</span>
</button>
</div>
`;
// <div id="live_${channel.uid}" class="live"></div>
});
channelsContainer.innerHTML = channelHTML;
channels.forEach(function(channel){
document.getElementById("goto_"+channel.uid).addEventListener("click", function(){ gotostream(channel.uid)});
})
// fetch the channel streaming data (is live, stream name,etc)
channels.forEach(channel => {
let url = `https://booyah.live/api/v3/channels/${channel.uid}`
fetch(url)
.then((response) => response.json())
.then((json) => {
let stream = json['channel']
console.log(channel)
document.getElementById(stream.channel_id).setAttribute('title',stream.name);
/*if(stream.is_streaming){
document.getElementById('live_'+stream.channel_id).style.display = 'inline-block'
}*/
})
})
});
}
});
function gotostream(uid){
chrome.tabs.create({active: true, url: `https://booyah.live/channels/${uid}`});
}