Created
April 17, 2024 19:25
-
-
Save RealSGII2/af3f444e7ba1f0b2c4c8730691bc766d to your computer and use it in GitHub Desktop.
oNOazGG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="timer"> | |
| <div class="space"></div> | |
| <label> | |
| <input type="text"> | |
| <span id='timer'></span> | |
| </label> | |
| <div class="space"></div> | |
| </div> | |
| <div class="buttons"> | |
| <button id="start"> | |
| <span>Toggle Window</span> | |
| </button> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const $ = q => document.querySelector(q); | |
| const $i = i => $('#s' + i); | |
| const formatTime = (str) => { | |
| console.log(str) | |
| const s = str.padStart(4, '0').slice(0, 2) + ':' + str.padStart(4, '0').slice(2); | |
| return new Date('Jan 1, 1970 00:' + s).toLocaleTimeString('en-US', { timeStyle: 'medium', hour12: false }).slice(3).replace(':', ''); | |
| } | |
| let isCleared = true; | |
| let isRunning = false; | |
| $('input').addEventListener('focusout', () => { | |
| $('input').value = formatTime($('input').value); | |
| updateClockEditor(); | |
| }); | |
| const start = () => { | |
| isRunning = true; | |
| document.body.classList.add('running'); | |
| currentInterval = setInterval(() => { | |
| $('#timer').innerHTML = '' | |
| const date = new Date(new Date('May 13, 2024 12:00:00 CST').getTime() - Date.now() + 5 * 60 * 60 * 1000); | |
| const timeString = date.toLocaleString('en-US', { | |
| day: '2-digit', | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| second: '2-digit', | |
| hour12: false, | |
| }).replace(', ', ':'); | |
| for (let chunkPos in timeString.split(':')) { | |
| const chunk = timeString.split(':')[chunkPos]; | |
| const without0 = chunk.replace(/^[0:]/g,'') | |
| for (let charPos in chunk) { | |
| const char = chunk[charPos]; | |
| const isGrey = (chunk.length - without0.length) > charPos; | |
| const className = isGrey ? 'unsure' : ''; | |
| $('#timer').innerHTML += `<span class="${className}"}>${char}</span>` | |
| } | |
| const char = ['d ', 'h ', 'm ', 's '][chunkPos] | |
| $('#timer').innerHTML += `<span class="unsure"}>${char}</span>`; | |
| } | |
| }, 1000) | |
| } | |
| start(); | |
| $('#start').addEventListener('click', async () => { | |
| if (!window.documentPictureInPicture.window) { | |
| // Open a Picture-in-Picture window. | |
| const pipWindow = await window.documentPictureInPicture.requestWindow({ | |
| width: videoPlayer.clientWidth, | |
| height: videoPlayer.clientHeight + 50, | |
| }); | |
| } | |
| // if (!isRunning) { | |
| // start(); | |
| // } else { | |
| // if (isCleared) { | |
| // clearInterval(currentInterval); | |
| // document.body.classList.remove('running'); | |
| // isRunning = false; | |
| // $('#start span').innerText = 'Start' | |
| // } else { | |
| // document.body.classList.remove('done'); | |
| // $('audio').load(); | |
| // isCleared = true; | |
| // $('#start span').innerText = 'Start' | |
| // } | |
| // } | |
| }); | |
| let mouseTimeout; | |
| addEventListener('mousemove', () => { | |
| document.body.classList.add('hover'); | |
| if (mouseTimeout) | |
| clearTimeout(mouseTimeout) | |
| mouseTimeout = setTimeout(() => { | |
| document.body.classList.remove('hover'); | |
| }, 1000); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;400;500&display=swap'); | |
| html, | |
| body { | |
| width: 100%; | |
| height: 100%; | |
| margin: 0; | |
| padding: 0; | |
| overflow: hidden; | |
| } | |
| body { | |
| background-color: #f6f8fa; | |
| font-family: "Roboto Mono", monospace; | |
| font-weight: 300; | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: center; | |
| } | |
| * { | |
| font-family: inherit; | |
| box-sizing: border-box; | |
| } | |
| .timer { | |
| display: flex; | |
| align-items: center; | |
| label { | |
| cursor: text; | |
| border-radius: 12px; | |
| &:focus-within { | |
| background-color: rgba(#0969da, 0.1); | |
| box-shadow: 0 0 0 2px #0969da; | |
| .caret { | |
| opacity: 1; | |
| animation: 1000ms blink infinite step-end; | |
| } | |
| } | |
| .done > & { | |
| animation: 1000ms dualBlink infinite step-end; | |
| } | |
| } | |
| input { | |
| width: 0; | |
| height: 0; | |
| background-color: none; | |
| border: none; | |
| outline: 0; | |
| } | |
| span { | |
| font-size: 12vh; | |
| user-select: none; | |
| &.unsure { | |
| opacity: 0.4; | |
| } | |
| &.letter { | |
| margin-right: 24px; | |
| + * { | |
| margin-left: 24px; | |
| } | |
| } | |
| } | |
| .caret { | |
| display: inline-block; | |
| position: relative; | |
| top: 1vh; | |
| height: 24vh; | |
| width: 4px; | |
| background-color: #000000; | |
| opacity: 0; | |
| } | |
| .space { | |
| flex: 1; | |
| } | |
| #m { | |
| text-align: right; | |
| } | |
| } | |
| .buttons { | |
| margin-top: 16px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| .running:not(.hover) & { | |
| opacity: 0; | |
| transition-duration: 1500ms; | |
| } | |
| transition: opacity 125ms; | |
| button { | |
| width: 200px; | |
| height: 44px; | |
| border: none; | |
| border-radius: 22px; | |
| transition: 85ms ease; | |
| cursor: pointer; | |
| font-size: 16px; | |
| font-weight: 500; | |
| &#start { | |
| background-color: #0969da; | |
| color: #ffffff; | |
| &:hover { | |
| background-color: lighten(#0969da, 6%); | |
| } | |
| &:active { | |
| background-color: lighten(#0969da, 12%); | |
| transition: none; | |
| } | |
| } | |
| } | |
| } | |
| @keyframes blink { | |
| 50% { opacity: 0 } | |
| } | |
| @keyframes dualBlink { | |
| 10% { opacity: 0 }; | |
| 30% { opacity: 1 }; | |
| 50% { opacity: 0 }; | |
| 70% { opacity: 1 }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment