Kindness Counter
Made by Sample Maker
A remix with visible ancestry
A creation from the community
Made by ArkheOS
A small counter with undo and reset, plus a private note.
What would you change about Save Rehearsal?
Copy your request, open Widget Canvas, then choose “Try in chat” and paste it.
You are exploring the published defaults. Changes here stay in this browser and do not change the creator’s work.
Made by Sample Maker
A remix with visible ancestry
<main><h1>Save Rehearsal</h1><p class="sub">A counter and a short private note</p><output id="count" aria-live="polite" aria-label="Counter">0</output><div class="actions"><button id="increase" type="button">Increase</button><button id="undo" type="button" disabled>Undo</button><button id="reset" type="button">Reset</button></div><p class="sub">Undo keeps the last 20 counter changes. Reset clears the counter, history and note.</p><label for="note">Private note</label><textarea id="note" maxlength="500" rows="3" placeholder="Write a short note…"></textarea><p id="status" role="status" aria-live="polite">Ready</p></main>
:root{font-family:system-ui,sans-serif;color-scheme:light dark}body{margin:0;background:transparent;color:light-dark(#202c39,#e9eef5)}main{max-width:440px;margin:auto;padding:24px 16px}h1{font-size:25px;margin:0 0 6px}.sub{color:light-dark(#606b77,#aab6c7);font-size:13px;line-height:1.5}output{display:block;font-size:64px;font-weight:650;font-variant-numeric:tabular-nums;margin:20px 0}.actions{display:flex;gap:8px;flex-wrap:wrap}button{font:600 14px system-ui;padding:11px 17px;border:1px solid light-dark(#bdc8d8,#526079);border-radius:8px;background:light-dark(#edf2f9,#283449);color:inherit}#increase{background:light-dark(#244b86,#a7c6ff);color:light-dark(#fff,#182c4b);border-color:transparent}button:disabled{opacity:.45}label{display:block;font-size:14px;font-weight:600;margin:20px 0 8px}textarea{box-sizing:border-box;width:100%;resize:vertical;font:16px system-ui;padding:11px;border:1px solid light-dark(#bdc8d8,#526079);border-radius:8px;background:light-dark(#fff,#202b3d);color:inherit}#status{font-size:12px;color:light-dark(#606b77,#aab6c7);min-height:18px}button:focus-visible,textarea:focus-visible{outline:3px solid light-dark(#a66a00,#ffcd72);outline-offset:3px}const MAX=999999,LIMIT=20;
let state={version:1,count:0,history:[],note:""},edited=false,restoreEpoch=0;
const count=document.getElementById("count"),note=document.getElementById("note"),status=document.getElementById("status");
const increase=document.getElementById("increase"),undo=document.getElementById("undo");
function boundedCount(n){return Number.isInteger(n)&&n>=0&&n<=MAX}
function normalize(s){if(!s||s.version!==1||!boundedCount(s.count)||!Array.isArray(s.history)||s.history.length>LIMIT||!s.history.every(boundedCount)||typeof s.note!=="string")return null;return {version:1,count:s.count,history:s.history.slice(),note:s.note.slice(0,500)}}
function paint(){count.textContent=String(state.count);increase.disabled=state.count>=MAX;undo.disabled=state.history.length===0;if(note.value!==state.note)note.value=state.note}
function restore(s){const valid=normalize(s);if(valid){state=valid;status.textContent="Restored widget state."}else if(s!=null){status.textContent="Saved state was invalid; using defaults."}paint()}
let pending=null,saving=false;
async function drain(){if(saving)return;saving=true;while(pending){const snapshot=pending;pending=null;try{await WidgetCanvas.setState(snapshot);status.textContent=pending?"Saving…":"Saved in widget state."}catch(e){status.textContent="Could not save. Your edits remain here."}}saving=false}
function save(){pending={version:1,count:state.count,history:state.history.slice(),note:state.note};status.textContent="Saving…";void drain()}
increase.addEventListener("click",()=>{if(state.count>=MAX)return;edited=true;state.history.push(state.count);state.history=state.history.slice(-LIMIT);state.count++;paint();save()});
undo.addEventListener("click",()=>{if(!state.history.length)return;edited=true;state.count=state.history.pop();paint();save()});
document.getElementById("reset").addEventListener("click",()=>{edited=true;state={version:1,count:0,history:[],note:""};paint();save()});
note.addEventListener("input",()=>{edited=true;state.note=note.value.slice(0,500);save()});
WidgetCanvas.setControlsPosition("top-right");WidgetCanvas.setSharingEnabled(false);WidgetCanvas.setResetEnabled(false);
window.addEventListener("widgetcanvas:restore",e=>{restoreEpoch++;if(!edited)restore(e.detail)});
paint();
(async()=>{const epoch=restoreEpoch;try{const saved=await WidgetCanvas.getState();if(!edited&&epoch===restoreEpoch)restore(saved)}catch(e){if(!edited)status.textContent="State unavailable; using defaults."}})();