update global css, add countdown and timer

This commit is contained in:
zyqunix 2025-01-20 23:02:58 +01:00
parent c52aa334ca
commit 10022e6d93
8 changed files with 339 additions and 0 deletions

25
timer/index.html Normal file
View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="https://rimgo.pussthecat.org/RFbdMMB.png" type="image/x-icon">
<title>zy's Timer</title>
</head>
<body>
<div class="main">
<span id="time">00:00:00:00</span>
<div class="buttons">
<button id="start">Start</button>
<button id="lap">Lap</button>
<button id="reset">Reset</button>
</div>
<a href="/countdown">Countdown</a>
<ul id="lap-list"></ul>
</div>
<script src="index.js"></script>
</body>
</html>

54
timer/index.js Normal file
View file

@ -0,0 +1,54 @@
const time = document.getElementById('time');
const start = document.getElementById('start');
const reset = document.getElementById('reset');
const lap = document.getElementById('lap');
const lapList = document.getElementById('lap-list');
let isActive = false;
let timer = null;
let startTime = null;
let elapsedTime = 0;
function formatTime(duration) {
const milliseconds = Math.floor((duration % 1000) / 10);
const seconds = Math.floor((duration / 1000) % 60);
const minutes = Math.floor((duration / 1000) / 60);
const hours = Math.floor((duration / 1000) / 60 / 60);
return `
${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}:${String(milliseconds).padStart(2, '0')}`;
}
start.addEventListener('click', () => {
if (! isActive) {
isActive = true;
start.innerHTML = "Stop";
startTime = Date.now() - elapsedTime;
timer = setInterval(() => {
elapsedTime = Date.now() - startTime;
time.textContent = formatTime(elapsedTime);
}, 10);
} else {
isActive = false;
clearInterval(timer);
start.innerHTML = "Start";
}
});
reset.addEventListener('click', () => {
isActive = false;
clearInterval(timer);
timer = null;
startTime = null;
elapsedTime = 0;
time.textContent = "00:00:00:00";
start.innerHTML = "Start";
lapList.innerHTML = "";
});
lap.addEventListener('click', () => {
if (isActive) {
const lapTime = document.createElement('li');
lapTime.textContent = formatTime(elapsedTime);
lapList.appendChild(lapTime);
}
});

82
timer/style.css Normal file
View file

@ -0,0 +1,82 @@
@import url(/global.css);
div.main {
padding: 60px;
display: grid;
justify-content: center;
background-color: #3a3a3a;
border-radius: 10px;
margin: 50px auto;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
max-width: 600px;
text-align: center;
}
div.main button {
margin: 0 10px;
cursor: pointer;
color: #fff;
border: none;
padding: 15px 25px;
font-size: 16px;
font-weight: bold;
transition: background-color 0.3s ease, transform 0.1s ease;
border-radius: 8px;
}
#time {
margin-bottom: 30px;
font-size: 36px;
font-weight: 700;
color: #f5f5f5;
}
.buttons {
display: flex;
justify-content: center;
gap: 10px;
}
#start {
background-color: #4caf50;
border: 2px solid #4caf50;
}
#lap {
background-color: #3b5998;
border: 2px solid #3b5998;
}
#reset {
background-color: #f44336;
border: 2px solid #f44336;
}
#start:hover {
background-color: #45a049;
transform: scale(1.01);
}
#lap:hover {
background-color: #2e486f;
transform: scale(1.01);
}
#reset:hover {
background-color: #e53935;
transform: scale(1.01);
}
a {
position: fixed;
bottom: 20px;
left: 20px;
color: #b3b3b3;
text-decoration: none;
font-size: 14px;
transition: color 0.2s ease;
}
a:hover {
color: #fff;
}