-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup_script.js
47 lines (45 loc) · 1.12 KB
/
popup_script.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
//region {variables and functions}
const timeId = "time";
const dateId = "date";
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const months = [
"Jan",
"Feb",
"Mar",
"May",
"Apr",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
const consoleGreeting = "Hello World! - from popup_script.js";
function setTimeAndDate(timeElement, dateElement) {
let date = new Date();
const minutes = (date.getMinutes() < 10 ? "0" : "") + date.getMinutes();
const time = date.getHours() + ":" + minutes;
//In "date.getMonth", 0 indicates the first month of the year
//In "date.getDay", 0 represents Sunday
date =
days[date.getDay()] +
", " +
months[date.getMonth()] +
" " +
date.getDate() +
" " +
date.getFullYear();
timeElement.innerHTML = time;
dateElement.innerHTML = date;
}
//end-region
//region {calls}
console.log(consoleGreeting);
document.addEventListener("DOMContentLoaded", function (dcle) {
const timeElement = document.getElementById(timeId);
const dateElement = document.getElementById(dateId);
setTimeAndDate(timeElement, dateElement);
});
//end-region