diff --git a/css/app.js b/css/app.js index bf53ec15..17a0123f 100644 --- a/css/app.js +++ b/css/app.js @@ -132,6 +132,31 @@ timeLinks.forEach(link => { } }); +const videoPlayer = document.getElementById('video'); + +function time(seconds) { + videoPlayer.currentTime = seconds; +} + + document.addEventListener('click', function(event) { + const clickedElement = event.target; + + if (clickedElement.classList.contains('comment')) { + const commentText = clickedElement.textContent.trim(); + + const timestampMatch = commentText.match(/(\d{1,2}:\d{2})/); + + if (timestampMatch) { + const timestamp = timestampMatch[0]; + let parts = timestamp.split(':'); + let seconds = (+parts[0]) * 60 + (+parts[1]); + + time(seconds); + } + } +}); + + // Save and resume video progress