From 9b7c097f2ec6a259536ab67aed51e6315b07349c Mon Sep 17 00:00:00 2001 From: Ashley //// Date: Thu, 11 Apr 2024 08:14:43 +0000 Subject: [PATCH] add jump to time v2 --- css/app.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/css/app.js b/css/app.js index bf53ec1..17a0123 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