~hristoast/mousikofidi

0657520993763190b90637de28924092afb6689f — Hristos N. Triantafillou 7 months ago 5151603
Corrections from the language-server linter
2 files changed, 48 insertions(+), 70 deletions(-)

M mousikofidi/static/js/player.js
M mousikofidi/static/js/queue.js
M mousikofidi/static/js/player.js => mousikofidi/static/js/player.js +28 -46
@@ 84,10 84,10 @@ HTMLElement.prototype.addEventListener = function(eventType, func, capture) {
    // Move and X spans, and play arrows should be re-added.
    var dontSkip = (
        this.classList.contains("move-down")
            || this.classList.contains("move-up")
            || this.classList.contains("X")
            || this.classList.contains("play-arrow")
            || this.classList.contains("video-arrow")
        || this.classList.contains("move-up")
        || this.classList.contains("X")
        || this.classList.contains("play-arrow")
        || this.classList.contains("video-arrow")
    )

    if ((activeEvents.includes(eventData)) && (!dontSkip))


@@ 108,10 108,7 @@ function playAudio(targetArrow, dontPlay) {
        return false;
    }
    var serve = browse.replace("browse", "serve");
    var siteName = pageTitle.getAttribute("data-sitename");
    var thisTrackNum = targetArrow.getAttribute("data-num");
    var title = targetArrow.getAttribute("data-title");
    var playingTextTitle = "Now Playing: " + title + " | " + siteName;
    var shuffle = shuffleBtn.getAttribute("data-stat");
    var shuffleMobile = shuffleBtnMobile.getAttribute("data-stat");
    var mobileHidden = window.getComputedStyle(document.getElementsByClassName("mobile-hide")[0])["display"] === "none";


@@ 133,7 130,7 @@ function playAudio(targetArrow, dontPlay) {

    if ((followTrack) && (!dontPlay)) {
        var scrollTarget = document.getElementById(targetArrow.id + "-target");
        scrollTarget.scrollIntoView({block: "start", behavior: "smooth"});
        scrollTarget.scrollIntoView({ block: "start", behavior: "smooth" });
    }

    if ((shuffle === "on") || (shuffleMobile === "on")) {


@@ 167,7 164,7 @@ function playVideo(targetArrow, dontPlay) {
    videoNowPlayingNumDiv.setAttribute("data-nowplaying-num", thisTrackNum);

    if (!dontPlay)
        video.scrollIntoView({block: "start", behavior: "smooth"});
        video.scrollIntoView({ block: "start", behavior: "smooth" });

    if ((shuffle === "on") || (shuffleMobile === "on")) {
        setRandomOrder("video");


@@ 219,7 216,7 @@ function setRandomOrder(trackType) {

// TODO: Delete the unused '_playingTitleSpan' var and all usages of it.
function setStatusTexts(mediaType, nowPlayingP, _playingTitleSpan, actionText,
                        nowPlayingNum, trackTitle, totalTracks, siteName, titleElement) {
    nowPlayingNum, trackTitle, totalTracks, siteName, titleElement) {
    var arrows;

    if (mediaType === "audio") {


@@ 250,9 247,9 @@ function setStatusTexts(mediaType, nowPlayingP, _playingTitleSpan, actionText,
    var playingTitleSpan = nowPlayingP.childNodes[1];

    playingTitleSpan.onclick = function() {
            var scrollTarget = document.getElementById(arrows[nowPlayingNum].id + "-target");
            scrollTarget.scrollIntoView({block: "start", behavior: "smooth"});
        };
        var scrollTarget = document.getElementById(arrows[nowPlayingNum].id + "-target");
        scrollTarget.scrollIntoView({ block: "start", behavior: "smooth" });
    };
    playingTitleSpan.classList.toggle("bold");

    updateNowPlayingTitle(


@@ 325,8 322,6 @@ function endedTrackListener(_, trackType) {
                    setRandomOrder(trackType);

                } else {
                    var _play = playFn(arrows[nextTrack]);

                    if (repeatAll) {
                        // console.log("Shuffled playlist is empty and will be recalculated...");
                        setRandomOrder(trackType);


@@ 432,7 427,7 @@ function skipTrack(target, mediaType, doCmd) {
            var nextTrack = randOrderArray.shift();
            var nt = arrows[nextTrack]

            if (typeof(nt) === "undefined") {
            if (typeof (nt) === "undefined") {
                var newStartTrack = randInt(t.length);
                playFn(arrows[newStartTrack]);
                setRandomOrder(mediaType);


@@ 550,7 545,6 @@ function randomizeTrackOrder(totalCount, trackType) {
        var nowPlayingTrackNum = videoNowPlayingNumDiv.getAttribute("data-nowplaying-num");
    }

    var randCount = 0;
    var trackList = [];

    if (totalCount > 2) {


@@ 568,10 562,10 @@ function randomizeTrackOrder(totalCount, trackType) {
        // Shuffle just two
        var first = randInt(2);
        var second = ((first == 1) ? 0 : 1)
        return [ first, second ];
        return [first, second];

    } else {
        return [ 0 ];
        return [0];
    }

    return trackList;


@@ 728,13 722,7 @@ function giveLink(playerType) {
        _player = single;
    }

    var urlToGive = window.location.protocol
        + "//"
        + window.location.host
        // + "/"
        + window.location.pathname
        + "?t="
        + Math.floor(_player.currentTime);
    var urlToGive = `${window.location.protocol}//${window.location.host}${window.location.pathname}?t=${Math.floor(_player.currentTime)}`;

    if (playerType === "audio") {
        arrows = playArrows;


@@ 823,7 811,7 @@ function toggletheaterView(targetButton) {
    // only the water themes limit the body width enough to make this do anything.
    var setBody = (
        (document.getElementById("current-theme").getAttribute("data-theme") === "light")
            || (document.getElementById("current-theme").getAttribute("data-theme") === "dark")
        || (document.getElementById("current-theme").getAttribute("data-theme") === "dark")
    );
    var tvStat = targetButton.getAttribute("data-stat") === "on";



@@ 921,7 909,6 @@ function volumeCtl(mediaType, action, val, interv) {
        || document.getElementById("single");
    var curVol = element.volume;
    var newVol;
    var newVolH;
    var newVolM;
    var vol = loadVolume();
    var volMeter = document.getElementById(`${mediaType}-volume-meter`);


@@ 1009,8 996,8 @@ function FidiKeyBindsSetup() {
                    volumeCtl("video", "up", null, interval);
                }

            // Volume down
            } else if (keyName === "ArrowDown") {
                // Volume down
                e.preventDefault();
                if (playArrows.length > 0) {
                    volumeCtl("audio", "down", null, interval);


@@ 1028,8 1015,8 @@ function FidiKeyBindsSetup() {
                    video.currentTime += seekLen;
                }

            // Seek back
            } else if (keyName === "ArrowLeft") {
                // Seek back
                e.preventDefault();
                if (playArrows.length > 0) {
                    audio.currentTime -= seekLen;


@@ 1049,8 1036,8 @@ function FidiKeyBindsSetup() {
                volumeCtl("video", "up", 1);
            }

        // Volume down
        } else if (keyName === "ArrowDown") {
            // Volume down
            e.preventDefault();
            if (playArrows.length > 0) {
                volumeCtl("audio", "down", 1);


@@ 1068,8 1055,8 @@ function FidiKeyBindsSetup() {
                skipTrack(null, "video", "fwd");
            }

        // Previous track
        } else if (keyName === "ArrowLeft") {
            // Previous track
            e.preventDefault();
            if (playArrows.length > 0) {
                skipTrack(null, "audio", "prev");


@@ 1185,8 1172,8 @@ function FidiVideoPlayerSetup(videoElement, trackServeUrl, playingText) {
        videoRepeatBtnMobile.addEventListener("click", toggleRepeatListener);
        videoShuffleBtnMobile.addEventListener("click", toggleShuffleVideoListener);
        // Use mouseup instead of click to ensure only one event is caught..
        videoVolumePlusBtn.addEventListener("mouseup", function() { volumeCtl("video", "up"); } );
        videoVolumeMinusBtn.addEventListener("mouseup", function() { volumeCtl("video", "down"); } );
        videoVolumePlusBtn.addEventListener("mouseup", function() { volumeCtl("video", "up"); });
        videoVolumeMinusBtn.addEventListener("mouseup", function() { volumeCtl("video", "down"); });

        var volData = loadVolume();
        video.volume = volData["video"];


@@ 1202,12 1189,7 @@ function FidiPlayerSetUp() {
      MousikóFídi playlist player main entry point.
    */
    var currentTrack = 0;
    var nowPlayingTrackNum;
    var playingText;
    var siteName = pageTitle.getAttribute("data-sitename");

    if (nowPlayingNumDiv)
        nowPlayingTrackNum = nowPlayingNumDiv.getAttribute("data-nowplaying-num");

    if (playArrows.length > 0) {
        playingText = playArrows[0].getAttribute("data-title");


@@ 1231,8 1213,8 @@ function FidiPlayerSetUp() {

    } else if ((single) && (audioProgress)) {
        // Volume controls for track detail pages
        audioVolumePlusBtn.addEventListener("click", function() { volumeCtl("audio", "up"); } );
        audioVolumeMinusBtn.addEventListener("click", function() { volumeCtl("audio", "down"); } );
        audioVolumePlusBtn.addEventListener("click", function() { volumeCtl("audio", "up"); });
        audioVolumeMinusBtn.addEventListener("click", function() { volumeCtl("audio", "down"); });
        var volData = loadVolume();
        single.volume = volData["audio"];
        audioProgress.value = volData["audio"] * volMeterFactor;


@@ 1262,8 1244,8 @@ function FidiPlayerSetUp() {
        );
    } else if ((single) && (videoProgress)) {
        // Volume controls for track detail pages
        videoVolumePlusBtn.addEventListener("click", function() { volumeCtl("video", "up"); } );
        videoVolumeMinusBtn.addEventListener("click", function() { volumeCtl("video", "down"); } );
        videoVolumePlusBtn.addEventListener("click", function() { volumeCtl("video", "up"); });
        videoVolumeMinusBtn.addEventListener("click", function() { volumeCtl("video", "down"); });
        var volData = loadVolume();
        single.volume = volData["video"];
        videoProgress.value = volData["video"] * volMeterFactor;


@@ 1282,7 1264,7 @@ function FidiPlayerSetUp() {
        videoLinkButton.addEventListener("click", videoLinkListener);

    if (params.has("goto"))
        document.getElementById(params.get("goto")).scrollIntoView({behavior: "smooth"});
        document.getElementById(params.get("goto")).scrollIntoView({ behavior: "smooth" });

    if (params.has("t"))
        seekTrack();


@@ 1301,10 1283,10 @@ function FidiPlayerSetUp() {
        }

        downArrow.addEventListener("click", function() {
            window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth'});
            window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
        });
        upArrow.addEventListener("click", function() {
            window.scrollTo({top: 0, behavior: 'smooth'});
            window.scrollTo({ top: 0, behavior: 'smooth' });
        });

        FidiScrollListener();

M mousikofidi/static/js/queue.js => mousikofidi/static/js/queue.js +20 -24
@@ 137,13 137,13 @@ async function cancelTokens(tExclude) {
        t = tokens[i];
        if (tExclude) {
            if (t.id !== tExclude.id)
                await cancelToken(t);
                cancelToken(t);
        } else {
            await cancelToken(t);
            cancelToken(t);
        }
    }
    await clearChildren(queueTableBody);
    await clearChildren(queueTableBodyVideo);
    clearChildren(queueTableBody);
    clearChildren(queueTableBodyVideo);
}

function getTokens() {


@@ 246,8 246,8 @@ function getFileType(path) {
        || (path.toLowerCase().endsWith(".flac"))) {
        return idAudio;
    } else if ((path.toLowerCase().endsWith(".mkv"))
               || (path.toLowerCase().endsWith(".mp4"))
               || (path.toLowerCase().endsWith(".webm"))) {
        || (path.toLowerCase().endsWith(".mp4"))
        || (path.toLowerCase().endsWith(".webm"))) {
        return idVideo;
    }
    return "unknown";


@@ 693,7 693,7 @@ function renderQueueRow(tableBody, count, data, clickListener, arrowClass, title
    var tracktotal = data.tracktotal;
    if (((track) && (tracktotal)) || ((track) && (tracktotal) && (tracktotal !== 0))) {
        rowTdTrack.textContent = `${track}/${tracktotal}`;
    } else if ((track) && (tracktotal) && (tracktotal === 0)){
    } else if ((track) && (tracktotal) && (tracktotal === 0)) {
        rowTdTrack.textContent = track;
    }



@@ 808,12 808,9 @@ function renderQueueRow(tableBody, count, data, clickListener, arrowClass, title
        return;

    // Load the player as needed
    var audioPlayerDiv = document.getElementById(idAudioPlayerDiv);
    var videoPlayerDiv = document.getElementById(idVideoPlayerDiv);
    if ((data.trackType === idAudio) && (count === 0)) {
        if (audio.getAttribute("data-action") !== "Now Playing:") {
            var playArrows = document.getElementsByClassName(playArrowClass);

            // FidiAudioPlayerSetup()
            // from player.js
            FidiAudioPlayerSetup(audioElement, count, getUrl(data.path, typeServe), data.title);


@@ 1044,12 1041,12 @@ async function renderQueue(token, audioQueue, audioCount, videoQueue, videoCount
    if ((goHereID) && (audioFollowCheckbox.checked === true)
        // Don't do this for video tracks
        && (!queueTableBodyVideo.contains(document.getElementById(goHereID))))
        document.getElementById(goHereID).scrollIntoView({behavior: "smooth"});
        document.getElementById(goHereID).scrollIntoView({ behavior: "smooth" });
}

function saveQueueToFile() {
    var forceSave = forceSaveInput.checked;
    var saved  = JSON.parse(savedPlaylists.getAttribute("playlists"));
    var saved = JSON.parse(savedPlaylists.getAttribute("playlists"));
    var name = saveQueueInput.value || null;

    if (!forceSave) {


@@ 1079,9 1076,9 @@ function saveQueueToFile() {
            // Special case
            document.getElementById(replaceCurrentId).style.display = "inline";

        // } else {
        //     // Show the user an error
        //     console.log(httpError);
            // } else {
            //     // Show the user an error
            //     console.log(httpError);
        }
    };



@@ 1090,7 1087,7 @@ function saveQueueToFile() {
    //     console.log(networkError);
    // };

    request.send(JSON.stringify({"name": name, "queue": loadQueue()}));
    request.send(JSON.stringify({ "name": name, "queue": loadQueue() }));
}

function loadQueueFromFile(dropDown) {


@@ 1111,7 1108,6 @@ function loadQueueFromFile(dropDown) {
        request.open("GET", url);
        request.onload = function() {
            if (request.status >= 200 && request.status < 400) {
                var oldQueue = loadQueue();
                var queue;
                var queueData = JSON.parse(request.response);
                var loadErrors = queueData["error"];


@@ 1167,7 1163,7 @@ function loadQueueFromFile(dropDown) {
                clearChildren(queueTableBodyVideo);

                doNotify(`The playlist "${playlistName}" ${words} the queue.`,
                         "green", "white", loadPlaylistFadeDelay);
                    "green", "white", loadPlaylistFadeDelay);

                queue = loadQueue();
                showQueue(queue);


@@ 1213,9 1209,9 @@ function loadQueueFromFile(dropDown) {
                    hideThis(videoPlayer);
                }

            // } else {
            //     // Show the user an error
            //     console.log(httpError);
                // } else {
                //     // Show the user an error
                //     console.log(httpError);
            }
        };



@@ 1378,11 1374,11 @@ function FidiQueueSetup() {
            var aa = document.getElementsByClassName(playArrowClass);
            var va = document.getElementsByClassName(videoArrowClass);

            for (i = 0; i < aa.length; i ++) {
            for (i = 0; i < aa.length; i++) {
                b = b.concat(aa[i]);
            }

            for (i = 0; i < va.length; i ++) {
            for (i = 0; i < va.length; i++) {
                b = b.concat(va[i]);
            }



@@ 1413,7 1409,7 @@ function FidiQueueSetup() {
        if (saveQueueBtn) {
            saveQueueBtn.addEventListener("click", saveQueueToFile);
            saveNameInput.addEventListener("keydown", function(event) {
                if (event.keyCode === 13)
                if (event.key === "Enter")
                    saveQueueToFile();
            });
        }