diff --git a/webapp/app.js b/webapp/app.js index a135ef5..5e59c46 100644 --- a/webapp/app.js +++ b/webapp/app.js @@ -24,15 +24,41 @@ return "light"; } + /** + * Map Telegram themeParams (snake_case) to CSS variables (--tg-theme-*). + * Only set when Telegram WebApp and themeParams are available. + */ + function applyThemeParamsToCss() { + var twa = window.Telegram?.WebApp; + var params = twa?.themeParams; + if (!params) return; + var root = document.documentElement; + var map = [ + ["bg_color", "bg-color"], + ["secondary_bg_color", "secondary-bg-color"], + ["text_color", "text-color"], + ["hint_color", "hint-color"], + ["link_color", "link-color"], + ["button_color", "button-color"], + ["header_bg_color", "header-bg-color"], + ["accent_text_color", "accent-text-color"] + ]; + map.forEach(function (pair) { + var value = params[pair[0]]; + if (value) root.style.setProperty("--tg-theme-" + pair[1], value); + }); + } + function applyTheme() { var scheme = getTheme(); document.documentElement.dataset.theme = scheme; - var bg = THEME_BG[scheme] || THEME_BG.dark; - if (window.Telegram?.WebApp?.setBackgroundColor) { - window.Telegram.WebApp.setBackgroundColor(bg); - } - if (window.Telegram?.WebApp?.setHeaderColor) { - window.Telegram.WebApp.setHeaderColor(bg); + var twa = window.Telegram?.WebApp; + if (twa) { + if (twa.setBackgroundColor) twa.setBackgroundColor("bg_color"); + if (twa.setHeaderColor) twa.setHeaderColor("bg_color"); + applyThemeParamsToCss(); + } else { + /* Outside Telegram: only data-theme is set; no setBackgroundColor/setHeaderColor. */ } } diff --git a/webapp/favicon.png b/webapp/favicon.png new file mode 100644 index 0000000..34f4c8d Binary files /dev/null and b/webapp/favicon.png differ diff --git a/webapp/index.html b/webapp/index.html index e64ec3f..b55a016 100644 --- a/webapp/index.html +++ b/webapp/index.html @@ -3,6 +3,7 @@
+