JavaScript App
JavaScript App: Client-Side Implementation
Overview
The JavaScript implementation is a pure client-side application requiring zero installation or server infrastructure. It runs entirely in the browser using vanilla JavaScript, HTML, and CSS.
Architecture
Core Components
Technology Stack
- Pure HTML/CSS/JavaScript - No frameworks or build tools
- LocalStorage API - Persistent data storage
- Fetch API - CoinGecko API integration
- Web Audio API - Alarm sound playback
- setInterval - Polling mechanism (15-second updates)
Data Persistence: LocalStorage
All application state is stored in the browser’s LocalStorage under a single key:
Storage Schema
LocalStorage Benefits
- Zero Configuration: Works immediately, no setup
- Privacy: Data never leaves the browser
- Portability: Copy HTML files to any device
- Offline Access: View historical data without internet
LocalStorage Limitations
- Storage Quota: Typically 5-10MB per origin
- Browser-Specific: Data doesn’t sync across browsers/devices
- Clearing Risk: Browser cache clear = data loss
- Single-User: No multi-user support
Price Update Mechanism
Polling Loop
CoinGecko API Integration
The app uses CoinGecko’s free public API (no authentication required):
For Stablecoin Pairs (quote = USDT/USDC/USD/BUSD/DAI):
For Crypto Pairs (quote = BTC/ETH/BNB):
Price History Management
- Retention: 24 hours of price data
- Granularity: One data point per 15-second interval (5,760 points/day)
- Cleanup: Automatic removal of data older than 24 hours
- Purpose: Powers timeframe alarms (e.g., “5% in 2 hours”)
Alarm Sound System
Web Audio API Implementation
Browser Audio Context Limitations
CRITICAL: Keep Tab Visible for Reliable Alarms
Browser audio contexts are suspended for inactive tabs to save resources.
For the most reliable alarm sound:
- ✅ Keep the browser tab VISIBLE or use a separate window
- ✅ Avoid minimizing or switching tabs for extended periods
- ✅ Browser audio can be suspended after 5-10 minutes of inactivity
Why this happens: Browsers like Chrome, Firefox, and Edge automatically suspend background audio contexts to reduce CPU usage and battery drain. This is a browser security/performance feature, not a bug.
Backup: Even if audio fails, the page title will flash “🚨 ALARM TRIGGERED! 🚨” as a visual indicator.
Test Your Alarm Sound
Before relying on alarms, verify audio works:
- Click the “🔔 Test Alarm” button in the UI
- You should hear a continuous alarm sound
- Ensure your system volume is adequate (alarm plays at 60%)
- Check that your browser allows audio playback from the site
If you don’t hear sound, check:
- Browser permissions (may need to click page first for autoplay)
- System volume and mute settings
- Browser console (F12) for audio errors
Visual Fallback Implementation:
User Interface
HTML Structure
- Minimal Dependencies: No UI frameworks
- Inline CSS: All styles in
<style>block - Responsive Design: Mobile-friendly layout
- Accessibility: Semantic HTML, clear labels
Key UI Components
Pair Management Panel
- Add new pairs input
- Active pairs list
- Remove pair button
- Alarm count badge
Alarm Configuration Modal
- Three alarm type tabs
- Dynamic form inputs
- Alarm list display
- Back to assets button
Alarm Trigger Modal
- Alarm details
- Dismiss button
- Sound playing indicator
Deployment
Option 1: Local File System
Option 2: Simple HTTP Server
Option 3: Static Hosting
Upload javascript-app/ folder to:
- GitHub Pages
- Netlify
- Vercel
- Any static file host
Advantages
- Zero Friction: Double-click HTML file to run
- No Dependencies: Works offline after first load
- Privacy: Data stored locally only
- Portability: Copy folder to any device
- Simplicity: ~500 lines of readable code
Limitations
- Single User: No multi-user support
- Tab Must Stay Open: Browser must remain running
- No Server-Side Logic: Can’t run headless
- Storage Quota: LocalStorage size limits
- Browser Dependency: Requires modern browser
Use Cases
Ideal For:
- Personal crypto monitoring
- Quick setup without infrastructure
- Learning/education purposes
- Portable USB deployment
- Privacy-conscious users
Not Ideal For:
- Team/shared monitoring
- Server-side automation
- Headless operation
- Large-scale deployments
Performance Considerations
Memory Management
- Price history capped at 24 hours
- Automatic cleanup on each update
- Typical memory usage: < 10MB
Network Usage
- API call every 15 seconds per pair
- ~2KB per API response
- Daily usage: ~11.5MB per pair
Browser Compatibility
- Chrome/Edge: ✅ Full support
- Firefox: ✅ Full support
- Safari: ✅ Full support (audio may require interaction)
- Mobile browsers: ✅ Works but keep screen on
Debugging
Common Issues
Alarms not triggering:
LocalStorage data corruption:
Audio not playing:
Next Steps
- Explore Alarm Logic for detailed alarm type documentation
- See API Integration for CoinGecko implementation details
- Compare with Python App for server-side alternative