-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
35 lines (33 loc) · 1 KB
/
background.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
window.setInterval(function () {
let todoList = [];
let time = new Date().getTime();
let endTime = time + 1000 * 20;
if (localStorage.getItem("todoList")) {
todoList = JSON.parse(localStorage.getItem("todoList"));
console.log(todoList);
for (let i = 0; i < todoList.length; i++) {
console.log(time);
if (todoList[i].nextTime <= endTime) {
alert("别忘记哦," + todoList[i].info);
todoList[i].nextTime += todoList[i].time * 60 * 1000;
}
}
localStorage.setItem("todoList", JSON.stringify(todoList));
}
}, 1000 * 20);
function addList(todo) {
let todoList = [];
if (localStorage.getItem("todoList")) {
todoList = JSON.parse(localStorage.getItem("todoList"));
}
if (todoList.length >= 5) {
alert("宝贝,最多只支持五条哦");
} else {
todoList.push(todo);
console.log(todoList);
localStorage.setItem("todoList", JSON.stringify(todoList));
}
}
function getList() {
return JSON.parse(localStorage.getItem("todoList"));
}