]> OzVa Git service - shopping-channel/commitdiff
Jumping through some hoops to appease Twich
authorMax Value <greenwoodw50@gmail.com>
Tue, 8 Apr 2025 00:37:51 +0000 (01:37 +0100)
committerMax Value <greenwoodw50@gmail.com>
Tue, 8 Apr 2025 00:37:51 +0000 (01:37 +0100)
+ added * CORS ):
~ moved inline extension js into seperate file

extensions/product.html
extensions/product.js [new file with mode: 0644]
requirements.txt
teleshopping.py

index 3a1a4b7466c516bf3b94bc196cc2697510f54a49..823ad2dcdb0a1fc402c8090f6b6d33937d6796ff 100644 (file)
@@ -92,8 +92,9 @@ body {
 
                </style>
                <script src="https://extension-files.twitch.tv/helper/v1/twitch-ext.min.js"></script>
+               <script src="./product.js"></script>
        </head>
-       <body onload="setInterval(update, 20000);">
+       <body>
                <img id="image" src="https://shopping.ozva.co.uk/api/img/0"></img>
                <div id="nameContainer" class="hide">
             <div id="nameBadgeContainer">
@@ -103,54 +104,5 @@ body {
                 <h1 id="name" style="top: 0">Product Name!</h1>
             </div>
                </div>
-
-               <script>
-
-let pastId = 0;
-
-function update() {
-
-       // setup and hide the name element & the image element
-       const name = document.getElementById("nameContainer");
-       const image = document.getElementById("image");
-       name.classList.add("hide")
-
-       fetch("https://shopping.ozva.co.uk/api/items", {cache: "default"})
-    .then(data => data.json())
-    .then(dataStatic => {
-        fetch("https://shopping.ozva.co.uk/api", {cache: "no-store"})
-        .then(data => data.json())
-        .then(data => {
-
-            // some variable setup
-            let id = data.item_id;
-            const items = dataStatic.items
-            const item = items[id];
-
-                       // hide the image if the item has changed
-                       if (id != pastId) { image.classList.add("hide"); }
-
-                       // change the image if the item has changed as soon as ftb
-                       if (id != pastId) {
-                               setTimeout(function () {
-                                       image.src = `https://shopping.ozva.co.uk/api/img/${id}`;
-                               }, 3000);
-                       }
-
-
-                       // regester the function to update the name and show the badge
-                       setTimeout(function () {
-                               document.getElementById("name").innerHTML = item.subtext;
-
-                               pastId = id;
-
-                               image.classList.remove("hide");
-                               name.classList.remove("hide");
-                       }, 10000);
-               });
-       });
-}
-
-               </script>
        </body>
 </html>
diff --git a/extensions/product.js b/extensions/product.js
new file mode 100644 (file)
index 0000000..8e8cfbe
--- /dev/null
@@ -0,0 +1,46 @@
+let pastId = 0;
+
+function update() {
+
+       // setup and hide the name element & the image element
+       const name = document.getElementById("nameContainer");
+       const image = document.getElementById("image");
+       name.classList.add("hide")
+
+       fetch("https://shopping.ozva.co.uk/api/items", {cache: "default"})
+       .then(data => data.json())
+       .then(dataStatic => {
+               fetch("https://shopping.ozva.co.uk/api", {cache: "no-store"})
+               .then(data => data.json())
+               .then(data => {
+
+                       // some variable setup
+                       let id = data.item_id;
+                       const items = dataStatic.items
+                       const item = items[id];
+
+                       // hide the image if the item has changed
+                       if (id != pastId) { image.classList.add("hide"); }
+
+                       // change the image if the item has changed as soon as ftb
+                       if (id != pastId) {
+                               setTimeout(function () {
+                                       image.src = `https://shopping.ozva.co.uk/api/img/${id}`;
+                               }, 3000);
+                       }
+
+
+                       // regester the function to update the name and show the badge
+                       setTimeout(function () {
+                               document.getElementById("name").innerHTML = item.subtext;
+
+                               pastId = id;
+
+                               image.classList.remove("hide");
+                               name.classList.remove("hide");
+                       }, 10000);
+               });
+       });
+}
+
+setInterval(update, 20000);
index 83260ee34097e5a3b20c80e6dd1fecf68fcbcc8a..19c1262e151c7d6a92fb4f3c5f2f8ff34d5949fb 100644 (file)
@@ -1,5 +1,6 @@
 flask_httpauth
-flask
 markupsafe
+flask_cors
 werkzeug
 jinja2
+flask
index 04574efbe9c37c2868dd32dd7a06f9b644317db4..4944a27a1b1b04e2c1753928cc4515854bbb5df1 100755 (executable)
@@ -9,12 +9,15 @@ from os import path, environ, system
 from math import radians, cos, sin
 from markupsafe import escape
 from ast import literal_eval
+from flask_cors import CORS
 import sqlite3
 import json
 
 INCREMENT = 18
 
 app = Flask(__name__)
+CORS(app)
+
 auth = HTTPBasicAuth()
 try:
        app.root_path = environ["SHOPPING_PATH"]