updated widgets
This commit is contained in:
+155
-101
@@ -309,15 +309,20 @@ data:
|
||||
# Todo Widget
|
||||
# --------------------------------
|
||||
@APP.get("/userdata/todo")
|
||||
def todo_widget(key: str = "", user: str = "default", accent: str = "4ade80", bgcolor: str = "0d1117"):
|
||||
def todo_widget(key: str = "", user: str = "default", accent: str = "5ac8d8", bgcolor: str = "transparent"):
|
||||
"""Serve the Todo widget HTML page."""
|
||||
expected_key = os.environ.get("GLANCE_HELPER_KEY", "")
|
||||
if key != expected_key:
|
||||
return Response(content="Unauthorized", status_code=401)
|
||||
|
||||
safe_user = re.sub(r'[^a-zA-Z0-9_-]', '', user) or "default"
|
||||
safe_accent = re.sub(r'[^a-fA-F0-9]', '', accent)[:6] or "4ade80"
|
||||
safe_bgcolor = re.sub(r'[^a-fA-F0-9]', '', bgcolor)[:6] or "0d1117"
|
||||
safe_accent = re.sub(r'[^a-fA-F0-9]', '', accent)[:6] or "5ac8d8"
|
||||
# Handle transparent background
|
||||
if bgcolor == "transparent" or not bgcolor:
|
||||
bg_style = "transparent"
|
||||
else:
|
||||
safe_bgcolor = re.sub(r'[^a-fA-F0-9]', '', bgcolor)[:6]
|
||||
bg_style = f"#{safe_bgcolor}" if safe_bgcolor else "transparent"
|
||||
|
||||
sections = load_userdata(safe_user)
|
||||
todos = sections.get("Todo", [])
|
||||
@@ -345,10 +350,9 @@ data:
|
||||
--accent-20: #{safe_accent}33;
|
||||
--accent-40: #{safe_accent}66;
|
||||
--accent-60: #{safe_accent}99;
|
||||
--bgcolor: #{safe_bgcolor};
|
||||
}}
|
||||
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
||||
html, body {{ background: var(--bgcolor); height: 100%; }}
|
||||
html, body {{ background: {bg_style}; height: 100%; }}
|
||||
body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: rgba(255,255,255,0.9); }}
|
||||
.container {{ display: flex; flex-direction: column; height: 100%; padding: 8px; gap: 8px; }}
|
||||
.todo-list {{ flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }}
|
||||
@@ -364,7 +368,7 @@ data:
|
||||
width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent);
|
||||
flex-shrink: 0;
|
||||
}}
|
||||
.todo-text {{ flex: 1; font-size: 14px; line-height: 1.4; word-break: break-word; }}
|
||||
.todo-text {{ flex: 1; font-size: 14px; line-height: 1.4; word-break: break-word; color: rgba(255,255,255,0.85); }}
|
||||
.todo-delete {{
|
||||
opacity: 0; background: none; border: none; cursor: pointer;
|
||||
font-size: 14px; padding: 4px; transition: opacity 0.15s;
|
||||
@@ -377,7 +381,7 @@ data:
|
||||
color: rgba(255,255,255,0.9); font-size: 14px; outline: none;
|
||||
}}
|
||||
.add-input:focus {{ border-color: var(--accent-40); background: rgba(255,255,255,0.1); }}
|
||||
.add-input::placeholder {{ color: var(--accent-40); }}
|
||||
.add-input::placeholder {{ color: rgba(255,255,255,0.4); }}
|
||||
.add-btn {{
|
||||
padding: 10px 16px; background: var(--accent-20); border: none;
|
||||
border-radius: 6px; color: var(--accent); font-size: 14px; cursor: pointer;
|
||||
@@ -491,15 +495,19 @@ data:
|
||||
import random as _random
|
||||
|
||||
@APP.get("/userdata/motivation")
|
||||
def motivation_widget(key: str = "", user: str = "default", accent: str = "4ade80", bgcolor: str = "0d1117"):
|
||||
"""Serve the Motivation widget HTML page with random quote and settings modal."""
|
||||
def motivation_widget(key: str = "", user: str = "default", accent: str = "5ac8d8", bgcolor: str = "transparent"):
|
||||
"""Serve the Motivation widget HTML page with random quote."""
|
||||
expected_key = os.environ.get("GLANCE_HELPER_KEY", "")
|
||||
if key != expected_key:
|
||||
return Response(content="Unauthorized", status_code=401)
|
||||
|
||||
safe_user = re.sub(r'[^a-zA-Z0-9_-]', '', user) or "default"
|
||||
safe_accent = re.sub(r'[^a-fA-F0-9]', '', accent)[:6] or "4ade80"
|
||||
safe_bgcolor = re.sub(r'[^a-fA-F0-9]', '', bgcolor)[:6] or "0d1117"
|
||||
safe_accent = re.sub(r'[^a-fA-F0-9]', '', accent)[:6] or "5ac8d8"
|
||||
if bgcolor == "transparent" or not bgcolor:
|
||||
bg_style = "transparent"
|
||||
else:
|
||||
safe_bgcolor = re.sub(r'[^a-fA-F0-9]', '', bgcolor)[:6]
|
||||
bg_style = f"#{safe_bgcolor}" if safe_bgcolor else "transparent"
|
||||
|
||||
sections = load_userdata(safe_user)
|
||||
quotes = sections.get("Motivation", [])
|
||||
@@ -508,11 +516,8 @@ data:
|
||||
current_quote = _random.choice(quotes) if quotes else "Add your first motivational quote!"
|
||||
current_quote_escaped = current_quote.replace("&", "&").replace("<", "<").replace(">", ">").replace('"', """)
|
||||
|
||||
# Build quotes list for modal
|
||||
quotes_html = ""
|
||||
for i, q in enumerate(quotes):
|
||||
q_escaped = q.replace("&", "&").replace("<", "<").replace(">", ">").replace('"', """)
|
||||
quotes_html += f'<div class="quote-item" data-index="{i}"><span class="quote-text">{q_escaped}</span><button class="quote-delete" onclick="deleteQuote({i})">×</button></div>'
|
||||
# Build manage URL (opens in new tab)
|
||||
manage_url = f"/userdata/motivation/manage?key={expected_key}&user={safe_user}&accent={safe_accent}"
|
||||
|
||||
html = f"""<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -522,113 +527,149 @@ data:
|
||||
<style>
|
||||
:root {{
|
||||
--accent: #{safe_accent};
|
||||
--accent-20: #{safe_accent}33;
|
||||
--accent-40: #{safe_accent}66;
|
||||
--accent-60: #{safe_accent}99;
|
||||
--bgcolor: #{safe_bgcolor};
|
||||
}}
|
||||
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
||||
html, body {{ background: var(--bgcolor); height: 100%; }}
|
||||
body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: rgba(255,255,255,0.9); }}
|
||||
.container {{ display: flex; flex-direction: column; height: 100%; padding: 12px; position: relative; }}
|
||||
html, body {{ background: {bg_style}; height: 100%; }}
|
||||
body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: rgba(255,255,255,0.85); }}
|
||||
.container {{ display: flex; flex-direction: column; height: 100%; padding: 8px 12px; position: relative; }}
|
||||
.settings-btn {{
|
||||
position: absolute; top: 8px; right: 8px;
|
||||
position: absolute; top: 4px; right: 4px;
|
||||
background: none; border: none; cursor: pointer;
|
||||
font-size: 16px; opacity: 0.4; transition: opacity 0.15s;
|
||||
font-size: 14px; opacity: 0.3; transition: opacity 0.15s;
|
||||
text-decoration: none; color: inherit;
|
||||
}}
|
||||
.settings-btn:hover {{ opacity: 0.8; }}
|
||||
.settings-btn:hover {{ opacity: 0.7; }}
|
||||
.quote-display {{
|
||||
flex: 1; display: flex; align-items: center; justify-content: center;
|
||||
text-align: center; padding: 8px 28px;
|
||||
text-align: center; padding: 4px 24px;
|
||||
}}
|
||||
.quote-text-main {{
|
||||
font-size: 15px; line-height: 1.5; font-style: italic;
|
||||
color: var(--accent); opacity: 0.9;
|
||||
font-size: 14px; line-height: 1.5; font-style: italic;
|
||||
color: rgba(255,255,255,0.8);
|
||||
}}
|
||||
.quote-count {{
|
||||
font-size: 11px; opacity: 0.4; text-align: center; padding-bottom: 4px;
|
||||
.quote-footer {{
|
||||
font-size: 11px; opacity: 0.4; text-align: center; padding-top: 4px;
|
||||
}}
|
||||
/* Modal */
|
||||
.modal-overlay {{
|
||||
display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
|
||||
align-items: center; justify-content: center; z-index: 1000;
|
||||
}}
|
||||
.modal-overlay.open {{ display: flex; }}
|
||||
.modal {{
|
||||
background: #1a1a2e; border-radius: 12px; width: 90%; max-width: 400px;
|
||||
max-height: 80%; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
|
||||
}}
|
||||
.modal-header {{
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
padding: 16px; border-bottom: 1px solid rgba(255,255,255,0.1);
|
||||
}}
|
||||
.modal-title {{ font-size: 16px; font-weight: 600; }}
|
||||
.modal-close {{
|
||||
background: none; border: none; font-size: 24px; cursor: pointer;
|
||||
color: rgba(255,255,255,0.6); line-height: 1;
|
||||
}}
|
||||
.modal-close:hover {{ color: rgba(255,255,255,0.9); }}
|
||||
.modal-body {{ flex: 1; overflow-y: auto; padding: 12px; }}
|
||||
.quote-item {{
|
||||
display: flex; align-items: flex-start; gap: 8px; padding: 10px;
|
||||
background: rgba(255,255,255,0.04); border-radius: 6px; margin-bottom: 8px;
|
||||
}}
|
||||
.quote-item .quote-text {{ flex: 1; font-size: 13px; line-height: 1.4; word-break: break-word; }}
|
||||
.quote-delete {{
|
||||
background: none; border: none; cursor: pointer; font-size: 18px;
|
||||
color: rgba(255,255,255,0.4); padding: 0 4px; line-height: 1;
|
||||
}}
|
||||
.quote-delete:hover {{ color: #f87171; }}
|
||||
.modal-footer {{ padding: 12px; border-top: 1px solid rgba(255,255,255,0.1); }}
|
||||
.add-form {{ display: flex; gap: 8px; }}
|
||||
.add-input {{
|
||||
flex: 1; padding: 10px 12px; border: 1px solid var(--accent-20);
|
||||
background: rgba(255,255,255,0.06); border-radius: 6px;
|
||||
color: rgba(255,255,255,0.9); font-size: 14px; outline: none;
|
||||
}}
|
||||
.add-input:focus {{ border-color: var(--accent-40); }}
|
||||
.add-btn {{
|
||||
padding: 10px 16px; background: var(--accent-20); border: none;
|
||||
border-radius: 6px; color: var(--accent); font-size: 14px; cursor: pointer;
|
||||
}}
|
||||
.add-btn:hover {{ background: var(--accent-40); }}
|
||||
.empty-state {{ text-align: center; padding: 20px; opacity: 0.5; font-size: 13px; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<button class="settings-btn" onclick="openModal()" title="Manage quotes">⚙️</button>
|
||||
<a class="settings-btn" href="{manage_url}" target="_blank" title="Manage quotes">⚙️</a>
|
||||
<div class="quote-display">
|
||||
<div class="quote-text-main">"{current_quote_escaped}"</div>
|
||||
</div>
|
||||
<div class="quote-count">{len(quotes)} quote{'s' if len(quotes) != 1 else ''}</div>
|
||||
<div class="quote-footer">{len(quotes)} quote{'s' if len(quotes) != 1 else ''}</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-overlay" id="modal" onclick="if(event.target===this)closeModal()">
|
||||
<div class="modal">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title">Manage Quotes</div>
|
||||
<button class="modal-close" onclick="closeModal()">×</button>
|
||||
</div>
|
||||
<div class="modal-body" id="quotesList">
|
||||
{quotes_html if quotes_html else '<div class="empty-state">No quotes yet. Add your first one below!</div>'}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="add-form">
|
||||
<input type="text" class="add-input" id="newQuote" placeholder="Add a new quote..." onkeypress="if(event.key==='Enter')addQuote()">
|
||||
<button class="add-btn" onclick="addQuote()">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>"""
|
||||
return Response(content=html, media_type="text/html")
|
||||
|
||||
@APP.get("/userdata/motivation/manage")
|
||||
def motivation_manage(key: str = "", user: str = "default", accent: str = "5ac8d8"):
|
||||
"""Full-page management interface for motivation quotes."""
|
||||
expected_key = os.environ.get("GLANCE_HELPER_KEY", "")
|
||||
if key != expected_key:
|
||||
return Response(content="Unauthorized", status_code=401)
|
||||
|
||||
safe_user = re.sub(r'[^a-zA-Z0-9_-]', '', user) or "default"
|
||||
safe_accent = re.sub(r'[^a-fA-F0-9]', '', accent)[:6] or "5ac8d8"
|
||||
|
||||
sections = load_userdata(safe_user)
|
||||
quotes = sections.get("Motivation", [])
|
||||
|
||||
# Build quotes list HTML
|
||||
quotes_html = ""
|
||||
for i, q in enumerate(quotes):
|
||||
q_escaped = q.replace("&", "&").replace("<", "<").replace(">", ">").replace('"', """)
|
||||
quotes_html += f'''<div class="quote-item" data-index="{i}">
|
||||
<span class="quote-num">{i+1}.</span>
|
||||
<span class="quote-text">{q_escaped}</span>
|
||||
<button class="quote-delete" onclick="deleteQuote({i})" title="Delete">×</button>
|
||||
</div>'''
|
||||
|
||||
html = f"""<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Manage Motivation Quotes</title>
|
||||
<style>
|
||||
:root {{
|
||||
--accent: #{safe_accent};
|
||||
--accent-20: #{safe_accent}33;
|
||||
--accent-40: #{safe_accent}66;
|
||||
}}
|
||||
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
||||
html, body {{ background: #0d1117; min-height: 100vh; }}
|
||||
body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: rgba(255,255,255,0.9); }}
|
||||
.container {{ max-width: 600px; margin: 0 auto; padding: 24px 16px; }}
|
||||
.header {{ margin-bottom: 24px; }}
|
||||
.header h1 {{ font-size: 20px; font-weight: 600; margin-bottom: 4px; color: var(--accent); }}
|
||||
.header p {{ font-size: 13px; opacity: 0.6; }}
|
||||
.add-form {{ display: flex; gap: 8px; margin-bottom: 20px; }}
|
||||
.add-input {{
|
||||
flex: 1; padding: 12px 14px; border: 1px solid var(--accent-20);
|
||||
background: rgba(255,255,255,0.06); border-radius: 8px;
|
||||
color: rgba(255,255,255,0.9); font-size: 14px; outline: none;
|
||||
}}
|
||||
.add-input:focus {{ border-color: var(--accent-40); background: rgba(255,255,255,0.1); }}
|
||||
.add-input::placeholder {{ color: rgba(255,255,255,0.4); }}
|
||||
.add-btn {{
|
||||
padding: 12px 20px; background: var(--accent-20); border: none;
|
||||
border-radius: 8px; color: var(--accent); font-size: 14px; cursor: pointer;
|
||||
transition: background 0.15s; white-space: nowrap;
|
||||
}}
|
||||
.add-btn:hover {{ background: var(--accent-40); }}
|
||||
.quotes-list {{ display: flex; flex-direction: column; gap: 8px; }}
|
||||
.quote-item {{
|
||||
display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
|
||||
background: rgba(255,255,255,0.04); border-radius: 8px;
|
||||
transition: background 0.15s;
|
||||
}}
|
||||
.quote-item:hover {{ background: rgba(255,255,255,0.08); }}
|
||||
.quote-item:hover .quote-delete {{ opacity: 1; }}
|
||||
.quote-num {{ font-size: 12px; opacity: 0.4; min-width: 24px; padding-top: 2px; }}
|
||||
.quote-text {{ flex: 1; font-size: 14px; line-height: 1.5; word-break: break-word; }}
|
||||
.quote-delete {{
|
||||
opacity: 0; background: none; border: none; cursor: pointer;
|
||||
font-size: 20px; color: rgba(255,255,255,0.4); padding: 0 4px;
|
||||
transition: opacity 0.15s, color 0.15s;
|
||||
}}
|
||||
.quote-delete:hover {{ color: #f87171; }}
|
||||
.empty-state {{ text-align: center; padding: 40px 20px; opacity: 0.5; font-size: 14px; }}
|
||||
.status {{ font-size: 12px; text-align: center; padding: 8px; opacity: 0.7; }}
|
||||
.status.error {{ color: #f87171; opacity: 1; }}
|
||||
.status.success {{ color: #4ade80; opacity: 1; }}
|
||||
.close-hint {{ text-align: center; margin-top: 24px; font-size: 12px; opacity: 0.4; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Manage Motivation Quotes</h1>
|
||||
<p>User: {safe_user} • {len(quotes)} quote{'s' if len(quotes) != 1 else ''}</p>
|
||||
</div>
|
||||
<div class="add-form">
|
||||
<input type="text" class="add-input" id="newQuote" placeholder="Add a new motivational quote..." onkeypress="if(event.key==='Enter')addQuote()">
|
||||
<button class="add-btn" onclick="addQuote()">Add Quote</button>
|
||||
</div>
|
||||
<div class="status" id="status"></div>
|
||||
<div class="quotes-list" id="quotesList">
|
||||
{quotes_html if quotes_html else '<div class="empty-state">No quotes yet. Add your first motivational quote above!</div>'}
|
||||
</div>
|
||||
<div class="close-hint">Close this tab when done. Refresh your dashboard to see changes.</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const apiKey = '{expected_key}';
|
||||
const user = '{safe_user}';
|
||||
const baseUrl = '/userdata/motivation';
|
||||
|
||||
function openModal() {{ document.getElementById('modal').classList.add('open'); }}
|
||||
function closeModal() {{ document.getElementById('modal').classList.remove('open'); }}
|
||||
function showStatus(msg, type) {{
|
||||
const s = document.getElementById('status');
|
||||
s.textContent = msg;
|
||||
s.className = 'status ' + (type || '');
|
||||
if (type !== 'error') setTimeout(() => {{ s.textContent = ''; s.className = 'status'; }}, 2000);
|
||||
}}
|
||||
|
||||
async function addQuote() {{
|
||||
const input = document.getElementById('newQuote');
|
||||
@@ -640,15 +681,27 @@ data:
|
||||
headers: {{ 'Content-Type': 'application/json' }},
|
||||
body: JSON.stringify({{ text: text }})
|
||||
}});
|
||||
if (r.ok) {{ input.value = ''; location.reload(); }}
|
||||
}} catch(e) {{ console.error(e); }}
|
||||
if (r.ok) {{
|
||||
input.value = '';
|
||||
showStatus('Quote added!', 'success');
|
||||
setTimeout(() => location.reload(), 500);
|
||||
}} else {{
|
||||
showStatus('Failed to add quote', 'error');
|
||||
}}
|
||||
}} catch(e) {{ showStatus('Error: ' + e.message, 'error'); }}
|
||||
}}
|
||||
|
||||
async function deleteQuote(index) {{
|
||||
if (!confirm('Delete this quote?')) return;
|
||||
try {{
|
||||
const r = await fetch(baseUrl + '/delete?key=' + apiKey + '&user=' + user + '&index=' + index, {{ method: 'POST' }});
|
||||
if (r.ok) location.reload();
|
||||
}} catch(e) {{ console.error(e); }}
|
||||
if (r.ok) {{
|
||||
showStatus('Quote deleted', 'success');
|
||||
setTimeout(() => location.reload(), 500);
|
||||
}} else {{
|
||||
showStatus('Failed to delete', 'error');
|
||||
}}
|
||||
}} catch(e) {{ showStatus('Error: ' + e.message, 'error'); }}
|
||||
}}
|
||||
</script>
|
||||
</body>
|
||||
@@ -694,6 +747,7 @@ data:
|
||||
return {"quote": _random.choice(quotes), "total": len(quotes)}
|
||||
return {"quote": "", "total": 0}
|
||||
|
||||
|
||||
# ================================
|
||||
# Időkép configuration
|
||||
# ================================
|
||||
|
||||
@@ -766,14 +766,14 @@ data:
|
||||
# Tasks (persistent, file-based)
|
||||
- type: iframe
|
||||
css-class: iframe-no-tint
|
||||
source: https://glance-helper.dooplex.hu/userdata/todo?key=oplQqnLnJK2vErRVYJpvVUcSDBOSbCHZSbsYY2bwSifgTMfT&user=kisfenyo&accent=4ade80&bgcolor=0d1117
|
||||
source: https://glance-helper.dooplex.hu/userdata/todo?key=oplQqnLnJK2vErRVYJpvVUcSDBOSbCHZSbsYY2bwSifgTMfT&user=kisfenyo&accent=5ac8d8&bgcolor=transparent
|
||||
height: 200
|
||||
title: Tasks
|
||||
# Motivation Quote
|
||||
- type: iframe
|
||||
css-class: iframe-no-tint
|
||||
source: https://glance-helper.dooplex.hu/userdata/motivation?key=oplQqnLnJK2vErRVYJpvVUcSDBOSbCHZSbsYY2bwSifgTMfT&user=kisfenyo&accent=4ade80&bgcolor=0d1117
|
||||
height: 100
|
||||
source: https://glance-helper.dooplex.hu/userdata/motivation?key=oplQqnLnJK2vErRVYJpvVUcSDBOSbCHZSbsYY2bwSifgTMfT&user=kisfenyo&accent=5ac8d8&bgcolor=transparent
|
||||
height: 80
|
||||
title: Motivation
|
||||
# Outline Notes iframe
|
||||
- type: iframe
|
||||
|
||||
Reference in New Issue
Block a user