Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ <h2>학과 선택:</h2>
</button>
<div class="dropdown-content">
<div class="list Selected">정보컴퓨터공학부</div>
<div class="list">식품영양학과</div>
<div class="list">토목공학과</div>
<!-- <div class="list">의생명공학과</div>
<div class="list">기계공학과</div>
<div class="list">전기공학과</div>
Expand Down
7 changes: 6 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"type": "module"
},
"permissions": ["scripting", "storage", "alarms", "notifications"],
"host_permissions": ["https://onestop.pusan.ac.kr/", "https://cse.pusan.ac.kr/cse/14651/subview.do"],
"host_permissions": [
"https://onestop.pusan.ac.kr/",
"https://cse.pusan.ac.kr/cse/14651/subview.do",
"https://fsn.pusan.ac.kr/fsn/15462/subview.do?enc=Zm5jdDF8QEB8JTJGYmJzJTJGZnNuJTJGMjc4MyUyRmFydGNsTGlzdC5kbyUzRmJic09wZW5XcmRTZXElM0QlMjZpc1ZpZXdNaW5lJTNEZmFsc2UlMjZzcmNoQ29sdW1uJTNEJTI2cGFnZSUzRDElMjZzcmNoV3JkJTNEJTI2cmdzQmduZGVTdHIlM0QlMjZiYnNDbFNlcSUzRCUyNnJnc0VuZGRlU3RyJTNEJTI2",
"https://civil.pusan.ac.kr/civil/16275/subview.do"
],
"action": {
"default_popup": "/assets/popup/popup.html"
},
Expand Down
18 changes: 17 additions & 1 deletion scripts/crawling.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { localStorageGet } from './storage.js';

async function getSchedules() {
const { tabs } = await chrome.windows.create({
url: 'https://onestop.pusan.ac.kr',
Expand All @@ -22,8 +24,22 @@ async function getSchedules() {
}

async function getMajorNotices() {
const MAJOR_NOTICE_URL = {
정보컴퓨터공학부: 'https://cse.pusan.ac.kr/cse/14651/subview.do',
식품영양학과:
'https://fsn.pusan.ac.kr/fsn/15462/subview.do?enc=Zm5jdDF8QEB8JTJGYmJzJTJGZnNuJTJGMjc4MyUyRmFydGNsTGlzdC5kbyUzRmJic09wZW5XcmRTZXElM0QlMjZpc1ZpZXdNaW5lJTNEZmFsc2UlMjZzcmNoQ29sdW1uJTNEJTI2cGFnZSUzRDElMjZzcmNoV3JkJTNEJTI2cmdzQmduZGVTdHIlM0QlMjZiYnNDbFNlcSUzRCUyNnJnc0VuZGRlU3RyJTNEJTI2',
토목공학과: 'https://civil.pusan.ac.kr/civil/16275/subview.do',
};
let majorNoticeUrl = MAJOR_NOTICE_URL['정보컴퓨터공학부'];
const { mymajor } = await localStorageGet('mymajor');
console.log(mymajor);

if (mymajor) {
majorNoticeUrl = MAJOR_NOTICE_URL[mymajor];
console.log(majorNoticeUrl);
}
const { tabs } = await chrome.windows.create({
url: 'https://cse.pusan.ac.kr/cse/14651/subview.do',
url: majorNoticeUrl,
state: 'minimized',
});

Expand Down
14 changes: 13 additions & 1 deletion scripts/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const createNotificationSignal = () => {
// 팝업 설정 페이지에서 설정한 크롤링 주기를 이용하여 알람을 생성합니다.
chrome.alarms.create('crawlingPeriod', {
delayInMinutes: 0,
periodInMinutes: request.crawlingPeriod * 60,
// periodInMinutes: request.crawlingPeriod * 60,
periodInMinutes: 1,
});
}
});
Expand All @@ -17,6 +18,7 @@ const createNotificationSignal = () => {
const createDDayNotification = async () => {
const aDay = 1000 * 60 * 60 * 24;
chrome.storage.onChanged.addListener(async (changes) => {
console.log(changes);
if (changes.todayDate || changes.noticeDDay) {
const { schedules } = await localStorageGet('schedules');
const { noticeDDay } = await localStorageGet('noticeDDay');
Expand Down Expand Up @@ -81,7 +83,10 @@ const updateStorageByAlarm = async () => {

const createNotification = () => {
const newNotice = [];
// 학과 변경시, 새로 크롤링한 데이터를 새로 등록된 공지로 인식 -> 알림 발생
// mymajor, 학과에 따른 공지데이터가 2차례 나눠서 들어옴
chrome.storage.onChanged.addListener(async (changes) => {
console.log(changes);
if (changes.fixedNotices) {
if (changes.fixedNotices.oldValue) {
for (let i = 0; i < changes.fixedNotices.newValue.length; i += 1) {
Expand All @@ -103,6 +108,13 @@ const createNotification = () => {
}
}

if (
newNotice.length ===
(changes.fixedNotices?.newValue.length || 0) + (changes.nonfixedNotices?.newValue.length || 0)
) {
newNotice.length = 0;
}

const { modalOnOff } = await chrome.storage.local.get('modalOnOff');
if (modalOnOff && newNotice.length > 0) {
for (let i = 0; i < newNotice.length; i += 1) {
Expand Down
1 change: 1 addition & 0 deletions scripts/storage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const localStorageSet = (content) => {
chrome.storage.local.set(content);
console.log(content);
};

const localStorageGet = (keys) => {
Expand Down
4 changes: 2 additions & 2 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* 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';
import { localStorageGet, localStorageSet } from './scripts/storage.js';

// function openModal() {
// chrome.windows.create({
Expand Down Expand Up @@ -42,7 +42,7 @@ chrome.runtime.onInstalled.addListener(async ({ reason }) => {
todayDate: new Date().getDate(),
modalOnOff: true,
noticeDDay: 3,
crawlingPeriod: 1,
crawlingPeriod: 3,
mymajor: '정보컴퓨터공학부',
initialStart: true,
});
Expand Down