From 77d5af8fa073508bc9230fcf8e4279a2f4695ac6 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Tue, 5 May 2026 20:43:06 +0200 Subject: [PATCH] sha --- .gitea/workflows/deploy.yml | 2 +- app.js | 69 ++++++++++++++++++++----------------- index.html | 19 ++-------- styles.css | 5 +-- version.js | 1 + 5 files changed, 45 insertions(+), 51 deletions(-) create mode 100644 version.js diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 27e2d60..3f87d81 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -26,5 +26,5 @@ jobs: username: ${{ secrets.FTP_USER }} password: ${{ secrets.FTP_PASS }} local-dir: ./ - server-dir: /public_html/ + server-dir: / diff --git a/app.js b/app.js index 2b45b81..1550a2e 100644 --- a/app.js +++ b/app.js @@ -450,15 +450,15 @@ historyToggle.addEventListener('click', ()=>{ // historyBtn.addEventListener('click', toggleHistory) // if (historyToggle) historyToggle.addEventListener('click', toggleHistory) -historyBack.addEventListener('click', ()=>{ - historyScreen.classList.add('hidden') - menuScreen.classList.remove('hidden') -}) +// historyBack.addEventListener('click', ()=>{ +// historyScreen.classList.add('hidden') +// menuScreen.classList.remove('hidden') +// }) -clearHistoryBtn.addEventListener('click', ()=>{ - try{ localStorage.removeItem('matma:history') }catch(e){} - renderHistory() -}) +// clearHistoryBtn.addEventListener('click', ()=>{ +// try{ localStorage.removeItem('matma:history') }catch(e){} +// renderHistory() +// }) // keyboard support: allow Enter/Backspace/0-9 window.addEventListener('keydown', (e)=>{ @@ -479,29 +479,34 @@ window.addEventListener('keydown', (e)=>{ // small helper to set initial focus - mobile browsers will not open keyboard for divs document.addEventListener('touchstart', ()=>{}, {passive:true}) -// load COMMIT_SHA from /version.js if present (no-cache fetch) -;(function loadCommitSha(){ +// Load commit SHA into footer (robust: prefers window.COMMIT_SHA, then meta tag, then fetch plain file) +document.addEventListener('DOMContentLoaded', async () => { const el = document.getElementById('commit-sha') if (!el) return - // prefer a no-cache fetch - fetch('/version.js', {cache: 'no-store'}) - .then(r => { - if (!r.ok) throw new Error('no version.js') - return r.text() - }) - .then(text => { - // naive parse: look for COMMIT_SHA = '...'; or window.COMMIT_SHA - let m = text.match(/COMMIT_SHA\s*=\s*['\"]([0-9a-fA-F]+)['\"]/) - if (m) return m[1] - m = text.match(/window\.COMMIT_SHA\s*=\s*['\"]([0-9a-fA-F]+)['\"]/) - if (m) return m[1] - return null - }) - .catch(()=>{ - // fallback to global - return (window && window.COMMIT_SHA) ? window.COMMIT_SHA : null - }) - .then(sha => { - el.textContent = sha ? sha.slice(0,8) : 'unknown' - }) -})() + // 1) prefer a global injected by CI: window.COMMIT_SHA + let sha = (window.COMMIT_SHA || '').toString().trim() + // 2) fallback to meta tag if CI injects that instead + if (!sha) { + const meta = document.querySelector('meta[name="commit-sha"]') + if (meta && meta.content) sha = meta.content.trim() + } + // 3) finally try to fetch the external file (works if it's plain text or a tiny JS file) + if (!sha) { + try { + const res = await fetch('/version.js', { cache: 'no-cache' }) + if (res.ok) { + const txt = (await res.text()).trim() + // try to extract a quoted/assigned sha like: window.COMMIT_SHA = "abc..." or COMMIT_SHA: "..." + const m = txt.match(/COMMIT_SHA\s*(?:=|:)\s*["']?([0-9a-fA-F]{7,40})["']?/) + if (m && m[1]) sha = m[1] + else { + const firstLine = txt.split(/\r?\n/).find(l => l.trim().length>0) + if (firstLine) sha = firstLine.trim() + } + } + } catch (e) { + // ignore failures silently + } + } + if (sha) el.textContent = sha.slice(0,8) +}) diff --git a/index.html b/index.html index 56a730b..c6f8612 100644 --- a/index.html +++ b/index.html @@ -140,24 +140,11 @@ - -
-
-
- -
-
Historia sesji
-
- -
-
-
- -
-
- + + + diff --git a/styles.css b/styles.css index af8d085..a76670b 100644 --- a/styles.css +++ b/styles.css @@ -7,9 +7,10 @@ *{box-sizing:border-box} html,body{height:100%} .app-wrap{width:100%;max-width:420px} +.app-wrap{width:100%;max-width:420px} body{ margin:0; font-family:Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial; - background:var(--bg); color:#111; display:flex; align-items:center; justify-content:center; padding:16px; + background:var(--bg); color:#111; display:flex; flex-direction:column; align-items:center; justify-content:flex-start; min-height:100vh; padding:16px; } .screen{width:100%;background:var(--card);border-radius:16px;box-shadow:0 6px 22px rgba(16,24,40,0.08);position:relative;overflow:auto;-webkit-overflow-scrolling:touch} .screen.hidden{display:none} @@ -62,7 +63,7 @@ body{ .summary h2{margin:6px 0} .summary p{font-size:18px} -.app-footer{font-size:12px;color:var(--muted);text-align:center;padding:10px 0} +.app-footer{font-size:12px;color:var(--muted);text-align:center;padding:10px 0;width:100%;max-width:420px} @media (orientation:portrait){ .screen{max-height:94vh} diff --git a/version.js b/version.js new file mode 100644 index 0000000..28c6ec0 --- /dev/null +++ b/version.js @@ -0,0 +1 @@ +const COMMIT_SHA = '-';