From 7e44b662b4f1f41646aaab2881e0c6684173270f Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Fri, 6 Sep 2024 15:57:54 +0100 Subject: [PATCH] send theme in share URL --- templates/tpos/index.html | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/templates/tpos/index.html b/templates/tpos/index.html index ea47174..63ac5b2 100644 --- a/templates/tpos/index.html +++ b/templates/tpos/index.html @@ -655,19 +655,32 @@
new Date(obj.time * 1000), 'YYYY-MM-DD HH:mm' ) - obj.tpos = ['/tpos/', obj.id].join('') - obj.shareUrl = [ - window.location.protocol, - '//', - window.location.host, - obj.tpos - ].join('') + obj.tpos = `/tpos/${obj.id}` + obj.shareUrl = `${window.location.protocol}//${window.location.host}${obj.tpos}` + obj.items = JSON.parse(obj.items) - obj.itemsMap = new Map() - obj.items.forEach((item, idx) => { - let id = `${obj.id}:${idx + 1}` - obj.itemsMap.set(id, {...item, id}) - }) + obj.itemsMap = new Map( + obj.items.map((item, idx) => { + const id = `${obj.id}:${idx + 1}` + return [id, {...item, id}] + }) + ) + + // Retrieve theme, dark mode, and gradient settings from localStorage. + const getSetting = key => + localStorage.getItem(`lnbits.${key}`)?.split('|')[1] || null + const theme = getSetting('theme') + const dark = getSetting('darkMode') + const gradient = getSetting('gradientBg') + + // Append the theme, dark, and gradient settings as query parameters to the share URL. + const url = new URL(obj.shareUrl) + theme && url.searchParams.append('theme', theme) + dark && url.searchParams.append('dark', dark) + gradient && url.searchParams.append('gradient', gradient) + + // Update the share URL in the object. + obj.shareUrl = url.toString() return obj }