| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Custom Timer</title> |
| <style> |
| :root { |
| --countdown-color: #ff4b1f; |
| --timer-color: #32cd32; |
| --pause-color: #ffcc00; |
| --stop-color: #ffffff; |
| } |
| |
| body, html { |
| margin: 0; |
| padding: 0; |
| height: 100%; |
| display: flex; |
| justify-content: center; |
| align-items: center; |
| font-family: Arial, sans-serif; |
| transition: background 0.5s, color 0.5s; |
| box-sizing: border-box; |
| } |
| |
| .container { |
| text-align: center; |
| background: #ffffff; |
| padding: 15px; |
| border-radius: 10px; |
| width: 100%; |
| max-width: 422px; |
| height: auto; |
| box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); |
| display: flex; |
| flex-direction: column; |
| justify-content: space-between; |
| } |
| |
| .input-row, .button-row, .iframe-row { |
| display: flex; |
| justify-content: space-between; |
| align-items: center; |
| margin: 5px 0; |
| } |
| |
| .input-row input, .button-row button, .iframe-row iframe { |
| flex: 1; |
| margin: 3px; |
| color: black; |
| border-radius: 5px; |
| border: 1px solid #ccc; |
| } |
| |
| input { |
| padding: 10px; |
| border: none; |
| border-radius: 5px; |
| text-align: center; |
| font-size: 1em; |
| } |
| |
| #timeDisplay { |
| font-size: 2.5em; |
| color: #32cd32; |
| width: 100%; |
| display: flex; |
| justify-content: center; |
| align-items: center; |
| font-family: 'Courier New', Courier, monospace; |
| letter-spacing: 2px; |
| background: #f4f4f4; |
| border-radius: 5px; |
| margin: 10px 0; |
| transition: color 0.5s; |
| } |
| |
| button { |
| padding: 8px; |
| border: none; |
| border-radius: 5px; |
| color: white; |
| cursor: pointer; |
| font-size: 0.9em; |
| transition: background-color 0.3s; |
| } |
| |
| .button-row button:disabled { |
| background-color: grey; |
| cursor: not-allowed; |
| } |
| |
| #startCountdownButton { |
| background-color: var(--countdown-color); |
| } |
| |
| #startTimerButton { |
| background-color: var(--timer-color); |
| } |
| |
| #pauseButton { |
| background-color: var(--pause-color); |
| } |
| |
| #stopButton { |
| background-color: var(--stop-color); |
| color: black; |
| } |
| |
| .iframe-row iframe { |
| width: 100%; |
| height: 110px; |
| border: none; |
| } |
| </style> |
| </head> |
| <body> |
| <audio id="alertSound"> |
| <source src="ear0.wav" type="audio/mpeg"> |
| </audio> |
| <div class="container"> |
| <div class="iframe-row"> |
| <a href="https://feeday.cn"><img class="img" src="https://tool.lu/netcard/" width="320" height="120" alt=""/></a> |
| </div> |
| <div class="input-row"> |
| <input type="number" id="hours" placeholder="HH" min="0" max="23"> |
| <input type="number" id="minutes" placeholder="MM" min="0" max="59" value="15"> |
| <input type="number" id="seconds" placeholder="SS" min="0" max="59"> |
| </div> |
| <div class="button-row"> |
| <button id="startCountdownButton" onclick="startCountdown()">倒计时</button> |
| <button id="startTimerButton" onclick="startTimer()">计时器</button> |
| <button id="pauseButton" onclick="pauseTimer()" disabled>暂停</button> |
| <button id="stopButton" onclick="stopTimer()" disabled>停止</button> |
|
|
| </div> |
| <div id="timeDisplay">00:00:00:00</div> |
|
|
|
|
| <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=320 height=110 src="//music.163.com/outchain/player?type=0&id=12658009656&auto=1&height=90"></iframe> |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
|
|
| <script> |
| let timer; |
| let endTime; |
| let startTime; |
| let remainingTime; |
| let isCountdown = false; |
| let isPaused = false; |
| |
| const timeDisplay = document.getElementById('timeDisplay'); |
| const alertSound = document.getElementById('alertSound'); |
| |
| document.addEventListener('DOMContentLoaded', () => { |
| startTimer(); |
| }); |
| |
| function startCountdown() { |
| if (timer) { |
| clearInterval(timer); |
| } |
| const hours = parseInt(document.getElementById('hours').value) || 0; |
| const minutes = parseInt(document.getElementById('minutes').value) || 0; |
| const seconds = parseInt(document.getElementById('seconds').value) || 0; |
| |
| if (hours === 0 && minutes === 0 && seconds === 0) { |
| alert('Please set a valid time for countdown.'); |
| return; |
| } |
| |
| document.body.className = 'countdown'; |
| timeDisplay.style.color = 'var(--countdown-color)'; |
| const totalMilliseconds = (hours * 3600 + minutes * 60 + seconds) * 1000; |
| |
| if (totalMilliseconds > 0) { |
| isCountdown = true; |
| endTime = Date.now() + totalMilliseconds; |
| timer = setInterval(updateTime, 10); |
| document.getElementById('startCountdownButton').disabled = true; |
| document.getElementById('startTimerButton').disabled = false; |
| document.getElementById('pauseButton').disabled = false; |
| document.getElementById('stopButton').disabled = false; |
| } |
| } |
| |
| function startTimer() { |
| if (timer) { |
| clearInterval(timer); |
| } |
| document.body.className = 'timer'; |
| timeDisplay.style.color = 'var(--timer-color)'; |
| startTime = Date.now(); |
| isPaused = false; |
| isCountdown = false; |
| timer = setInterval(updateTime, 10); |
| document.getElementById('startCountdownButton').disabled = false; |
| document.getElementById('startTimerButton').disabled = true; |
| document.getElementById('pauseButton').disabled = false; |
| document.getElementById('stopButton').disabled = false; |
| } |
| |
| function pauseTimer() { |
| document.body.className = 'pause'; |
| timeDisplay.style.color = 'var(--pause-color)'; |
| clearInterval(timer); |
| if (isCountdown) { |
| remainingTime = endTime - Date.now(); |
| } else { |
| remainingTime = Date.now() - startTime; |
| } |
| isPaused = true; |
| document.getElementById('pauseButton').innerText = "继续"; |
| document.getElementById('pauseButton').onclick = resumeTimer; |
| } |
| |
| function resumeTimer() { |
| document.body.className = isCountdown ? 'countdown' : 'timer'; |
| timeDisplay.style.color = isCountdown ? 'var(--countdown-color)' : 'var(--timer-color)'; |
| if (isCountdown) { |
| endTime = Date.now() + remainingTime; |
| } else { |
| startTime = Date.now() - remainingTime; |
| } |
| isPaused = false; |
| timer = setInterval(updateTime, 10); |
| document.getElementById('pauseButton').innerText = "暂停"; |
| document.getElementById('pauseButton').onclick = pauseTimer; |
| } |
| |
| |
| function stopTimer() { |
| document.body.className = 'stop'; |
| timeDisplay.style.color = 'var(--stop-color)'; |
| clearInterval(timer); |
| timeDisplay.innerHTML = '00:00:00:00'; |
| resetButtons(); |
| } |
| |
| function updateTime() { |
| const currentTime = Date.now(); |
| let remaining; |
| if (isCountdown) { |
| remaining = endTime - currentTime; |
| if (remaining <= 0) { |
| clearInterval(timer); |
| alertSound.play(); |
| resetButtons(); |
| timeDisplay.innerHTML = '00:00:00:00'; |
| return; |
| } |
| } else { |
| remaining = currentTime - startTime; |
| } |
| |
| const milliseconds = remaining % 1000; |
| const totalSeconds = Math.floor(remaining / 1000); |
| const seconds = totalSeconds % 60; |
| const totalMinutes = Math.floor(totalSeconds / 60); |
| const minutes = totalMinutes % 60; |
| const hours = Math.floor(totalMinutes / 60); |
| |
| timeDisplay.innerHTML = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}:${pad(Math.floor(milliseconds / 100), 2)}`; |
| } |
| |
| function pad(number, length = 2) { |
| return number.toString().padStart(length, '0'); |
| } |
| |
| |
| |
| function resetButtons() { |
| document.getElementById('startCountdownButton').disabled = false; |
| document.getElementById('startTimerButton').disabled = false; |
| document.getElementById('pauseButton').disabled = true; |
| document.getElementById('stopButton').disabled = true; |
| |
| |
| document.getElementById('pauseButton').innerText = "暂停"; |
| document.getElementById('pauseButton').onclick = pauseTimer; |
| |
| document.body.className = ''; |
| isPaused = false; |
| remainingTime = 0; |
| timer = null; |
| } |
| |
| </script> |
| </body> |
| </html> |