-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Merge pull request #9 from HiBixby/develop
π v0.1.2
- Loading branch information
Showing
21 changed files
with
267 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,68 @@ | ||
console.log("background.js loaded!"); | ||
|
||
chrome.alarms.onAlarm.addListener((alarm) => { | ||
console.log("Alarm!!!"); | ||
let passedAlarmCnt = 0; | ||
const CreateTab = (link) => { | ||
//λ§ν¬κ° nullμ΄ μλλΌλ©΄ ν μ΄κΈ° | ||
if (link !== null) { | ||
chrome.tabs.create({ | ||
url: link, | ||
}); | ||
} | ||
}; | ||
const CreateNotificationOptions = (message) => { | ||
let notificationOptions = { | ||
type: "basic", | ||
iconUrl: "logo.png", | ||
title: "μ¨, μΌν΄", | ||
message: "π³μ λͺ©μμπ³", | ||
priority: 2, | ||
}; | ||
if (message !== null) { | ||
notificationOptions.message = message; | ||
} | ||
return notificationOptions; | ||
}; | ||
const CreateNotification = (NOTIFICATION_ID, message) => { | ||
chrome.notifications.create( | ||
NOTIFICATION_ID, | ||
CreateNotificationOptions(message) | ||
); | ||
}; | ||
const UpdateNotification = (NOTIFICATION_ID, message) => { | ||
chrome.notifications.update( | ||
NOTIFICATION_ID, | ||
CreateNotificationOptions(message), | ||
(wasUpdated) => { | ||
console.log("wasUpdated:", wasUpdated); | ||
} | ||
); | ||
}; | ||
const FindIndexOfTodo = (id, result) => { | ||
for (index in result.todos) { | ||
if (id === result.todos[index].id.toString()) return index; | ||
} | ||
}; | ||
|
||
chrome.alarms.onAlarm.addListener(async (alarm) => { | ||
console.log("Alarm executed!", alarm); | ||
const id = alarm.name; | ||
chrome.storage.local.get(["todos"]).then((result) => { | ||
for (index in result.todos) { | ||
if (id === result.todos[index].id.toString()) { | ||
const message = result.todos[index].title; | ||
chrome.notifications.create(id.toString(), { | ||
type: "basic", | ||
iconUrl: "logo.png", | ||
title: "μ¨, μΌν΄", | ||
message: message ? message : "π³μ λͺ© μμπ³", | ||
priority: 2, | ||
}); | ||
if (result.todos[index].link !== null) { | ||
chrome.tabs.create({ | ||
url: result.todos[index].link, | ||
}); | ||
} | ||
} | ||
const result = await chrome.storage.local.get(["todos"]); | ||
console.log("result is...", result); | ||
const index = FindIndexOfTodo(id, result); | ||
//μκ°μ΄ μ§λ μλμΌ λ | ||
if (Date.now() > result.todos[index].date + 60000) { | ||
passedAlarmCnt++; | ||
const NOTIFICATION_ID = "hasPassedAlarms"; | ||
const message = `μ리λ₯Ό λΉμ΄ λμ ${passedAlarmCnt}κ°μ μλ¦Όμ΄ μ€νλμ§ μμμ΅λλ€.`; | ||
if (passedAlarmCnt === 1) { | ||
CreateNotification(NOTIFICATION_ID, message); | ||
} else { | ||
UpdateNotification(NOTIFICATION_ID, message); | ||
} | ||
}); | ||
//μ μ μλμΌ λ | ||
} else { | ||
const message = result.todos[index].title; | ||
CreateNotification(id, message); | ||
CreateTab(result.todos[index].link); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
html, | ||
body { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} | ||
|
||
.logo-container { | ||
height: 100vh; | ||
width: 100vw; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "whale-hae", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite", | ||
|
Oops, something went wrong.