From: Chris Fulljames Date: Sat, 8 Feb 2025 00:32:50 +0000 (-0500) Subject: Palette swap gifs using user profile colors X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=838fc5db1e26e729eb5222d771ed4747fc8c8b51;p=littlesongplace.git Palette swap gifs using user profile colors --- diff --git a/main.py b/main.py index 92c2a1e..856e062 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import base64 import json import logging import os @@ -695,6 +696,23 @@ def sanitize_user_text(text): attributes=allowed_attributes, css_sanitizer=css_sanitizer) +def get_gif_data(): + gifs = [] + static_path = Path(__file__).parent / "static" + for child in static_path.iterdir(): + if child.suffix == ".gif": + with open(child, "rb") as gif: + b64 = base64.b64encode(gif.read()).decode() + gifs.append(f'
') + + gifs = "\n".join(gifs) + return gifs + +@app.context_processor +def inject_global_vars(): + return dict(gif_data=get_gif_data()) + + ################################################################################ # Database ################################################################################ diff --git a/static/player.js b/static/player.js index c55fdf0..868e8dd 100644 --- a/static/player.js +++ b/static/player.js @@ -157,12 +157,14 @@ document.addEventListener("DOMContentLoaded", (event) => { // Show pause button when audio is playing var button = document.getElementById("play-pause-button"); audio.addEventListener("play", (event) => { - button.src = "/static/lsp_btn_pause02.gif"; + button.className = "lsp_btn_pause02"; + button.src = customImage(document.getElementById("lsp_btn_pause02")); }) // Show play button when audio is paused audio.addEventListener("pause", (event) => { - button.src = "/static/lsp_btn_play02.gif"; + button.className = "lsp_btn_play02"; + button.src = customImage(document.getElementById("lsp_btn_play02")); }) // Audio position scrubbing diff --git a/templates/base.html b/templates/base.html index b1d4639..693afd3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,9 +12,61 @@ + + {{ gif_data|safe }} + + +