Add repo hygiene rules and ignore secrets

This commit is contained in:
2026-02-03 06:55:39 +01:00
parent 88732a8ae7
commit 6035bc1715
52 changed files with 3295 additions and 25 deletions

View File

@@ -118,4 +118,88 @@
if(b.dataset.alertpulse === pulse) b.classList.add("is-selected");
});
});
})();
function formatNumber(val){
const num = Number.isFinite(val) ? val : 0;
return Math.round(num).toLocaleString("de-DE");
}
const resourceMap = {
"Metall": "metal",
"Kristall": "crystals",
"Deuterium": "deuterium",
"Energie": "energy"
};
function updateResourceBar(state){
const stats = document.querySelectorAll(".resource-row .stat");
stats.forEach((stat)=>{
const label = stat.querySelector(".stat-k")?.textContent?.trim();
const key = resourceMap[label];
if(!key) return;
const value = state?.resources?.[key];
if(typeof value !== "number") return;
const valueEl = stat.querySelector(".stat-v");
if(!valueEl) return;
const dot = valueEl.querySelector(".dot");
const display = key === "energy" ? Math.round(value) : Math.floor(value);
const prefix = key === "energy" && display >= 0 ? "+" : "";
valueEl.textContent = "";
if(dot) valueEl.appendChild(dot);
valueEl.appendChild(document.createTextNode(` ${prefix}${formatNumber(display)}`));
});
}
async function fetchState(){
try{
const res = await fetch("/api/state");
if(!res.ok) return null;
return await res.json();
}catch(e){
return null;
}
}
async function refreshState(){
const state = await fetchState();
if(state) updateResourceBar(state);
}
function ensureBuildButton(){
const content = document.getElementById("content");
if(!content || document.getElementById("buildOreMine")) return;
const wrap = document.createElement("div");
wrap.className = "actions";
const btn = document.createElement("button");
btn.className = "btn btn-primary";
btn.id = "buildOreMine";
btn.type = "button";
btn.textContent = "Erzmine bauen";
btn.addEventListener("click", async ()=>{
try{
const res = await fetch("/api/build/start", {
method: "POST",
headers: {"Content-Type":"application/json"},
body: JSON.stringify({building_key:"ore_mine", amount:1})
});
const data = await res.json();
if(res.ok){
toast("success","Bau gestartet","Erzmine in Queue gelegt");
updateResourceBar({resources: data.resources});
}else{
toast("error","Bau fehlgeschlagen", data.message || "Aktion nicht möglich");
}
}catch(e){
toast("error","Netzwerk","API nicht erreichbar");
}
});
wrap.appendChild(btn);
content.appendChild(wrap);
}
document.addEventListener("DOMContentLoaded", ()=>{
refreshState();
ensureBuildButton();
setInterval(refreshState, 30000);
});
})();