-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
41 lines (34 loc) · 1.19 KB
/
config.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
import {TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET, TWITCH_REDIRECT_URI, CASTER_USER_ID} from "./env.js";
const TWITCH_AUTH_SCOPES = [ // %3A is url encoded colon (:)
"moderator%3Aread%3Afollowers",
"channel%3Aread%3Asubscriptions",
"bits%3Aread"
]
const TWITCH_AUTH_URL = function() {
let parts = {
base: "https://id.twitch.tv/oauth2/authorize?",
arguments: [
"response_type=token",
`client_id=${TWITCH_CLIENT_ID}`,
`redirect_uri=${TWITCH_REDIRECT_URI}`,
`scope=${TWITCH_AUTH_SCOPES.join("+")}`
]
}
return `${parts.base}${parts.arguments.join("&")}`;
}
const TWITCH_AUTH_TOKEN = function() {
if (window.localStorage.getItem("TWITCH_AUTH_TOKEN") === null) {
document.getElementById("TickerHeader").innerHTML = `${TWITCH_AUTH_URL()}`;
}
return window.localStorage.getItem("TWITCH_AUTH_TOKEN");
}
document.onreadystatechange = () => {
if (!document.URL.includes("#access_token")) return;
window.localStorage.setItem("TWITCH_AUTH_TOKEN", document.URL.split("#")[1].split("&")[0].split("=")[1]);
}
export {
TWITCH_CLIENT_ID,
TWITCH_CLIENT_SECRET,
TWITCH_AUTH_TOKEN,
CASTER_USER_ID
};