<commit_before>// <NAME>
// September 2013
// depends on jquery

// setup the controls

$(document).on('ready', function() {

    var interval = null;
    var setup = function() {
        // setup after loading bar exists and now playing gets made

        if ($('#loading-progress').css('display') === 'none' && $('.now-playing-menu').length !== 0) {

            // inject custom menu item into DOM

            $('.now-playing-menu').append('<div class="goog-menuseparator" style="-webkit-user-select: none;" role="separator" id=":6" aria-hidden="false"></div> <div class="goog-menuitem" role="menuitem" style="-webkit-user-select: none;" id="stop-after-track"><div class="goog-menuitem-content" style="-webkit-user-select: none;">Stop after this track</div></div>');

            // set up hover states for menu item

            var cssClass = 'goog-menuitem-highlight';
            $('#stop-after-track').hover(
                function() {$(this).addClass(cssClass);},
                function() {$(this).removeClass(cssClass);}
            );
            $('#stop-after-track').on('click', toggleStopAfterTrack);

            clearInterval(interval);
        }
    };
    interval = setInterval(setup, 800);


    // state variables
    var shouldStop = false;
    var stopAfterTrack = null;


    // main functions
    var enableStop = function() {
        var $stopAfterTrack = $('#stop-after-track');
        var $subdiv = $stopAfterTrack.find('div');
        shouldStop = true;
        stopAfterTrack = getCurrentTrack();
        // add checkmark
        $subdiv.prepend('&#10003; ');

        // start checking for if we should pause the track
        document.getElementsByTagName("audio")[0].parentNode.addEventListener("ended", trackDone, true);
        interval = setInterval(checkChangedTrack, 500);
    };
    var disableStop = function() {
        var $stopAfterTrack = $('#stop-after-track');
        var $subdiv = $stopAfterTrack.find('div');
        shouldStop = false;
        stopAfterTrack = null;
        $subdiv.text('Stop after this track');
        document.getElementsByTagName("audio")[0].parentNode.removeEventListener("ended", trackDone, true);
        clearInterval(interval);
    };
    var toggleStopAfterTrack = function(evt) {
        if (shouldStop) {
            disableStop();
        } else {
            enableStop();
        }
    };


    // helper functions
    var getCurrentTrack = function() {
        return $('#playerSongInfo').text();
    };
    var trackDone = function () {
        // pause html 5 player
        this.firstChild.pause();
        event.stopImmediatePropagation();
        // sync UI with player state
        $('[data-id="play-pause"]').click();
        disableStop();
    };
    var checkChangedTrack = function() {
        if (getCurrentTrack() != stopAfterTrack) {
            disableStop();
        }
    };
});<commit_msg>comments<commit_after>// <NAME>
// September 2013
// depends on jquery

// setup the controls

$(document).on('ready', function() {

    var interval = null;
    var setup = function() {
        // setup after loading bar exists and now playing gets made

        if ($('#loading-progress').css('display') === 'none' && $('.now-playing-menu').length !== 0) {

            // inject custom menu item into DOM

            $('.now-playing-menu').append('<div class="goog-menuseparator" style="-webkit-user-select: none;" role="separator" id=":6" aria-hidden="false"></div> <div class="goog-menuitem" role="menuitem" style="-webkit-user-select: none;" id="stop-after-track"><div class="goog-menuitem-content" style="-webkit-user-select: none;">Stop after this track</div></div>');

            // set up hover states for menu item

            var cssClass = 'goog-menuitem-highlight';
            $('#stop-after-track').hover(
                function() {$(this).addClass(cssClass);},
                function() {$(this).removeClass(cssClass);}
            );
            $('#stop-after-track').on('click', toggleStopAfterTrack);

            clearInterval(interval);
        }
    };
    interval = setInterval(setup, 800);


    // state variables
    var shouldStop = false;
    var stopAfterTrack = null;


    // main functions
    var enableStop = function() {
        var $stopAfterTrack = $('#stop-after-track');
        var $subdiv = $stopAfterTrack.find('div');
        shouldStop = true;
        stopAfterTrack = getCurrentTrack();
        // add checkmark
        $subdiv.prepend('&#10003; ');

        // when audio ends, intercept and prevent event
        document.getElementsByTagName("audio")[0].parentNode.addEventListener("ended", trackDone, true);
        interval = setInterval(checkChangedTrack, 500);
    };
    var disableStop = function() {
        var $stopAfterTrack = $('#stop-after-track');
        var $subdiv = $stopAfterTrack.find('div');
        shouldStop = false;
        stopAfterTrack = null;
        $subdiv.text('Stop after this track');
        document.getElementsByTagName("audio")[0].parentNode.removeEventListener("ended", trackDone, true);
        clearInterval(interval);
    };
    var toggleStopAfterTrack = function(evt) {
        if (shouldStop) {
            disableStop();
        } else {
            enableStop();
        }
    };


    // helper functions
    var getCurrentTrack = function() {
        return $('#playerSongInfo').text();
    };
    var trackDone = function () {
        // pause html 5 player
        this.firstChild.pause();
        event.stopImmediatePropagation();
        // sync UI with audio player state
        $('[data-id="play-pause"]').click();
        disableStop();
    };
    var checkChangedTrack = function() {
        if (getCurrentTrack() != stopAfterTrack) {
            disableStop();
        }
    };
});
{'fraction_non_alphanumeric': 0.15447014152571625, 'fraction_numerical': 0.0069036934760096655, 'mean_word_length': 2.433056872037915, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7470120', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1548, 'n_words': 357}