File size: 1,612 Bytes
986a9c2
 
 
111554a
 
 
 
 
 
 
 
01bb868
 
111554a
 
01bb868
 
 
111554a
01bb868
 
 
111554a
986a9c2
 
 
 
 
 
 
 
fc5ebc4
 
 
 
 
111554a
01bb868
111554a
 
fc5ebc4
 
 
 
 
 
 
 
 
 
111554a
397ee41
111554a
397ee41
111554a
 
 
 
 
 
 
397ee41
 
 
 
01bb868
 
986a9c2
 
 
 
 
 
 
 
fc5ebc4
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
let showSeconds = true;
let showAmPm = true;

function showTime() {
    const date = new Date();
    let h = date.getHours(); // 0 - 23
    let m = date.getMinutes(); // 0 - 59
    let s = date.getSeconds(); // 0 - 59
    let session = "AM";

    if (h == 0) {
        h = 12;
    }

    if (h > 12) {
        h = h - 12;
        session = "PM";
    }

    h = (h < 10) ? "0" + h : h;
    m = (m < 10) ? "0" + m : m;
    s = (s < 10) ? "0" + s : s;

    let time = h + ":" + m;
    if (showSeconds) {
        time += ":" + s;
    }
    if (showAmPm) {
        time += " " + session;
    }

    const clockDisplay = document.getElementById("MyClockDisplay");
    clockDisplay.innerText = time;
    clockDisplay.textContent = time;

    adjustFontSize(clockDisplay);

    setTimeout(showTime, 1000);
}

function adjustFontSize(element) {
    if (showSeconds && showAmPm) {
        element.style.fontSize = "180px";
    } else if (showSeconds || showAmPm) {
        element.style.fontSize = "200px";
    } else {
        element.style.fontSize = "240px";
    }
}

function toggleMenu() {
    const menu = document.getElementById('menu');
    if (menu.style.display === 'none' || menu.style.display === '') {
        menu.style.display = 'flex';
    } else {
        menu.style.display = 'none';
    }
}

function changeColor(color) {
    document.querySelector('.clock').style.color = color;
}

function changeFont(font) {
    document.querySelector('.clock').style.fontFamily = font;
}

function toggleSeconds() {
    showSeconds = !showSeconds;
}

function toggleAmPm() {
    showAmPm = !showAmPm;
}

showTime();;