Spaces:
Running
Running
File size: 5,181 Bytes
f6dcf38 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo App</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', system-ui, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 2rem;
display: grid;
place-items: center;
}
.container {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 2rem;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
width: 90%;
max-width: 500px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1.5rem;
font-weight: 600;
}
.input-section {
display: flex;
gap: 0.5rem;
margin-bottom: 1.5rem;
}
input {
flex: 1;
padding: 0.75rem 1rem;
border: 2px solid #e1e5e9;
border-radius: 12px;
font-size: 1rem;
transition: all 0.3s ease;
}
input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
button {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 12px;
cursor: pointer;
font-weight: 600;
transition: transform 0.2s ease;
}
button:hover { transform: translateY(-2px); }
.todo-item {
background: white;
padding: 1rem;
margin-bottom: 0.5rem;
border-radius: 12px;
display: flex;
align-items: center;
gap: 1rem;
border: 2px solid #f0f0f0;
transition: all 0.3s ease;
}
.todo-item:hover {
border-color: #667eea;
transform: translateX(5px);
}
.todo-item.completed {
opacity: 0.6;
text-decoration: line-through;
}
.todo-text { flex: 1; }
.delete-btn {
background: #ff4757;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 8px;
cursor: pointer;
font-size: 0.875rem;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.anycoder-link {
color: #667eea;
text-decoration: none;
font-size: 0.875rem;
font-weight: 500;
}
@media (max-width: 480px) {
.container { padding: 1.5rem; }
.input-section { flex-direction: column; }
button { width: 100%; }
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>π Todo App</h1>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" class="anycoder-link">Built with anycoder</a>
</div>
<div class="input-section">
<input type="text" id="todoInput" placeholder="Add a new task..." maxlength="100">
<button onclick="addTodo()">Add Task</button>
</div>
<div id="todoList"></div>
</div>
<script>
let todos = JSON.parse(localStorage.getItem('todos')) || [];
function renderTodos() {
const todoList = document.getElementById('todoList');
todoList.innerHTML = todos.map((todo, index) => `
<div class="todo-item ${todo.completed ? 'completed' : ''}">
<span class="todo-text">${todo.text}</span>
<button onclick="toggleTodo(${index})">${todo.completed ? 'Undo' : 'Done'}</button>
<button class="delete-btn" onclick="deleteTodo(${index})">Delete</button>
</div>
`).join('');
localStorage.setItem('todos', JSON.stringify(todos));
}
function addTodo() {
const input = document.getElementById('todoInput');
const text = input.value.trim();
if (text) {
todos.push({ text, completed: false });
input.value = '';
renderTodos();
}
}
function toggleTodo(index) {
todos[index].completed = !todos[index].completed;
renderTodos();
}
function deleteTodo(index) {
todos.splice(index, 1);
renderTodos();
}
document.getElementById('todoInput').addEventListener('keypress', (e) => {
if (e.key === 'Enter') addTodo();
});
renderTodos();
</script>
</body>
</html> |