-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
32 lines (30 loc) · 914 Bytes
/
content.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
const createModal = element => {
const modal = document.createElement("div");
modal.classList.add("modal");
const content = document.createElement("div");
content.classList.add("modal-content");
content.innerHTML = element;
modal.appendChild(content);
document.body.appendChild(modal);
};
const removeModal = () => {
const modalElements = document.getElementsByClassName("modal");
Array.from(modalElements).forEach(el => el.remove());
};
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message) {
let timeleft = 20;
const timerFn = setInterval(() => {
if (timeleft <= 0) {
createModal("Well done! Your eyes thank you ʕ•́ᴥ•̀ʔっ♡");
clearInterval(timerFn);
setTimeout(() => {
removeModal();
}, 3000);
} else {
createModal(timeleft);
}
timeleft--;
}, 1000);
}
});