Skip to content

Commit 1c1244e

Browse files
authored
Merge pull request #3 from obayomi96/ft-new-features
[Feature]: Update version with additional features & fixes
2 parents 0f715bd + e3e1b5c commit 1c1244e

File tree

9 files changed

+167
-135
lines changed

9 files changed

+167
-135
lines changed

.github/pull_request_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## What does this PR do?
2+
3+
4+
## How can this PR (Update) be manually tested?
5+
6+
7+
## Other Information / Background Context
8+
9+
10+
## Issue Information
11+
12+
- Summary of Issue (In your own words):

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## BLINKALERT CHROME EXTENSION (Version 3.0.0)
1+
## BLINKALERT CHROME EXTENSION (Version 3.0.3)
22

33
###### DESCRIPTION
44

@@ -14,6 +14,8 @@
1414
###### FEATURES
1515

1616
* Reminder at 20 minutes interval to, rest and take the 20-20-20 exercise.
17+
* You can select between 3 options of duration interval.
18+
* Displays a visual timer on the extension popup for time left till next break.
1719
* Leads you through the exercise procedures in a new tab.
1820

1921
###### AUTHOR

css/style.css

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ h3.title {
2121
text-align: center;
2222
padding: 10px;
2323
}
24-
.version {
24+
.github {
2525
font-size: 10px;
2626
color: grey;
2727
padding: 10px;
@@ -99,26 +99,7 @@ h3.title {
9999
border: 0.1rem #eee solid;
100100
}
101101

102-
.modal-icons {
103-
bottom: 0;
104-
border-top: 0.5px solid #dadada;
105-
height: 30px;
106-
width: 100%;
107-
}
108-
.logo {
109-
padding: 15px;
110-
}
111-
.logo-icon {
112-
vertical-align: text-bottom;
113-
margin-right: 12px;
114-
}
115-
.flex-container {
116-
display: flex;
117-
justify-content: space-between;
118-
padding: 10px 22px;
119-
bottom: 0;
120-
}
121-
.flex {
102+
.github-a {
122103
opacity: 1;
123104
transition: opacity 0.2s ease-in-out;
124105
width: 120px;
@@ -127,10 +108,23 @@ h3.title {
127108
margin: 0;
128109
padding: 0;
129110
}
130-
.flex:hover {
111+
112+
.github-a:hover {
131113
opacity: 0.4;
132114
}
133-
.flex .fa {
115+
116+
.github-a .fa {
134117
font-size: 20px;
135118
color: #2f5876;
136119
}
120+
121+
#popup-timer {
122+
border: 1px solid #dadada;
123+
display: inline;
124+
padding: 5px;
125+
color: black;
126+
font-family: Verdana, sans-serif, Arial;
127+
font-size: 14px;
128+
font-weight: normal;
129+
text-decoration: none;
130+
}

exercise.html

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!doctype html>
22
<html>
3+
34
<head>
45
<meta charset="utf-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -9,21 +10,26 @@
910
<title>Blink Alert</title>
1011
</head>
1112
<header>
12-
<h1>20-20-20 Exercise</h1>
13-
<hr>
13+
<h1>20-20-20 Exercise</h1>
14+
<hr>
1415
</header>
15-
<body>
16-
<div id="countdown-timer" class="countdown-timer"></div>
17-
<div id="modal" class="modal">
18-
<div class="modal__header">
19-
<h2>Exercise</h2>
20-
</div><br><br>
21-
<div id="message">
22-
After or during a long day of working with a computer, it is recommended to keep your eyes healthy for the long run by taking the 20-20-20 exercise every 20 minutes</div> <br>
23-
<hr>
24-
<br><div class="rule" id="message">Look Away From Your Computer, Look at something 20 feets away for 20 seconds (see timer..)<br> -BLINK AS MANY TIMES AS YOU CAN</div>
25-
</div>
26-
<script src="js/main.js"></script>
27-
<script src="js/background.js"></script>
28-
</body>
16+
17+
<body>
18+
<div id="countdown-timer" class="countdown-timer"></div>
19+
<div id="modal" class="modal">
20+
<div class="modal__header">
21+
<h2>Exercise</h2>
22+
</div><br><br>
23+
<div id="message">
24+
After or during a long day of working with a computer, it is recommended to keep your eyes healthy for the long
25+
run by taking the 20-20-20 exercise every 20 minutes</div> <br>
26+
<hr>
27+
<br>
28+
<div class="rule" id="message">Look Away From Your Computer, Look at something 20 feets away for 20 seconds (see
29+
timer..)<br> -BLINK AS MANY TIMES AS YOU CAN</div>
30+
</div>
31+
<script src="js/main.js"></script>
32+
<script src="js/background.js"></script>
33+
</body>
34+
2935
</html>

js/background.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Chrome notification API
2+
const options = {
3+
type: "basic",
4+
title: "Blink Alert! - Take a break",
5+
message:
6+
"Look away from your computer for 20 seconds. (click here to take full exercise)",
7+
iconUrl: "../images/eyeIcon_128.png",
8+
};
9+
10+
let selectedDuration;
11+
let intervalId;
12+
13+
const createNotification = () => {
14+
chrome.notifications.create(options);
15+
};
16+
17+
const createExerciseTab = () => {
18+
chrome.tabs.create({ url: "exercise.html" });
19+
};
20+
21+
chrome.notifications.onClicked.addListener(createExerciseTab);
22+
23+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
24+
if (message.updateInterval) {
25+
chrome.storage.local.get("duration", ({ duration }) => {
26+
selectedDuration = duration;
27+
if (intervalId) {
28+
clearInterval(intervalId);
29+
}
30+
intervalId = setInterval(createNotification, +selectedDuration);
31+
});
32+
}
33+
});
34+
35+
chrome.runtime.onInstalled.addListener(() => {
36+
// Set an initial alarm when the extension is installed or updated
37+
chrome.storage.local.get("duration", ({ duration }) => {
38+
selectedDuration = duration;
39+
intervalId = setInterval(createNotification, +selectedDuration);
40+
});
41+
});
42+
43+
const keepAlive = () => setInterval(chrome.runtime.getPlatformInfo, 20e3);
44+
chrome.runtime.onStartup.addListener(keepAlive);
45+
keepAlive();

js/main.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// 20 minutes countdown timer
1+
// 20 minutes countdown timer for excersise page
22
function countdown(elementName, minutes, seconds) {
33
let element, endTime, hours, mins, msLeft, time;
44
// Make countdown double digits when less that 10
55
function twoDigits(n) {
66
return n <= 9 ? "0" + n : n;
77
}
8-
// Timer counter update
98
function updateTimer() {
109
msLeft = endTime - +new Date();
1110
if (msLeft < 1000) {
@@ -16,13 +15,13 @@ function countdown(elementName, minutes, seconds) {
1615
mins = time.getUTCMinutes();
1716
element.innerHTML =
1817
(hours ? "0" + ":" + twoDigits(mins) : mins) +
19-
":" + twoDigits(time.getUTCSeconds());
18+
":" +
19+
twoDigits(time.getUTCSeconds());
2020
setTimeout(updateTimer, time.getUTCMilliseconds() + 500);
2121
}
22-
} // updateTimer function end
23-
22+
}
2423
element = document.getElementById(elementName);
2524
endTime = +new Date() + 1000 * (60 * minutes + seconds) + 500;
2625
updateTimer();
27-
} // countdown function end
26+
}
2827
countdown("countdown-timer", 0, 20);

js/popup.js

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,45 @@
1-
// // Chrome notification API
2-
const options = {
3-
type: "basic",
4-
title: "Blink Alert! - Its been 20 minutes!",
5-
message:
6-
"Look away from your Computer, Look at something 20 feet away for 20 seconds. (CLICK HERE TO TAKE EXERCISE)",
7-
iconUrl: "images/eyeIcon_128.png",
8-
};
9-
10-
let selectedDuration;
11-
12-
const durationBtn1 = document.getElementById("durationBtn1");
13-
const durationBtn2 = document.getElementById("durationBtn2");
14-
const durationBtn3 = document.getElementById("durationBtn3");
15-
161
const checkSelectedBtn = (value) => {
17-
if (value === "1200000") {
2+
if (value === 1200000) {
183
durationBtn1.classList.add("btnSelected");
194
durationBtn2.classList.remove("btnSelected");
205
durationBtn3.classList.remove("btnSelected");
21-
} else if (value === "3600000") {
6+
} else if (value === 3600000) {
227
durationBtn2.classList.add("btnSelected");
238
durationBtn1.classList.remove("btnSelected");
249
durationBtn3.classList.remove("btnSelected");
25-
} else if (value === "7200000") {
10+
} else if (value === 7200000) {
2611
durationBtn3.classList.add("btnSelected");
2712
durationBtn1.classList.remove("btnSelected");
2813
durationBtn2.classList.remove("btnSelected");
2914
}
3015
};
3116

32-
chrome.storage.local.get("duration", ({ duration }) => {
33-
selectedDuration = duration || 1200000;
34-
checkSelectedBtn(duration);
35-
});
17+
const durationBtn1 = document.getElementById("durationBtn1");
18+
const durationBtn2 = document.getElementById("durationBtn2");
19+
const durationBtn3 = document.getElementById("durationBtn3");
3620

37-
durationBtn1.addEventListener("click", () => {
38-
chrome.storage.local.set({ duration: "1200000" }, () => {
39-
selectedDuration = 1200000;
40-
});
41-
chrome.storage.local.get("duration", ({ duration }) => {
42-
checkSelectedBtn(duration);
21+
const setDuration = (value) => {
22+
chrome.storage.local.set({ duration: value }, () => {
23+
// Send a message to the background script to update the interval
24+
chrome.runtime.sendMessage({ updateInterval: true });
25+
checkSelectedBtn(value);
4326
});
44-
});
27+
};
4528

46-
durationBtn2.addEventListener("click", () => {
47-
chrome.storage.local.set({ duration: "3600000" }, () => {
48-
selectedDuration = 3600000;
49-
});
29+
document.addEventListener("DOMContentLoaded", () => {
5030
chrome.storage.local.get("duration", ({ duration }) => {
51-
checkSelectedBtn(duration);
31+
setDuration(duration || 1200000);
5232
});
5333
});
5434

55-
durationBtn3.addEventListener("click", () => {
56-
chrome.storage.local.set({ duration: "7200000" }, () => {
57-
selectedDuration = 7200000;
58-
});
59-
chrome.storage.local.get("duration", ({ duration }) => {
60-
checkSelectedBtn(duration);
61-
});
35+
durationBtn1.addEventListener("click", () => {
36+
setDuration(1200000);
6237
});
6338

64-
setInterval(() => {
65-
chrome.notifications.create(options);
66-
}, Number(selectedDuration) || 1200000);
39+
durationBtn2.addEventListener("click", () => {
40+
setDuration(3600000);
41+
});
6742

68-
// Create a new tab onclick of notification
69-
chrome.notifications.onClicked.addListener(function () {
70-
chrome.tabs.create({ url: "exercise.html" });
43+
durationBtn3.addEventListener("click", () => {
44+
setDuration(7200000);
7145
});

manifest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "Blink Alert",
44
"description": "A reminder for a computer user to take the 20-20-20 blinking exercise at set intervals",
5-
"version": "3.0.2",
5+
"version": "3.0.3",
66
"icons": {
77
"19": "images/eyeIcon.png",
88
"128": "images/eyeIcon_128.png"
@@ -19,6 +19,9 @@
1919
"notifications",
2020
"storage"
2121
],
22+
"background": {
23+
"service_worker": "js/background.js"
24+
},
2225
"content_security_policy": {
2326
"extension_pages": "script-src 'self'; object-src 'self'"
2427
}

0 commit comments

Comments
 (0)