Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>대충 만든 투두리스트</title>
<style>
:root {
font-family: "Pretendard", "Noto Sans KR", system-ui, -apple-system, sans-serif;
color: #1f2937;
background: #f3f4f6;
}
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
padding: 16px;
}
.card {
width: min(560px, 100%);
background: #fff;
border-radius: 16px;
box-shadow: 0 12px 40px rgba(17, 24, 39, 0.12);
padding: 24px;
}
h1 {
margin: 0 0 14px;
font-size: 1.6rem;
}
.composer {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
}
input {
border: 1px solid #d1d5db;
border-radius: 10px;
padding: 11px 12px;
font-size: 1rem;
}
button {
border: 0;
border-radius: 10px;
background: #2563eb;
color: #fff;
font-weight: 700;
padding: 0 16px;
cursor: pointer;
}
ul {
list-style: none;
padding: 0;
margin: 16px 0 0;
}
li {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 12px;
padding: 10px 2px;
border-bottom: 1px solid #e5e7eb;
}
li.done span {
text-decoration: line-through;
color: #9ca3af;
}
.delete {
background: transparent;
color: #dc2626;
padding: 0;
}
.hint {
margin-top: 14px;
color: #6b7280;
font-size: .9rem;
}
</style>
</head>
<body>
<main class="card">
<h1>📝 대충 만든 투두리스트</h1>
<div class="composer">
<input id="todoInput" placeholder="할 일 입력하고 엔터" />
<button id="addBtn">추가</button>
</div>
<ul id="todoList"></ul>
<p class="hint">체크하면 완료, ❌ 누르면 삭제됨. 브라우저 저장(localStorage) 지원.</p>
</main>

<script>
const input = document.getElementById('todoInput');
const addBtn = document.getElementById('addBtn');
const list = document.getElementById('todoList');
const STORAGE_KEY = 'rough-todos';

let todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');

const save = () => localStorage.setItem(STORAGE_KEY, JSON.stringify(todos));

function render() {
list.innerHTML = '';

todos.forEach((todo, index) => {
const li = document.createElement('li');
if (todo.done) li.classList.add('done');

const check = document.createElement('input');
check.type = 'checkbox';
check.checked = todo.done;
check.addEventListener('change', () => {
todos[index].done = check.checked;
save();
render();
});

const text = document.createElement('span');
text.textContent = todo.text;

const del = document.createElement('button');
del.className = 'delete';
del.textContent = '❌';
del.addEventListener('click', () => {
todos = todos.filter((_, i) => i !== index);
save();
render();
});

li.append(check, text, del);
list.appendChild(li);
});
}

function addTodo() {
const text = input.value.trim();
if (!text) return;
todos.unshift({ text, done: false });
input.value = '';
save();
render();
input.focus();
}

addBtn.addEventListener('click', addTodo);
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') addTodo();
});

render();
</script>
</body>
</html>