-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbackground.js
54 lines (50 loc) · 2.68 KB
/
background.js
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
const facts = [
"Do you know adult humans are 60 percent water, and our blood is 90 percent water? 🌊",
"Drinking water instead of soda can help with weight loss! 🥛",
"Do you know drinking water reduces the chance of a hangover? 🍺",
"Drinking water helps in enhancing physical performance! 🏋",
"Drinking water improves your skin health and beauty! 💃",
"Drinking water instead of other liquids will help you in weight loss! 🧘♀️",
"Drinking more water may help relieve Constipation! 🚽",
"Pace yourself to approach half of your recommended consumption by midday! 🌞",
"Drinking water when you first get up helps you to improve your immune system! 💪",
"Do you know drinking water before a workout will protect you from dehydration? 🏋",
"Drinking water helps you to regulate Body temperature! 🚶♂️",
"Did you know that drinking water lubricates the joints? It can even help with your back pain 🎒",
"Drinking water helps maintaining your blood pressure 🅰️🅱️🆎🅾️",
"Your brain is strongly influenced by your hydration status, make sure to drink water regularly 🧠",
"Dehydration can trigger headaches and migraine, drinking water is the cheapest treatment 🧠",
"Choose water when eating out. Generally, you will save money and reduce calories 😉",
"Carry a water bottle wherever you go, it's the mother nature's health potion ❤️",
"By the time you feel thirsty, your body has lost more than 1% of its total water, so let’s not feel thirst! ⚠️",
"Drinking enough water everyday can help reduce heart disease and cancer. Water helps flush toxins out of your body 👩🏻⚕️",
"There is the same amount of water on Earth as there was when the planet was formed. Believe it or not, the water you drink could share the same molecules that dinosaurs drank 🦖",
];
const factsSize = facts.length;
const notificationMessage = "Hey there, It's time to drink some water.";
const notificationTitle = "Stay hydrated!";
let timeInterval = 15;
function restartAlarms() {
browser.alarms.clearAll();
browser.alarms.create("waterReminder", {
periodInMinutes: timeInterval,
});
}
function handleMessage(request, sender, sendResponse) {
timeInterval = request.time;
sendResponse({
response: "Time received successfully",
});
restartAlarms();
}
browser.alarms.onAlarm.addListener(() => {
const fact = facts[Math.floor(Math.random() * factsSize)];
browser.notifications.create("waterNotification", {
type: "basic",
iconUrl: "icons/bottle.png",
title: notificationTitle,
message: `${notificationMessage} \n ${fact}`,
});
});
restartAlarms();
browser.runtime.onMessage.addListener(handleMessage);