Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Building a Drift-Free, Zero-Dependency Cue Timer in a Single HTML File

Most browser timers are way heavier than they need to be—wrapped in ad scripts, cookie banners, and frameworks just to count down five minutes. When I need a clean timer for rehearsal pacing, sprint blocks, or quick work intervals, I want something dark-mode, keyboard-first, and completely offline-capable. So I put together Cue Timer in a single index.html page with zero dependencies and zero…

Creating a precise, dependency-free timer for tasks like rehearsal pacing can be challenging due to the complex nature of browser timers. These timers often come bundled with unnecessary elements such as ad scripts, cookie banners, and frameworks, making them far heavier than required. When a user needs a clean, offline-capable timer for activities like work intervals or sprint blocks, a lightweight solution is desired.

Cue Timer addresses these needs through a single HTML file, ensuring zero external dependencies and audio assets.

One key challenge in timer creation is avoiding the common issue of setInterval drift. This occurs when a timer, set to decrement at one-second intervals using setInterval(..., 1000), experiences throttling in background tabs, potentially leading to a drift of several seconds in a 15-minute timer. Instead of relying on interval ticks, Cue Timer records a target timestamp upon starting the timer using performance.now().

This timestamp is utilized to calculate the delta time on each requestAnimationFrame, ensuring the timer remains incredibly accurate even if the browser tab is backgrounded.

Another innovative aspect of Cue Timer is its procedural chimes, achieved through the Web Audio API. This eliminates the need for external .mp3 or .wav files, aligning with the single-file requirement. By leveraging the AudioContext, the timer can synthesize a clean two-tone sine chime with only 15 lines of code. The implementation uses an exponential attack and release to avoid the harsh digital "click" that can occur when cutting an oscillator off abruptly, resulting in a smooth and pleasant sound effect.

Cue Timer also prioritizes user experience by incorporating keyboard-first controls. This means that all functions are accessible via keyboard shortcuts, making the timer usable without a mouse. For instance, pressing the Spacebar toggles between starting and pausing the timer, R resets the preset to its current value, and numeric keys allow the user to jump directly to preset times of 5, 15, or 25 minutes.

These features make Cue Timer an efficient and user-friendly tool for anyone needing a reliable timer without relying on external resources.

For those interested in the full implementation, the complete source code is available on GitHub at github.com/donovanlafferty/cue-timer. Donovan Lafferty, the developer behind Cue Timer, is an Orlando-based developer and entertainment operations specialist. His work extends beyond this timer, including audio experiments on SoundCloud and project demos on YouTube.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

WebMCP: Eight Tools That Registered Nothing for Ninety Days

Eight tools. That is how many WebMCP tools the team at ModelPiper shipped in late April. For three months, every one of them registered nothing. Not for some visitors.

  • Eight WebMCP tools shipped by ModelPiper in late April
  • Tools did not register anything for ninety days despite normal site function
  • WebMCP API faces challenges due to browsing context requirement and perceived redundancy

Metered Billing Evidence: Usage Snapshots Explained for Logistics Access Reviews

Metered billing design Where to store usage snapshots Evidence the reviewer must receive Shared database, separate permissions Store them beside accepted usage when one team can enforce the collection…

  • Usage snapshots stored alongside accepted usage with separate permissions
  • Define billable unit as one completed shipment-status report
  • Implement metered billing using shared database with separate permissions

How Content Filtering Works in Streaming Apps

Content filtering in streaming apps is a layered pipeline. It decides what shows up for each user based on age ratings, content tags, and viewing history. Not a single block-or-allow decision.

More from Wednesday 25 November →