--- 03-fixed script +++ 04-saved script @@ -8,7 +8,7 @@ const doneList = document.querySelector("#doneList"); const seedButton = document.querySelector("#seedButton"); - let tasks = []; + let tasks = loadTasks(); const now = new Date(); document.querySelector("#today").textContent = [ @@ -44,6 +44,15 @@ saveAndRender(); }); + function loadTasks() { + try { + const data = JSON.parse(localStorage.getItem(storageKey)); + return Array.isArray(data) ? data.filter(t => t && typeof t.id === 'string' && typeof t.title === 'string' && typeof t.done === 'boolean').map(t=>({...t,priority:['높음','보통','낮음'].includes(t.priority)?t.priority:'보통',createdAt:Number.isNaN(Date.parse(t.createdAt))?new Date().toISOString():t.createdAt})) : []; + } catch { + return []; + } + } + function createSampleTasks() { return [ { id: crypto.randomUUID(), title: "바이브코딩 뜻 글 제목 후보 정리", priority: "높음", done: false, createdAt: new Date().toISOString() }, @@ -53,6 +62,8 @@ } function saveAndRender() { + try {localStorage.setItem(storageKey, JSON.stringify(tasks));document.querySelector('#storageMessage').textContent='';} + catch {document.querySelector('#storageMessage').textContent='이 브라우저에서는 저장할 수 없어 새로고침하면 사라집니다.';} render(); }