File size: 3,277 Bytes
5f27d46 986a9c2 98dfbc2 986a9c2 111554a 01bb868 111554a 01bb868 111554a 01bb868 111554a 986a9c2 fc5ebc4 98dfbc2 111554a 01bb868 111554a fc5ebc4 5f27d46 fc5ebc4 5f27d46 fc5ebc4 a0af26c fc5ebc4 111554a 397ee41 111554a 397ee41 111554a 397ee41 01bb868 986a9c2 faa54ab 986a9c2 faa54ab 986a9c2 98dfbc2 faa54ab 98dfbc2 5f27d46 98dfbc2 faa54ab a0af26c faa54ab |
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
let showSeconds = false;
let showAmPm = true;
let autoSize = 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;
if (autoSize) {
adjustFontSize(clockDisplay);
}
setTimeout(showTime, 1000);
}
function adjustFontSize(element) {
if (showSeconds && showAmPm) {
element.style.fontSize = "120px";
} else if (showSeconds || showAmPm) {
element.style.fontSize = "150px";
} else {
element.style.fontSize = "180px
}
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;
showTime();
}
function toggleAmPm() {
showAmPm = !showAmPm;
showTime();
}
function toggleAutoSize() {
autoSize = !autoSize;
const sizeSlider = document.getElementById('sizeSlider');
sizeSlider.disabled = autoSize;
if (autoSize) {
showTime();
}
}
function adjustSpacing(value) {
document.querySelector('.clock').style.letterSpacing = value + 'px';
}
function adjustSize(value) {
if (!autoSize) {
document.querySelector('.clock').style.fontSize = value + 'px';
}
}
function changeBackground(background) {
document.body.style.background = background;
}
function updateCustomGradient() {
const color1 = document.getElementById('customBgColor1').value;
const color2 = document.getElementById('customBgColor2').value;
const gradient = `linear-gradient(to right, ${color1}, ${color2})`;
changeBackground(gradient);
}
function resetDefaults() {
showSeconds = false;
showAmPm = true;
autoSize = true;
document.getElementById('toggleSeconds').checked = false;
document.getElementById('toggleAmPm').checked = true;
document.getElementById('toggleAutoSize').checked = true;
document.getElementById('spacingSlider').value = 7;
document.getElementById('sizeSlider').value = 180;
document.querySelector('.clock').style.color = '#73b66f';
document.querySelector('.clock').style.fontFamily = 'Stencil';
document.querySelector('.clock').style.letterSpacing = '7px';
document.querySelector('.clock').style.fontSize = '180px';
document.body.style.background = 'black';
showTime();
}
document.addEventListener('DOMContentLoaded', (event) => {
showTime();
}); |