pub / tw2html

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

index.php (3200B)


      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 <?php
      9 
     10 // Fetch GET and POST arguments
     11 if (is_null($_POST["streams"])) {
     12   $loading_screen = true;
     13   if (!is_null($_GET["streams"])) {
     14     $channels = explode(",", $_GET["streams"]);
     15   } else {
     16     $channels = explode(",", $_COOKIE["streams"]);
     17   }
     18 } else {
     19   $loading_screen = false;
     20   $channels = unserialize($_POST["streams"]);
     21 }
     22 
     23 // Prepare streams array
     24 $streams = array(
     25     "stream" => $channels,
     26     "desc" => array(),
     27     "game" => array(),
     28     "status" => array(),
     29     "time" => array()
     30 );
     31 
     32 ?>
     33 
     34   <head>
     35     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     36     <title>Twitch Streams</title>
     37     <link rel="icon" type="image/png" href="assets/img/twitch.png">
     38     <link rel="icon" type="image/png" sizes="16x16" href="assets/img/twitch_16.png">
     39     <link rel="icon" type="image/png" sizes="32x32" href="assets/img/twitch_32.png">
     40     <link rel="icon" type="image/png" sizes="64x64" href="assets/img/twitch_64.png">
     41     <link rel="icon" type="image/png" sizes="128x128" href="assets/img/twitch_128.png">
     42     <link rel="apple-touch-icon" href="assets/img/twitch.png">
     43     <link rel="stylesheet" type="text/css" href="assets/css/simple.min.css"/>
     44     <link rel="stylesheet" href="assets/css/loading.css" />
     45     <link rel="stylesheet" href="assets/css/custom.css" />
     46     <script async src="assets/js/twitch.js"></script>
     47     <link crossorigin="use-credentials" rel="manifest" href="manifest.json">
     48     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     49   </head>
     50 
     51   <body>
     52 
     53   <header>
     54     <h1>Streams</h1>
     55     <!-- Save Button -->
     56     <a
     57       id="savebtn"
     58       class="button"
     59       href="#"
     60       onclick="document.cookie='streams=<?php echo implode(",", $streams["stream"]); ?>;path=/;max-age=31536000;';document.querySelector('#savebtn').style.color='inherit';"
     61       <?php
     62         if (implode(",", $streams["stream"]) != $_COOKIE["streams"]) {
     63            echo "style=color:#db4325";
     64         }
     65       ?>
     66     >
     67       Save
     68     </a>
     69     <!-- Reload Button -->
     70     <a
     71       class="button"
     72       href="<?php echo "/?streams=" . implode(",", $streams["stream"]); ?>"
     73     >
     74       Reload
     75     </a>
     76     <!-- Live pseudo-button -->
     77     <a class="button" href="#streams">
     78       Live: <span id="num_streams">0</span>
     79     </a>
     80   </header>
     81 
     82   <!-- Search Bar -->
     83   <form action="https://www.twitch.tv/search" method="GET" target="_blank" style="width:100%;margin-top:1em;">
     84       <input id="searchbar" type="text" id="searchInput" name="term" placeholder="Search on twitch.tv">
     85   </form>
     86 
     87   <div id="streams">
     88 
     89 <?php
     90 
     91 // Streams or Loading Screen
     92 if (!$loading_screen) {
     93   // Load Stream Data
     94   include("lib/load_streams.php");
     95   // Build HTML from Stream Data
     96   include("lib/build_html.php");
     97 } else {
     98   // Load Loading Screen content
     99   include("lib/loadingscreen.php");
    100 }
    101 
    102 ?>
    103 
    104   </div>
    105 
    106   </body>
    107 
    108   <!-- Script for counting active streams -->
    109   <script>
    110     var num_streams = document.querySelectorAll(".streamlisting").length;
    111     document.querySelector("#num_streams").innerText = num_streams;
    112   </script>
    113   
    114 </html>