From 62caee7fd810b572d1668b6f547001827ace3a1d Mon Sep 17 00:00:00 2001 From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:51:01 -0500 Subject: [PATCH] adaptive qr code, dark mode and more - Dark mode is set based on user browser info - QR Code changes colours based on dark or light mode - "DUP" controlPerm for preventing duplicates in the future - Fully implemented in the server but not yet the client --- Client/scripts.js | 28 +++++++++++++++++++--------- Server/webbyBits.py | 12 +++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Client/scripts.js b/Client/scripts.js index cb7361e..7b612d5 100644 --- a/Client/scripts.js +++ b/Client/scripts.js @@ -8,9 +8,12 @@ const VALID_FILE_EXT = ["mp3","flac","wav"]; const params = new URLSearchParams(location.search); let darkmodetemp = getCookie("darkmode"); +if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + darkmodetemp = "true"; +} if(darkmodetemp === "") { darkmodetemp = params.get("darkmode") -} +} if (darkmodetemp === "true") { // i know this is gonna cause weird blinking // maybe the dark mode function should be loaded before any content, would that work? @@ -64,7 +67,7 @@ async function getFromServer(bodyInfo, source="",password=adminPass) { } catch(e) { // console.log("error print here:"); // console.log(e); - if (e == "TypeError: Failed to fetch"){ + if (e.toString().contains("TypeError: Failed to fetch")){ alertText("Error: Can't Connect to Server (is the ip set?)") } else { alertText("Error: " + e); @@ -194,7 +197,11 @@ function alertTimeSet(time) { function ipSetEnter(e){ if (e.key == "Enter") { - e.preventDefault(); + e.preventDefault(); + // why on gosh's green earth am i sending a value here? + // im gonna get rid of all these individual "enter" dectectors and do something + // like i did for the keyboard selection of elements + // basically just if(e==click || e.key == enter) ipSetter(document.getElementById("iptextbox").value) } } @@ -222,13 +229,16 @@ function ipSetter(){ function qrCodeGenerate() { let tempURL = "http://" + document.location.href.split("/")[2] + "/?ip=" + ip; - document.getElementById("qrcode").innerHTML = "" + document.getElementById("qrcode").innerHTML = ""; + // get the current foreground and background + let dark = window.getComputedStyle(document.body).getPropertyValue("--text-color"); + let light = window.getComputedStyle(document.body).getPropertyValue("--bg-main"); new QRCode(document.getElementById("qrcode"), { text: tempURL, width: 256, height: 256, - colorDark : "#000000", - colorLight : "#eeeeee", + colorDark : dark, + colorLight : light, correctLevel : QRCode.CorrectLevel.H }); } @@ -349,8 +359,8 @@ async function submitSong(songid) { let returncode = await getFromServer({song: songid}, "songadd"); if(returncode == ERR_NO_ADMIN) { // right now the error is alerted in getFromServer, maybe will change that - } else if(returncode["error"]=="song-in-queue") { - alertText("That song's about to play! Hang on!") + } else if(returncode["status"]!==200) { + alertText("That song's already in the queue! Hang on!") } else { alertText("Added to Queue"); } @@ -382,7 +392,7 @@ function toggleDark(e) { document.getElementById("darkmode-button").innerHTML = "Off"; x.remove("dark-mode"); } - + qrCodeGenerate(); } async function sha256(message) { diff --git a/Server/webbyBits.py b/Server/webbyBits.py index c20959c..cbab57f 100644 --- a/Server/webbyBits.py +++ b/Server/webbyBits.py @@ -28,7 +28,8 @@ controlPerms = { "SK":True, "AS":True, "PM":True, - "VOL":True + "VOL":True, + "DUP":True # Not implemented, allow duplicate songs in queue } fileofDB = sql.connect("songDatabase.db") @@ -215,12 +216,9 @@ def songadd(): try: if (ADMIN_PASS == recieveData['password']) or controlPerms["AS"]: # Password exists and is correct, or it's not restricted - # if (recieveData['song'] in playlist): - # return {"error":"song-in-queue"} - # else: - # Right now the above is disabled since i want to make it optional first - # probably with a checkbox like the other admin controls - if True: + if not(controlPerms["DUP"]) and (recieveData['song'] in playlist) and not(ADMIN_PASS == recieveData['password']): + return {"error":"This song is already in the queue, hang on!","data":None},409 + else: queueSong(recieveData['song']) return ERR_200 else: