-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
49 lines (42 loc) · 1.7 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
<!DOCTYPE html>
<html>
<body>
<div id="error"></div>
<style>
a {
word-break: break-word;
}
</style>
<script>
const API_KEY = 'AIzaSyAaJzJNVXjbG4QFp7nvRyt_u4YRPMP6HQY';
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
const showError = (message) => document.getElementById("error").innerHTML = message
const channelId = params.channelId
if (!channelId) {
const message = 'Please add "<code>channelId=<your-channel-id></code>" to the URL. ' +
'You can find your channel ID here: ' +
'<a target="youtube" href="https://www.youtube.com/account_advanced">https://www.youtube.com/account_advanced</a>'
showError(message)
throw message
}
const url = `https://www.googleapis.com/youtube/v3/search?key=${API_KEY}&part=snippet&channelId=${channelId}&eventType=live&type=video`;
fetch(url)
.then(response => response.json())
.then(data => {
if (data.error) throw data.error
if (data.items.length < 1) {
const studioUrl = `https://studio.youtube.com/channel/${channelId}/livestreaming`
throw 'Not currently live. Refresh this browser dock once you go live.' +
'<br /><br /> Live streaming Studio: ' +
`<a target="youtube" href="${studioUrl}">${studioUrl}</a>`
}
const videoId = data.items[0].id.videoId;
console.info(`videoId: ${videoId}`)
window.location.href = `https://studio.youtube.com/live_chat?is_popout=1&v=${videoId}`
})
.catch(error => showError(error.hasOwnProperty('message') ? error.message : error));
</script>
</body>
</html>