-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Description
freesound\static\bw-frontend\src\pages\sound.js's findTimeLinksAndAddEventListeners traces only the first two timecode elements in for example #00:01:12
Ideally it would handle hours as well.
This untested gen AI rewrite might work:
const findTimeLinksAndAddEventListeners = element => {
// Replace timestamps of pattern #m:ss, #h:m:s, etc. (e.g. #0:36, #0:0:1, #01:01:99) for anchor with a specific class and play icon
const playIconHtml = '<span class="bw-icon-play" style="font-size:70%"></span>';
element.innerHTML = element.innerHTML.replaceAll(/#\d+(?::\d+)+/g, '<a class="play-at-time" href="javascript:void(0);">' + playIconHtml + '$&</a>');
element.innerHTML = element.innerHTML.replaceAll(playIconHtml + '#', playIconHtml);
// Add listener events to each of the created anchors
Array.from(element.getElementsByClassName('play-at-time')).forEach(playAtTimeElement => {
playAtTimeElement.addEventListener('click', (e) => {
if (!e.altKey){
const parts = playAtTimeElement.innerText.split(':').map(n => parseInt(n, 10));
const seconds = parts.reverse().reduce((sum, val, idx) => sum + val * Math.pow(60, idx), 0);
playAtTime(audioElement, seconds);
} else {
audioElement.pause();
}
});
});
};Random test suite: https://freesound.org/people/freesoundtest111/sounds/811459/
Actual use case (at time of creating this ticket hh:mm:ss is used) https://freesound.org/people/HushAndHarmonyNow/sounds/842156/
Alternatively, tracing from the right might be a solution.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
