summaryrefslogtreecommitdiff
path: root/twitch.html
blob: 109c676f852fb48d83204e1a5bac6e46944db688 (plain)
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
<!DOCTYPE html>
<html>
    <head>
        <title>chat widget</title>
        <link rel="stylesheet" href="/style.css">
    </head>
    <body class="messages" id="messages">
        <noscript>
            JavaScript is required.
        </noscript>
    </body>

    <script src="/scripts/emotes.js"></script>
    <script src="/scripts/chat.js"></script>
    <script src="/scripts/badges.js"></script>
    <script>
        let user = null;
        const params = {
            "ircserver": "wss://irc-ws.chat.twitch.tv",
            "ircuser": "justinfan12345",
            "ircpass": "65432",
            "channel": null,
            "tinyemotesinstances": null,
            "fetchrecentmessages": null,
            "membership": null,
            "thirdpartyemotes": null
        };
        const badges = {};
        const emotes = {};
        
        window.addEventListener("load", () => {
            for (const [k, v] of new URLSearchParams(window.location.search)) {
                if (v.trim().length == 0) {
                    continue;
                }
                params[k] = v;
            }
            
            if (params.channel == null) {
                addSystemMessage("No channel specified!");
                return;
            }
            
            fetch(`https://api.ivr.fi/v2/twitch/user?login=${params["channel"]}`)
                .then((r) => r.json())
                .then((json) => {
                    if (json.length == 0) {
                        addSystemMessage(`Channel #${params["channel"]} does not exist.`);
                        return;
                    }
                    
                    user = json[0];
                    
                    if (params.fetchrecentmessages != null) {
                        getRecentMessages(user["login"]);
                    }
                    
                    connectToChat(params.ircserver, params.ircuser, params.ircpass, user["login"]);
                    getTwitchBadges(user["login"], badges);
                    
                    // adding emotes
                    const emotePromises = [
                        () => getFFZChannelEmotes(user["id"], emotes),
                        () => getFFZGlobalEmotes(emotes),
                        () => getBetterTTVGlobalEmotes(emotes),
                        () => getBetterTTVChannelEmotes(user["id"], emotes),
                        () => get7TVChannelEmotes(user["id"], emotes),
                        () => get7TVGlobalEmotes(emotes),
                    ];
                    
                    if (params["tinyemotesinstances"] != null) {
                        for (const url of params["tinyemotesinstances"].split("\n")) {
                            emotePromises.push(() => getTinyemotesChannelEmotes(url, user["id"], emotes));
                            emotePromises.push(() => getTinyemotesGlobalEmotes(url, emotes));
                        }
                    }
                    
                    if (params.thirdpartyemotes) {
                        emotePromises
                            .reduce((p, fn) => p.then(fn), Promise.resolve())
                            .then(() => addSystemMessage("All emotes loaded"));
                    }
                });
        });
    </script>
</html>