wip
This commit is contained in:
parent
8631733274
commit
bba62e3527
18 changed files with 916 additions and 11 deletions
232
stopwatch/index.html
Normal file
232
stopwatch/index.html
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Stopwatch</title>
|
||||
<meta property="og:title" content="Stopwatch" />
|
||||
<meta property="og:image" content="http://shots.wayl.one/shot/?url=https://stopwatch.wayl.one/&height=630&width=1200&scaled_width=1200&scaled_height=630&selectors=" />
|
||||
<meta property="og:description" content="A large display stopwatch, it just counts up." />
|
||||
<meta property="og:url" content="https://stopwatch.wayl.one/" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:site_name" content="Stopwatch" />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content="Stopwatch" />
|
||||
<meta name="twitter:description" content="A large display stopwatch, it just counts up." />
|
||||
<meta name="twitter:image" content="http://shots.wayl.one/shot/?url=https://stopwatch.wayl.one/&height=630&width=1200&scaled_width=1200&scaled_height=640&selectors=" />
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
height: 100vh;
|
||||
background: black;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-family: monospace;
|
||||
color: lime;
|
||||
user-select: none;
|
||||
}
|
||||
#title {
|
||||
min-width: 100vw;
|
||||
min-height: 5rem;
|
||||
font-size: 3vw;
|
||||
margin-bottom: 1em;
|
||||
outline: none;
|
||||
text-align: center;
|
||||
}
|
||||
#timer {
|
||||
font-size: 10vw;
|
||||
cursor: pointer;
|
||||
}
|
||||
/* Modal styles */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
display: none;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
.modal {
|
||||
box-shadow: 0 0 3rem 1rem #00ff0017;
|
||||
background: black;
|
||||
border: 2px solid lime;
|
||||
border-radius: 0.5rem;
|
||||
padding: 2rem;
|
||||
max-width: 90%;
|
||||
color: lime;
|
||||
text-align: left;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
.modal h2 {
|
||||
margin-top: 0;
|
||||
color: #008e00;
|
||||
}
|
||||
.modal ul {
|
||||
color: #00ae00;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="title" contenteditable="true"></div>
|
||||
<div id="timer">00:00.000</div>
|
||||
<!-- Modal -->
|
||||
<div id="modal-overlay" class="modal-overlay">
|
||||
<div class="modal">
|
||||
<h2>Help</h2>
|
||||
<p>
|
||||
It's just a stopwatch, it counts up, press enter, space or click to start/stop.
|
||||
</p>
|
||||
<p>
|
||||
Start typing to give it a title.
|
||||
</p>
|
||||
<p>
|
||||
Copy with <kbd>Ctrl</kbd> + <kbd>c</kbd>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const timerElement = document.getElementById('timer');
|
||||
const copyButton = document.getElementById('copyButton');
|
||||
let startTime = null;
|
||||
let elapsedTime = 0;
|
||||
let running = true;
|
||||
let animationFrameId = null;
|
||||
|
||||
function formatTime(ms) {
|
||||
const totalMilliseconds = Math.floor(ms);
|
||||
const totalSeconds = Math.floor(totalMilliseconds / 1000);
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
const milliseconds = totalMilliseconds % 1000;
|
||||
|
||||
return (
|
||||
String(minutes).padStart(2, '0') + ':' +
|
||||
String(seconds).padStart(2, '0') + '.' +
|
||||
String(milliseconds).padStart(3, '0')
|
||||
);
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
const now = performance.now();
|
||||
const elapsed = now - startTime + elapsedTime;
|
||||
timerElement.textContent = formatTime(elapsed);
|
||||
animationFrameId = requestAnimationFrame(updateTimer);
|
||||
}
|
||||
|
||||
function toggleTimer() {
|
||||
if (running) {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
elapsedTime += performance.now() - startTime;
|
||||
running = false;
|
||||
} else {
|
||||
startTime = performance.now();
|
||||
running = true;
|
||||
updateTimer();
|
||||
}
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const title = params.get('title');
|
||||
const title_el = document.getElementById('title')
|
||||
if (title) {
|
||||
title_el.textContent = title;
|
||||
}
|
||||
|
||||
|
||||
// ---- Modal logic ----
|
||||
const overlay = document.getElementById('modal-overlay');
|
||||
|
||||
function toggleModal() {
|
||||
if (overlay.style.display === 'none') {
|
||||
overlay.style.display = 'flex';
|
||||
} else {
|
||||
overlay.style.display = 'none';
|
||||
}
|
||||
}
|
||||
function hideModal() {
|
||||
overlay.style.display = 'none';
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'c' && e.ctrlKey) {
|
||||
const time = timerElement.textContent;
|
||||
navigator.clipboard.writeText(time);
|
||||
} else if (e.key === 'Enter' && !(document.activeElement === title_el)) {
|
||||
toggleTimer();
|
||||
} else if (e.key === 'Escape' && document.activeElement === title_el) {
|
||||
console.log('Escape');
|
||||
title_el.blur();
|
||||
} else if (e.key === 'Escape') {
|
||||
console.log('Escape');
|
||||
hideModal();
|
||||
} else if (e.code === 'Space' && !(document.activeElement === title_el)) {
|
||||
toggleTimer();
|
||||
|
||||
} else if (e.key === '?' && !title_el.isFocused) {
|
||||
toggleModal();
|
||||
} else if (e.key === '?') {
|
||||
} else if (e.keyCode === 191) {
|
||||
} else if (e.ctrlKey && e.key === 'a'){
|
||||
title_el.focus();
|
||||
} else if (e.ctrlKey){
|
||||
} else if (e.shiftKey){
|
||||
} else {
|
||||
title_el.focus();
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
timerElement.addEventListener('click', toggleTimer);
|
||||
|
||||
// on change of title update query params
|
||||
title_el.addEventListener('input', () => {
|
||||
const new_title = title_el.textContent;
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('title', new_title);
|
||||
window.history.replaceState({}, '', url);
|
||||
});
|
||||
|
||||
// Start timer on page load
|
||||
window.addEventListener('load', () => {
|
||||
startTime = performance.now();
|
||||
updateTimer();
|
||||
});
|
||||
|
||||
// Wake Lock support
|
||||
let wakeLock = null;
|
||||
async function requestWakeLock() {
|
||||
try {
|
||||
if ('wakeLock' in navigator) {
|
||||
wakeLock = await navigator.wakeLock.request('screen');
|
||||
console.log("Wake lock acquired");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Wake lock error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (wakeLock !== null && document.visibilityState === "visible") {
|
||||
requestWakeLock();
|
||||
}
|
||||
});
|
||||
|
||||
requestWakeLock();
|
||||
|
||||
|
||||
overlay.addEventListener('click', e => {
|
||||
if (e.target === overlay) hideModal();
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue