diff --git a/.DS_Store b/.DS_Store index 986c8d5..b14404c 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index 2211aa8..514f128 100644 --- a/README.md +++ b/README.md @@ -60,46 +60,3 @@ - -### 디렉토리 구조 - -```plaintext -comboong-note/ -├── README.md -├── assets -│ ├── fonts -│ │ └── SCDream4.otf -│ ├── img -│ │ ├── drop_down.png -│ │ ├── iconImg-128.png -│ │ ├── iconImg-16.png -│ │ ├── iconImg-32.png -│ │ ├── iconImg-48.png -│ │ └── iconImg.png -│ ├── modal -│ │ ├── modal.html -│ │ └── modal.js -│ └── popup -│ ├── popup.css -│ ├── popup.html -│ └── popup.js -├── manifest.json -├── package-lock.json -├── package.json -├── scripts -│ ├── crawling.js -│ ├── notification.js -│ ├── preprocess.js -│ ├── setting.js -│ └── storage.js -└── service-worker.js -``` - - -### 기술 스택 - -

- - - -

diff --git a/assets/.DS_Store b/assets/.DS_Store index 19a263d..88b40bf 100644 Binary files a/assets/.DS_Store and b/assets/.DS_Store differ diff --git a/assets/img/.DS_Store b/assets/img/.DS_Store index ac120d2..0926f91 100644 Binary files a/assets/img/.DS_Store and b/assets/img/.DS_Store differ diff --git a/assets/img/Initial_settings_img.png b/assets/img/Initial_settings_img.png new file mode 100644 index 0000000..e7ae42c Binary files /dev/null and b/assets/img/Initial_settings_img.png differ diff --git a/assets/img/bell_img.png b/assets/img/bell_img.png new file mode 100644 index 0000000..3fb1eee Binary files /dev/null and b/assets/img/bell_img.png differ diff --git a/assets/img/iconImg-1.png b/assets/img/iconImg-1.png new file mode 100644 index 0000000..d036671 Binary files /dev/null and b/assets/img/iconImg-1.png differ diff --git a/assets/img/iconImg-128.png b/assets/img/iconImg-128.png deleted file mode 100644 index 8b2ab0d..0000000 Binary files a/assets/img/iconImg-128.png and /dev/null differ diff --git a/assets/img/iconImg-16.png b/assets/img/iconImg-16.png deleted file mode 100644 index d65e5d6..0000000 Binary files a/assets/img/iconImg-16.png and /dev/null differ diff --git a/assets/img/iconImg-32.png b/assets/img/iconImg-32.png deleted file mode 100644 index 858ca65..0000000 Binary files a/assets/img/iconImg-32.png and /dev/null differ diff --git a/assets/img/iconImg-48.png b/assets/img/iconImg-48.png deleted file mode 100644 index 95bf12c..0000000 Binary files a/assets/img/iconImg-48.png and /dev/null differ diff --git a/assets/img/refresh.png b/assets/img/refresh.png deleted file mode 100644 index 74bf9c9..0000000 Binary files a/assets/img/refresh.png and /dev/null differ diff --git a/assets/img/setting_img.png b/assets/img/setting_img.png new file mode 100644 index 0000000..673e3ad Binary files /dev/null and b/assets/img/setting_img.png differ diff --git a/assets/img/warning_img.png b/assets/img/warning_img.png new file mode 100644 index 0000000..0d802bd Binary files /dev/null and b/assets/img/warning_img.png differ diff --git a/assets/modal/modal.css b/assets/modal/modal.css new file mode 100644 index 0000000..ef3ef5a --- /dev/null +++ b/assets/modal/modal.css @@ -0,0 +1,106 @@ +@font-face { + font-family: 'SCDream'; + font-weight: 400; + src: url('/assets/fonts/SCDream4.otf'); + } +html::-webkit-scrollbar{ + display: none; +} +body { + font-family: SCDream; + width: 500px; + height: 440px; + background-color: white; + margin: 0; +} +.Comboongtext { + text-align: middle; + vertical-align: top; + padding: 10px 0 0 0px; + margin: 0; + display: flex; + align-items: center; +} +.iconcomboong { + width: 57px; + height: 60px; + display: flex; + padding: 0 40px; +} +.commentbox { + padding: 0; + height: 230px; + background-color: #F5F5F5; + flex-direction: column; + justify-content: space-around; + box-shadow: 0px 4px 3px 0 rgb(153, 151, 151); +} +.comment1, .comment2, .comment3{ + display: flex; + align-items: center; + flex: 10em; + flex: 30%; + padding-top: 20px; +} +.li-img{ + width: 40px; + padding: 8px 15px 0px 15px; +} +.li-comment{ + list-style-type: none; + white-space: nowrap; + flex: 10em; + flex: 30%; +} +ul{ + display: grid; + padding-left: 0; +} +#extra{ + float: right; + background-color: #edf6ff; + border-radius: 30px 30px 30px 0; + width: 230px; + height: 100px; + padding: 0px 0px 15px 0px; + white-space: pre; + margin: 15px; + display: none; + position: absolute; + top: 20px; + left: 230px; + z-index: 1000; + box-shadow: 0px 4px 3px 0 rgb(153, 151, 151); +} +.extra_default{ + color: black; + font-weight: bold; +} +.extra_settings{ + color: grey; + font-weight: bold; +} +#settingset{ + width: 22px; + height: 20px; +} + +.error-imform{ +display: flex; +justify-content: center; +} +.error-text { + width: 385px; + height: 40px; + background-color: #105395; + vertical-align: middle; + text-align: center; + display: inline-block; + margin-top: 20px; + margin-left: auto; + margin-right: auto; + padding-top: 20px; + color: white; + border-radius: 0px 30px; +} + diff --git a/assets/modal/modal.html b/assets/modal/modal.html index d6fb0ed..2279618 100644 --- a/assets/modal/modal.html +++ b/assets/modal/modal.html @@ -4,9 +4,31 @@ Comboong Note + - 모달 - +

Comboong Note

+
+ +
+
+
+ 오류 제보: leadcomboongnote@gmail.com +
+
+ + diff --git a/assets/modal/modal.js b/assets/modal/modal.js index 7ef4a80..d52b193 100644 --- a/assets/modal/modal.js +++ b/assets/modal/modal.js @@ -3,3 +3,15 @@ // console.log(modalDisplayData); // console.log(modalDisplayData.content, modalDisplayData.remainingDays); // })(); +document.addEventListener('DOMContentLoaded', function () { + const settingsImg = document.getElementById('settingset'); + const extraDiv = document.getElementById('extra'); + + settingsImg.addEventListener('mouseenter', function () { + extraDiv.style.display = 'block'; + }); + + settingsImg.addEventListener('mouseleave', function () { + extraDiv.style.display = 'none'; + }); + }); \ No newline at end of file diff --git a/manifest.json b/manifest.json index aa72c32..946a50f 100644 --- a/manifest.json +++ b/manifest.json @@ -7,15 +7,9 @@ "service_worker": "service-worker.js", "type": "module" }, - "permissions": ["scripting", "storage", "alarms", "notifications"], + "permissions": ["tabs", "scripting", "storage", "alarms", "notifications"], "host_permissions": ["https://onestop.pusan.ac.kr/", "https://cse.pusan.ac.kr/cse/14651/subview.do"], "action": { "default_popup": "/assets/popup/popup.html" - }, - "icons": { - "16": "assets/img/iconImg-16.png", - "32": "assets/img/iconImg-32.png", - "48": "assets/img/iconImg-48.png", - "128": "assets/img/iconImg-128.png" } } diff --git a/scripts/crawling.js b/scripts/crawling.js index ffad95e..8abcf3c 100644 --- a/scripts/crawling.js +++ b/scripts/crawling.js @@ -1,16 +1,9 @@ -import { localStorageSet, localStorageGet } from './storage.js'; - async function getSchedules() { const { tabs } = await chrome.windows.create({ url: 'https://onestop.pusan.ac.kr', state: 'minimized', }); - setTimeout(function () { - chrome.windows.remove(tabs[0].windowId); - return null; - }, 15000); - const result = await chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, func: () => { @@ -34,11 +27,6 @@ async function getMajorNotices() { state: 'minimized', }); - setTimeout(function () { - chrome.windows.remove(tabs[0].windowId); - return null; - }, 15000); - const result = await chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, func: () => { diff --git a/scripts/notification.js b/scripts/notification.js index fc87aa9..172a4a6 100644 --- a/scripts/notification.js +++ b/scripts/notification.js @@ -1,14 +1,17 @@ /* eslint-disable no-param-reassign */ import { getMajorNotices, getSchedules } from './crawling.js'; import { localStorageGet, localStorageSet } from './storage.js'; +import preprocessAndUpload from './preprocess.js'; const createNotificationSignal = () => { - chrome.runtime.onMessage.addListener((request) => { + chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + console.log(request); if (request.crawlingPeriod) { + console.log('i created alarm'); // 팝업 설정 페이지에서 설정한 크롤링 주기를 이용하여 알람을 생성합니다. chrome.alarms.create('crawlingPeriod', { delayInMinutes: 0, - periodInMinutes: request.crawlingPeriod * 60, + periodInMinutes: 60, }); } }); @@ -20,27 +23,21 @@ const createDDayNotification = async () => { if (changes.todayDate || changes.noticeDDay) { const { schedules } = await localStorageGet('schedules'); const { noticeDDay } = await localStorageGet('noticeDDay'); - const { modalOnOff } = await localStorageGet('modalOnOff'); const todayDate = new Date(); + console.log(noticeDDay); - if (modalOnOff) { - for (let i = 0; i < schedules.length; i += 1) { - const scheduledDay = new Date(schedules[i].startDay); - let dDay = (scheduledDay - todayDate) / aDay; - - if (dDay > noticeDDay) { - break; - } else if (dDay < 0) { - dDay = 'Day'; - } else { - dDay = Math.ceil(dDay); - } + for (let i = 0; i < schedules.length; i += 1) { + const scheduledDay = new Date(schedules[i].startDay); + const dDay = (scheduledDay - todayDate) / aDay; + if (dDay > noticeDDay) { + break; + } else { chrome.notifications.create( { type: 'basic', iconUrl: 'assets/img/iconImg.png', - title: `학사일정 알림 - [D-${dDay}]`, + title: `학사일정 D-Day - {${dDay}}`, message: `${schedules[i].content}`, silent: false, }, @@ -52,66 +49,41 @@ const createDDayNotification = async () => { }); }; -const updateStorageByAlarm = async () => { - const schedules = await getSchedules(); - const majorNotices = await getMajorNotices(); - const fixedNotices = []; - const nonfixedNotices = []; - - // 네트워크 오류로 인해 schedules, majorNotices가 null일 경우 5초 뒤에 다시 시도합니다. - if (schedules === null || majorNotices === null) { - setTimeout(updateStorageByAlarm, 5000); - return; - } - - 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() }); -}; - const createNotification = () => { const newNotice = []; chrome.storage.onChanged.addListener(async (changes) => { + console.log(changes); if (changes.fixedNotices) { - if (changes.fixedNotices.oldValue) { + try { for (let i = 0; i < changes.fixedNotices.newValue.length; i += 1) { if (changes.fixedNotices.oldValue[0].articleTitle === changes.fixedNotices.newValue[i].articleTitle) { break; } newNotice.push(changes.fixedNotices.newValue[i]); } - } + } catch (err) {} } if (changes.nonfixedNotices) { - if (changes.nonfixedNotices.oldValue) { + try { for (let i = 0; i < changes.nonfixedNotices.newValue.length; i += 1) { if (changes.nonfixedNotices.oldValue[0].articleTitle === changes.nonfixedNotices.newValue[i].articleTitle) { break; } newNotice.push(changes.nonfixedNotices.newValue[i]); } - } + } catch (err) {} } + console.log(newNotice); const { modalOnOff } = await chrome.storage.local.get('modalOnOff'); - if (modalOnOff && newNotice.length > 0) { + if (modalOnOff === true && newNotice.length > 0) { for (let i = 0; i < newNotice.length; i += 1) { chrome.notifications.create( { type: 'basic', iconUrl: 'assets/img/iconImg.png', title: '새 공지가 등록되었습니다.', - message: `${newNotice[i].articleTitle}`, + message: `${newNotice[0].articleTitle}`, silent: false, }, () => {}, @@ -121,7 +93,40 @@ const createNotification = () => { } }); - chrome.alarms.onAlarm.addListener(updateStorageByAlarm); + chrome.alarms.onAlarm.addListener(async (alarm) => { + const schedules = await getSchedules(); + const majorNotices = await getMajorNotices(); + const fixedNotices = []; + const nonfixedNotices = []; + + // 네트워크 연결 오류 시 예외 처리 필요 + + while (true) { + try { + 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); + }); + console.log('i got alarm!'); + localStorageSet({ schedules, fixedNotices, nonfixedNotices, todayDate: new Date().getDate() }); + break; + } catch (err) { + console.log('Error occured: ', err); + // eslint-disable-next-line no-await-in-loop + await new Promise((resolve, reject) => { + setTimeout(resolve, 5000); + }); + } + } + }); }; export { createNotificationSignal, createDDayNotification, createNotification }; diff --git a/scripts/storage.js b/scripts/storage.js index b9de739..fb3aa2e 100644 --- a/scripts/storage.js +++ b/scripts/storage.js @@ -1,5 +1,6 @@ const localStorageSet = (content) => { chrome.storage.local.set(content); + console.log(content); // 크롬 개발자도구에선 확장프로그램의 로컬 스토리지를 볼 수 없다고 해서, 콘솔에 띄웁니다 }; const localStorageGet = (keys) => { diff --git a/service-worker.js b/service-worker.js index d4266eb..7f5df45 100644 --- a/service-worker.js +++ b/service-worker.js @@ -3,15 +3,15 @@ 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, -// }); -// } +function openModal() { + chrome.windows.create({ + url: 'assets/modal/modal.html', + type: 'popup', + width: 500, + height: 450, + focused: true, + }); +} chrome.runtime.onInstalled.addListener(async ({ reason }) => { if (reason === 'install' || reason === 'update') { @@ -52,3 +52,4 @@ chrome.runtime.onInstalled.addListener(async ({ reason }) => { createNotificationSignal(); createNotification(); createDDayNotification(); +openModal(); \ No newline at end of file