-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
81 lines (67 loc) · 2.1 KB
/
Copy pathcontentScript.js
File metadata and controls
81 lines (67 loc) · 2.1 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let imageIndex = 0;
const imageUrls = [
{
url: "image1.gif",
text: "Relaxes the neck pain due to continuous work.",
},
{
url: "image2.gif",
text: "Increase the blood flow in your arm and reduce soreness.",
},
{
url: "image3.gif",
text: "This stretch is also known as the rhomboid upper or upper back stretch.",
},
{
url: "image4.gif",
text: "Regain your mobility and full range of motion and flexibility of the neck muscles.",
},
{
url: "image5.gif",
text: "This frees your glute muscles and relaxes the waist pain.",
},
];
let startTime = null;
let intervalId = null;
function updateImage() {
const image = document.getElementById("carousel-image");
image.src = chrome.runtime.getURL(imageUrls[imageIndex].url);
const paragraph = document.getElementById("carousel-paragraph");
paragraph.textContent = imageUrls[imageIndex].text;
}
function getRandomImageIndex() {
imageIndex = Math.floor(Math.random() * imageUrls.length);
}
function updateActiveTime() {
const currentTime = new Date();
const activeTime = Math.floor((currentTime - startTime) / 1000);
const hours = Math.floor(activeTime / 3600);
const minutes = Math.floor((activeTime % 3600) / 60);
const seconds = activeTime % 60;
const formattedTime = `${hours.toString().padStart(2, "0")}:${minutes
.toString()
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
const activeTimeElement = document.getElementById("active-time");
activeTimeElement.textContent = `Surfing Time: ${formattedTime}`;
}
document.addEventListener("DOMContentLoaded", () => {
getRandomImageIndex();
updateImage();
chrome.runtime.sendMessage("getStartTime", (response) => {
startTime = new Date(response.startTime);
updateActiveTime();
intervalId = setInterval(updateActiveTime, 1000);
});
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.updateActiveTime) {
updateActiveTime();
}
if (message === "nextImage") {
getRandomImageIndex();
updateImage();
}
if (message === "popupClosed") {
clearInterval(intervalId);
}
});