feat: make transcript timestamps clickable to seek player

This commit is contained in:
Paul Gauthier (aider) 2025-03-14 08:53:07 -07:00
parent 41219a7d85
commit feda315c2b
2 changed files with 38 additions and 2 deletions

View file

@ -87,6 +87,18 @@
margin-bottom: 20px;
position: relative;
}
/* Timestamp link styling */
.timestamp-link {
color: #0366d6;
text-decoration: none;
font-weight: bold;
cursor: pointer;
}
.timestamp-link:hover {
text-decoration: underline;
}
.asciinema-player-theme-aider {
/* Foreground (default text) color */
--term-color-foreground: #444444; /* colour238 */

View file

@ -1,5 +1,7 @@
document.addEventListener('DOMContentLoaded', function() {
// Parse the transcript section to create markers
let player; // Store player reference to make it accessible to click handlers
// Parse the transcript section to create markers and convert timestamps to links
function parseTranscript() {
const markers = [];
// Find the Transcript heading
@ -20,8 +22,30 @@ document.addEventListener('DOMContentLoaded', function() {
const minutes = parseInt(match[1], 10);
const seconds = parseInt(match[2], 10);
const timeInSeconds = minutes * 60 + seconds;
const formattedTime = `${minutes}:${seconds.toString().padStart(2, '0')}`;
const message = match[3].trim();
// Create link for the timestamp
const timeLink = document.createElement('a');
timeLink.href = '#';
timeLink.textContent = formattedTime;
timeLink.className = 'timestamp-link';
timeLink.dataset.time = timeInSeconds;
// Add click event to seek the player
timeLink.addEventListener('click', function(e) {
e.preventDefault();
if (player && typeof player.seek === 'function') {
player.seek(timeInSeconds);
player.play();
}
});
// Replace text with the link + message
item.textContent = '';
item.appendChild(timeLink);
item.appendChild(document.createTextNode(' ' + message));
markers.push([timeInSeconds, message]);
}
});
@ -39,7 +63,7 @@ document.addEventListener('DOMContentLoaded', function() {
const markers = parseTranscript();
// Create player with a single call
const player = AsciinemaPlayer.create(
player = AsciinemaPlayer.create(
url,
document.getElementById('demo'),
{