sha
All checks were successful
Deploy to FTP / deploy (push) Successful in 5s

This commit is contained in:
Sebastian Molenda
2026-05-05 20:43:06 +02:00
parent ae9f965e03
commit 77d5af8fa0
5 changed files with 45 additions and 51 deletions

69
app.js
View File

@@ -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)
})