-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice-worker.js
More file actions
54 lines (48 loc) · 1.53 KB
/
service-worker.js
File metadata and controls
54 lines (48 loc) · 1.53 KB
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
/* eslint-disable no-param-reassign */
import { getMajorNotices, getSchedules } from './scripts/crawling.js';
import { createDDayNotification, createNotification, createNotificationSignal } from './scripts/notification.js';
import { localStorageSet } from './scripts/storage.js';
// function openModal() {
// chrome.windows.create({
// url: 'assets/modal/modal.html',
// type: 'popup',
// width: 400,
// height: 400,
// focused: true,
// });
// }
chrome.runtime.onInstalled.addListener(async ({ reason }) => {
if (reason === 'install' || reason === 'update') {
// 모달창 개발 완료 후 주석 해제
// openModal();
const schedules = await getSchedules();
const majorNotices = await getMajorNotices();
const fixedNotices = [];
const nonfixedNotices = [];
schedules.forEach((schedule) => {
const sDay = schedule.duration.substr(0, 10);
const eDay = schedule.duration.substr(17, 10);
schedule.startDay = sDay;
schedule.endDay = eDay;
});
majorNotices.forEach((notice) => {
if (notice.articleTitle.startsWith('[ 일반공지 ]')) {
fixedNotices.push(notice);
} else nonfixedNotices.push(notice);
});
localStorageSet({
schedules,
fixedNotices,
nonfixedNotices,
todayDate: new Date().getDate(),
modalOnOff: true,
noticeDDay: 3,
crawlingPeriod: 1,
mymajor: '정보컴퓨터공학부',
initialStart: true,
});
}
});
createNotificationSignal();
createNotification();
createDDayNotification();