Skip to content

Make #00:00:01 timestamp links work with hours #2050

@qubodup

Description

@qubodup

freesound\static\bw-frontend\src\pages\sound.js's findTimeLinksAndAddEventListeners traces only the first two timecode elements in for example #00:01:12

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions