Skip to content

Commit a0d2df2

Browse files
committed
Update background.js
1 parent 91d1432 commit a0d2df2

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

js/background.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
setInterval(() => {
2-
const date = new Date();
3-
const hour = date.getHours();
4-
const minute = date.getMinutes();
5-
noticeAlert(hour, minute);
6-
}, 60000);
7-
81
// 发送闹钟提醒
92
function noticeAlert(hour, minute) {
103
chrome.storage.local.get(['noticeList'], (result) => {
114
const res = result.noticeList;
125
if (res !== undefined && res !== null && res !== '') {
136
try {
147
const rows = JSON.parse(res);
15-
console.log(rows);
168
for (let i = 0; i < rows.length; i += 1) {
17-
if (rows[i].hour === hour || rows[i].hour === -1) {
9+
if (parseInt(rows[i].hour, 10) === hour || parseInt(rows[i].hour, 10) === -1) {
1810
if (parseInt(rows[i].minute, 10) === minute) {
1911
chrome.notifications.create(null, {
2012
type: 'basic',
@@ -31,3 +23,11 @@ function noticeAlert(hour, minute) {
3123
}
3224
});
3325
}
26+
27+
chrome.alarms.create({ periodInMinutes: 1 });
28+
chrome.alarms.onAlarm.addListener(() => {
29+
const date = new Date();
30+
const hour = date.getHours();
31+
const minute = date.getMinutes();
32+
noticeAlert(hour, minute);
33+
});

0 commit comments

Comments
 (0)