pub / tw2html

Checks online status of streams on twitch.tv and lets you watch them
git clone https://https://src.jayvii.de/pub/tw2html.git
Home | Log | Files | Exports | Refs | README | RSS

index.php (4520B)


      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     $streams = array_unique($streams);
     42 
     43     /* refresh cookie */
     44     header(
     45       "Set-Cookie: " .
     46       "streams=" . implode(",", $streams) . ";" .
     47       "Max-Age=" . 31536000 . "; " . /* 60 x 60 x 24 x 365 = 1 year */
     48       "Domain=" . $_SERVER["SERVER_NAME"] . "; " .
     49       "SameSite=Strict;"
     50     );
     51 
     52   ?>
     53 
     54   <body onload="tw2html_daemon();">
     55 
     56   <header>
     57 
     58     <!-- Buttons -->
     59     <nav>
     60       <a href="#" onclick="tw2html_reload();">Reload</a>
     61       <a href="#streams">Streams</a>
     62       <a href="https://src.jayvii.de/pub/tw2html" target="_blank">
     63         Development
     64       </a>
     65     </nav>
     66 
     67     <!-- Headline -->
     68     <h1>Streams</h1>
     69 
     70     <!-- Loading Indicator -->
     71     <div id="loading_indicator">
     72       <?php
     73         foreach ($streams as $stream) {
     74       ?>
     75         <span
     76           class="loading_indicator"
     77           id="loading_indicator_<?php echo $stream; ?>"
     78           title="<?php echo $stream; ?>"
     79         >
     80     81         </span>
     82       <?php
     83         }
     84       ?>
     85     </div>
     86 
     87   </header>
     88 
     89   <!-- Search Bar -->
     90   <form
     91     action="https://www.twitch.tv/search"
     92     method="GET"
     93     target="_blank"
     94   >
     95       <input
     96         id="searchbar"
     97         type="text"
     98         id="searchInput"
     99         name="term"
    100         placeholder="Search on twitch.tv"
    101       >
    102   </form>
    103 
    104   <!-- Stream List Form -->
    105   <details id="streams">
    106     <summary>List of Streams</summary>
    107     <p>
    108       Please enter the Twitch.TV usernames of streams you want to check here, each
    109       separated with a <code>,</code>:
    110     </p>
    111     <form action="/" method="POST">
    112       <textarea
    113         name="streams"
    114         placeholder="streamerA, streamerB, ..."
    115       ><?php echo implode("," . PHP_EOL, $streams); ?></textarea>
    116       <input type="submit" value="Submit &amp; Reload">
    117     </form>
    118   </details>
    119 
    120   <!-- Streams List -->
    121   <?php
    122 
    123     foreach ($streams as $stream) {
    124 
    125   ?>
    126 
    127   <!-- Section for streamer <?php echo $stream; ?> (hidden by default) -->
    128   <section class="hidden streams" id="stream_<?php echo $stream; ?>">
    129 
    130     <!-- Headline: streamer name -->
    131     <h2>
    132       <?php echo $stream; ?>
    133     </h2>
    134 
    135     <!-- player Container -->
    136     <div class="player_container hidden"></div>
    137 
    138     <!-- Preview Image -->
    139     <img
    140       id="preview_<?php echo $stream; ?>"
    141       class="preview"
    142       src=""
    143       loading="lazy"
    144     >
    145 
    146     <!-- Stream Button -->
    147     <button onclick="tw2html_toggle_player('<?php echo $stream; ?>')">
    148       Toggle Player
    149     </button>
    150     <a
    151       class="button"
    152       href="https://www.twitch.tv/<?php echo $stream; ?>"
    153       target="_blank"
    154     >
    155       Open on Twitch
    156     </a>
    157     
    158 
    159 
    160     <!-- Chat Collapsable -->
    161     <details class="button">
    162         <summary onclick="tw2html_toggle_chat('<?php echo $stream; ?>');">
    163             Chat
    164         </summary>
    165         <div class="chat_container"></div>
    166     </details>
    167 
    168   </section>
    169 
    170   <?php
    171 
    172     }
    173 
    174   ?>
    175 
    176   </body>
    177 
    178 </html>