-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
107 lines (89 loc) · 3.43 KB
/
script.js
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
let isDarkMode = false;
function toggleTheme() {
const themeToggleButton = document.getElementById('theme-toggle');
isDarkMode = !isDarkMode;
if (isDarkMode) {
document.body.classList.add('dark-mode');
themeToggleButton.textContent = '☀';
} else {
document.body.classList.remove('dark-mode');
themeToggleButton.textContent = '🌙';
}
}
function updateClock() {
const clockElement = document.getElementById('live-clock');
const now = new Date();
const options = { timeZone: 'Asia/Kolkata', hour: '2-digit', minute: '2-digit', second: '2-digit' };
const timeString = now.toLocaleTimeString('en-US', options);
clockElement.textContent = `Current Time (IST): ${timeString}`;
}
setInterval(updateClock, 1000);
updateClock();
function addTask() {
const taskInput = document.getElementById('task-input');
const taskList = document.getElementById('task-list');
const emptyState = document.getElementById('empty-state');
if (taskInput.value.trim() === '') {
alert('Please enter a task.');
return;
}
if (emptyState) {
emptyState.remove();
}
const task = document.createElement('div');
task.className = 'task fade-in';
task.innerHTML = `
<span>${taskInput.value}</span>
<div class="task-actions">
<button class="complete" onclick="completeTask(this)">✔</button>
<button class="edit" onclick="editTask(this)">✏</button>
<button class="delete" onclick="deleteTask(this)">🗑</button>
<button class="move-up" onclick="moveTaskUp(this)">⬆</button>
<button class="move-down" onclick="moveTaskDown(this)">⬇</button>
</div>
`;
taskList.appendChild(task);
taskInput.value = '';
}
function completeTask(button) {
const task = button.parentElement.parentElement;
task.classList.add('completed');
button.disabled = true;
task.querySelector('.edit').disabled = true;
}
function editTask(button) {
const task = button.parentElement.parentElement;
const taskText = task.querySelector('span');
const newTaskText = prompt('Edit your task:', taskText.textContent);
if (newTaskText !== null && newTaskText.trim() !== '') {
taskText.textContent = newTaskText.trim();
} else {
alert('Task cannot be empty.');
}
}
function deleteTask(button) {
const task = button.parentElement.parentElement;
const taskList = document.getElementById('task-list');
task.remove();
if (taskList.children.length === 0) {
const emptyState = document.createElement('p');
emptyState.id = 'empty-state';
emptyState.className = 'empty-state';
emptyState.textContent = 'Your task list is empty. Add a task to get started!';
taskList.appendChild(emptyState);
}
}
function moveTaskUp(button) {
const task = button.parentElement.parentElement;
const previousTask = task.previousElementSibling;
if (previousTask && previousTask.className.includes('task')) {
task.parentElement.insertBefore(task, previousTask);
}
}
function moveTaskDown(button) {
const task = button.parentElement.parentElement;
const nextTask = task.nextElementSibling;
if (nextTask && nextTask.className.includes('task')) {
task.parentElement.insertBefore(nextTask, task);
}
}