index.php (4540B)
1 <!-- SPDX-License-Identifier: AGPL-3.0-or-later
2 SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
3 -->
4
5 <!DOCTYPE html>
6 <html>
7
8 <head>
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 <title>Twitch Streams</title>
11 <link rel="icon" type="image/png" href="assets/img/twitch.png">
12 <link rel="icon" type="image/png" sizes="16x16" href="assets/img/twitch_16.png">
13 <link rel="icon" type="image/png" sizes="32x32" href="assets/img/twitch_32.png">
14 <link rel="icon" type="image/png" sizes="64x64" href="assets/img/twitch_64.png">
15 <link rel="icon" type="image/png" sizes="128x128" href="assets/img/twitch_128.png">
16 <link rel="apple-touch-icon" href="assets/img/twitch.png">
17 <link rel="stylesheet" type="text/css" href="assets/css/simple.min.css"/>
18 <link rel="stylesheet" href="assets/css/custom.css" />
19 <script async src="assets/js/twitch.js"></script>
20 <link crossorigin="use-credentials" rel="manifest" href="manifest.json">
21 <meta name="viewport" content="width=device-width, initial-scale=1.0">
22 </head>
23
24 <?php
25
26 /* Initilise streams array */
27 $streams = array();
28
29 // Fetch POST argument or the COOKIE
30 // Cookie should have lowest priority (fallback), POST first (intend)
31 if (!is_null($_COOKIE["streams"])) {
32 $streams = explode(",", $_COOKIE["streams"]);
33 }
34 if (!is_null($_POST["streams"])) {
35 $streams = urldecode($_POST["streams"]);
36 $streams = preg_replace('/[^a-z0-9\-\_\.\,]+/', '', $streams);
37 $streams = explode(",", $streams);
38 }
39
40 // Sort streams by alphabet and ensure each stream is unique
41 sort($streams);
42 $streams = array_unique($streams);
43
44 /* refresh cookie */
45 header(
46 "Set-Cookie: " .
47 "streams=" . implode(",", $streams) . ";" .
48 "Max-Age=" . 31536000 . "; " . /* 60 x 60 x 24 x 365 = 1 year */
49 "Domain=" . $_SERVER["SERVER_NAME"] . "; " .
50 "SameSite=Strict;"
51 );
52
53 ?>
54
55 <body onload="tw2html_daemon();">
56
57 <header>
58
59 <!-- Buttons -->
60 <nav>
61 <a href="#" onclick="tw2html_reload();">Reload</a>
62 <a href="#streams">Streams</a>
63 <a href="https://src.jayvii.de/pub/tw2html" target="_blank">
64 Development
65 </a>
66 </nav>
67
68 <!-- Headline -->
69 <h1>Streams</h1>
70
71 <!-- Loading Indicator -->
72 <div id="loading_indicator">
73 <?php
74 foreach ($streams as $stream) {
75 ?>
76 <span
77 class="loading_indicator"
78 id="loading_indicator_<?php echo $stream; ?>"
79 title="<?php echo $stream; ?>"
80 >
81 ■
82 </span>
83 <?php
84 }
85 ?>
86 </div>
87
88 </header>
89
90 <!-- Search Bar -->
91 <form
92 action="https://www.twitch.tv/search"
93 method="GET"
94 target="_blank"
95 >
96 <input
97 id="searchbar"
98 type="text"
99 id="searchInput"
100 name="term"
101 placeholder="Search on twitch.tv"
102 >
103 </form>
104
105 <!-- Stream List Form -->
106 <details id="streams">
107 <summary>List of Streams</summary>
108 <p>
109 Please enter the Twitch.TV usernames of streams you want to check here, each
110 separated with a <code>,</code>:
111 </p>
112 <form action="/" method="POST">
113 <textarea
114 name="streams"
115 placeholder="streamerA, streamerB, ..."
116 ><?php echo implode("," . PHP_EOL, $streams); ?></textarea>
117 <input type="submit" value="Submit & Reload">
118 </form>
119 </details>
120
121 <!-- Streams List -->
122 <?php
123
124 foreach ($streams as $stream) {
125
126 ?>
127
128 <!-- Section for streamer <?php echo $stream; ?> (hidden by default) -->
129 <section class="hidden streams" id="stream_<?php echo $stream; ?>">
130
131 <!-- Headline: streamer name -->
132 <h2>
133 <?php echo $stream; ?>
134 </h2>
135
136 <!-- player Container -->
137 <div class="player_container hidden"></div>
138
139 <!-- Preview Image -->
140 <img
141 id="preview_<?php echo $stream; ?>"
142 class="preview"
143 src=""
144 loading="lazy"
145 >
146
147 <!-- Stream Button -->
148 <button onclick="tw2html_toggle_player('<?php echo $stream; ?>')">
149 Toggle Player
150 </button>
151 <a
152 class="button"
153 href="https://www.twitch.tv/<?php echo $stream; ?>"
154 target="_blank"
155 >
156 Open on Twitch
157 </a>
158
159
160
161 <!-- Chat Collapsable -->
162 <details class="button">
163 <summary onclick="tw2html_toggle_chat('<?php echo $stream; ?>');">
164 Chat
165 </summary>
166 <div class="chat_container"></div>
167 </details>
168
169 </section>
170
171 <?php
172
173 }
174
175 ?>
176
177 </body>
178
179 </html>