-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
77 lines (65 loc) · 2.44 KB
/
popup.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
document.addEventListener('DOMContentLoaded', function() {
const taskInput = document.getElementById('task');
const addTaskButton = document.getElementById('addTask');
const taskList = document.getElementById('taskList');
const removeAllTasksButton = document.getElementById('removeAllTasks');
function saveTasks(tasks) {
chrome.storage.local.set({ tasks: tasks }, function() {
if (chrome.runtime.lastError) {
console.error("Error saving tasks:", chrome.runtime.lastError);
return;
}
// Update the user interface here
});
}
function loadTasks(callback) {
chrome.storage.local.get(['tasks'], function(result) {
const tasks = result.tasks || [];
callback(tasks);
});
}
loadTasks(function(tasks) {
taskList.innerHTML = tasks
.map((task, index) => {
return `<li><input type="checkbox" class="task-checkbox" data-index="${index}"><span>${task}</span></li>`;
})
.join('');
});
addTaskButton.addEventListener('click', function() {
const taskText = taskInput.value.trim();
if (taskText) {
loadTasks(function(tasks) {
tasks.push(taskText);
saveTasks(tasks);
const taskItem = document.createElement('li');
taskItem.innerHTML = `<input type="checkbox" class="task-checkbox" data-index="${tasks.length - 1}"><span>${taskText}</span>`;
taskList.appendChild(taskItem);
taskInput.value = '';
});
}
});
taskList.addEventListener('click', function(event) {
const target = event.target;
if (target.classList.contains('task-checkbox')) {
const index = target.getAttribute('data-index');
const taskItem = target.parentElement;
loadTasks(function(tasks) {
tasks.splice(index, 1);
saveTasks(tasks);
taskItem.classList.add('removing');
setTimeout(function() {
taskItem.remove();
}, 3000); // Attendre 3 secondes avant de supprimer définitivement
// Retirez la classe "removing" après 3 secondes
setTimeout(function() {
taskItem.classList.remove('removing');
}, 300); // Correspond à la durée de l'animation (300 ms)
});
}
});
removeAllTasksButton.addEventListener('click', function() {
saveTasks([]);
taskList.innerHTML = '';
});
let pomodoroInterval; // Variable to store Pomodoro interval
});