<commit_before>$(function() {
        $("video").each(function() {
                if (lang=window.location.search.substring(1)) {
                        var ret=true;
                        $("select option").each(function() {
                                if ($(this).attr("val") == lang) { $(this).attr("selected",true); ret=false; }
                        });
                        if (!ret) {
                                $("subtitle").each(function() {
                                        var sub = $(this);
                                        google.language.translate($(this).html(),"en",lang, function(r) { 
                                               sub.html(r.translation);
                                        });
                                });
                        }
                }

                $("#language").change(function() { window.location="?" + $("#language option:selected").attr("val"); });
        });	
});

var lt = 0;
function update(vid) {
        var has_sub=false,
        t = vid.currentTime; 
        if (lt>t) $("#sub span").fadeTo(1,.3);
        $("subtitle").each(function() {
                var from = to_secs($(this).attr("from")),
                to = to_secs($(this).attr("to"));
                $(this).removeClass("good");
                if (from<t&&to>t) { 
                        has_sub=true; 
                        $(this).addClass("good");
                }
        });
        if (!has_sub) { 
               if (!$("#sub").hasClass("fading"))
                    $("#sub").addClass("fading").stop().animate({ opacity:0, top:"-=30px" }, "medium", "swing");
        } else {
               if ($("#sub").hasClass("fading"))
                    $("#sub").removeClass("fading").stop().animate({opacity:1,top:"410px"},1).html('');       
        }
        $("subtitle.good:last").each(function() { 
                if (!$(this).hasClass("on")) {
                       $("subtitle.on").removeClass("on");
                       $(this).addClass("on");
                       $("#sub").html('').hide();
                       var letters = $(this).text().split('');
                       $.each(letters,function(i, val) {
                                $("#sub").append('<span>' + val + '</span>');
                       });
                       $("#sub span").stop().fadeTo(1,.3, function() { $(this).show(); });
                }
                var from = to_secs($(this).attr("from")),
                to = to_secs($(this).attr("to")),
                perc = ((t-from)/(to-from)),
                num_letters = $(this).text().length*perc,
                i = 0;
                $("#sub span").each(function() { 
                        if (i++>num_letters) return;
                        $(this).stop().fadeTo("fast",1);
                }).parent().show();
        });
        lt = t;
}

function to_secs(time) {
	var t = time.split(":");<commit_msg>added comments to video.js to explain functions<commit_after>// fire when DOM is ready, jQuery shortcut for $(document).ready
$(function() {
        $("video").each(function() {
                if (lang=window.location.search.substring(1)) {
                        var ret=true;
                        $("select option").each(function() {
                                if ($(this).attr("val") == lang) { $(this).attr("selected",true); ret=false; }
                        });
                        if (!ret) {
                                $("subtitle").each(function() {
                                        var sub = $(this);
                                        google.language.translate($(this).html(),"en",lang, function(r) { 
                                               sub.html(r.translation);
                                        });
                                });
                        }
                }

                $("#language").change(function() { window.location="?" + $("#language option:selected").attr("val"); });
        });	
});

var lt = 0;
// fires when ontimeupdate() runs from <video> tag
function update(vid) {
        var has_sub=false,
        t = vid.currentTime; 
        if (lt>t) $("#sub span").fadeTo(1,.3);
        $("subtitle").each(function() {
                var from = to_secs($(this).attr("from")),
                to = to_secs($(this).attr("to"));
                $(this).removeClass("good");
                if (from<t&&to>t) { 
                        has_sub=true; 
                        $(this).addClass("good");
                }
        });
        if (!has_sub) { 
               if (!$("#sub").hasClass("fading"))
                    $("#sub").addClass("fading").stop().animate({ opacity:0, top:"-=30px" }, "medium", "swing");
        } else {
               if ($("#sub").hasClass("fading"))
                    $("#sub").removeClass("fading").stop().animate({opacity:1,top:"410px"},1).html('');       
        }
        $("subtitle.good:last").each(function() { 
                if (!$(this).hasClass("on")) {
                       $("subtitle.on").removeClass("on");
                       $(this).addClass("on");
                       $("#sub").html('').hide();
                       var letters = $(this).text().split('');
                       $.each(letters,function(i, val) {
                                $("#sub").append('<span>' + val + '</span>');
                       });
                       $("#sub span").stop().fadeTo(1,.3, function() { $(this).show(); });
                }
                var from = to_secs($(this).attr("from")),
                to = to_secs($(this).attr("to")),
                perc = ((t-from)/(to-from)),
                num_letters = $(this).text().length*perc,
                i = 0;
                $("#sub span").each(function() { 
                        if (i++>num_letters) return;
                        $(this).stop().fadeTo("fast",1);
                }).parent().show();
        });
        lt = t;
}

// convert time format mm:ss to seconds integer
function to_secs(time) {
	var t = time.split(":");
{'fraction_non_alphanumeric': 0.1933311432325887, 'fraction_numerical': 0.005256241787122208, 'mean_word_length': 1.2021699819168175, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5656552', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1518, 'n_words': 241}