From 529989438f8b355279ede60e9fa2308106e73f7c Mon Sep 17 00:00:00 2001 From: Max Value Date: Tue, 8 Apr 2025 01:37:51 +0100 Subject: [PATCH] Jumping through some hoops to appease Twich + added * CORS ): ~ moved inline extension js into seperate file --- extensions/product.html | 52 ++--------------------------------------- extensions/product.js | 46 ++++++++++++++++++++++++++++++++++++ requirements.txt | 3 ++- teleshopping.py | 3 +++ 4 files changed, 53 insertions(+), 51 deletions(-) create mode 100644 extensions/product.js diff --git a/extensions/product.html b/extensions/product.html index 3a1a4b7..823ad2d 100644 --- a/extensions/product.html +++ b/extensions/product.html @@ -92,8 +92,9 @@ body { + - +
@@ -103,54 +104,5 @@ body {

Product Name!

- - diff --git a/extensions/product.js b/extensions/product.js new file mode 100644 index 0000000..8e8cfbe --- /dev/null +++ b/extensions/product.js @@ -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); diff --git a/requirements.txt b/requirements.txt index 83260ee..19c1262 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ flask_httpauth -flask markupsafe +flask_cors werkzeug jinja2 +flask diff --git a/teleshopping.py b/teleshopping.py index 04574ef..4944a27 100755 --- a/teleshopping.py +++ b/teleshopping.py @@ -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"] -- 2.39.2