Populate History Page with Video Interaction Data
Context
Date: 2025-05-28
Feature: Populate the empty history page/view with video interaction data
User Request
The newly-created history "page" (or view or tab) is currently empty. Populate it with history (see background.js for details), ordered, with the most recently interacted video at the top. For each video, put the title, the "v" param (id) in parentheses, and the list of events. Put human-readable timestamps.
Analysis
From examining the codebase:
History Data Structure (from background.js):
- History is stored in browser.storage.local with key "history"
- Each video is keyed by video ID (the "v" parameter from YouTube URL)
- Each video entry contains:
url: Original video URL
title: Video title
duration: Video duration
history: Array of interaction events
- Each event contains:
action: Type of event ("play", "playing", "pause", "ended")
position: Timestamp in video where event occurred
timestamp: Unix timestamp when event was recorded
Existing UI Structure:
- History view framework already exists in popup.html
- Navigation between playlists and history views implemented
- CSS container for history already present but empty
Implementation
1. Added History Data Management (popup.js)
- Added
history and sortedHistory properties to Alpine.js data
- Created
loadHistory() method to fetch data from browser storage
- Created
sortHistoryByRecentInteraction() to sort videos by most recent interaction
- Added utility methods:
formatTimestamp(): Human-readable relative timestamps ("2 hours ago", etc.)
formatVideoPosition(): Convert seconds to MM:SS format
formatActionName(): Convert action types to human-readable names
2. Updated HTML Structure (popup.html)
- Populated empty history container with Alpine.js template
- Added structured display for each video:
- Video title (clickable link)
- Video ID in parentheses
- List of events with action, position, and timestamp
- Added empty state message
3. Added CSS Styles (popup.css)
- Comprehensive styling for history items
- Event display with proper spacing and typography
- Hover effects and visual hierarchy
- Responsive layout considerations
4. Enhanced Navigation
- Updated
showHistory() method to refresh data when switching views
- Maintained existing navigation between playlists and history
Key Features Implemented
- Chronological Ordering: Videos sorted by most recent interaction
- Comprehensive Event Display: Each event shows action type, video position, and human-readable timestamp
- Interactive Elements: Video titles are clickable links that open in new tabs
- Clean UI: Well-structured layout with proper visual hierarchy
- Empty State Handling: Friendly message when no history exists
Files Modified
popup/popup.js: Added history data management and formatting methods
popup/popup.html: Populated history container with structured content
popup/popup.css: Added comprehensive styling for history display
Testing Considerations
- Verify history loads correctly from browser storage
- Test sorting by most recent interaction
- Confirm human-readable timestamps display properly
- Validate video links open correctly
- Check empty state display when no history exists