<commit_before>function getParameterByName(url, name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(url);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var head = "http://www.youtube.com/embed/";
var tail = "?enablejsapi=1&origin=shakeelmohamed.com&autoplay=1";

$(function() {
    $("#form").submit(function(event) {
        event.preventDefault();
        var formValue = $("#query").val();
        if (formValue) {
            var shortUrlDomain = "youtu.be";
            var url = head;
            
            // YouTube video URL string, parse the v parameter
            if (formValue.indexOf("youtube.com") !== -1) {
                 url += getParameterByName(formValue, "v");
            }
            else if (formValue.indexOf(shortUrlDomain) !== -1) {
                var endPosition = formValue.indexOf("?") === -1 ? formValue.length : formValue.indexOf("?");
                var offset = formValue.indexOf(shortUrlDomain) + shortUrlDomain.length + 1; // Skip over the slash also
                url += formValue.substring(offset, endPosition);
            }
            else {
                // YouTube video ID string
                url += formValue;
            }
            
            $("#player").attr("src", url + tail);
        }
        else {
            alert("Try entering a YouTube video id or URL!");
        }
    });
});

// Google Analytics goodness
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36907845-2', 'shakeelmohamed.com');
ga('require', 'displayfeatures');
ga('send', 'pageview');<commit_msg>Handle v= querystring URL parameters. Closes #3<commit_after>function getParameterByName(url, name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(url);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var head = "http://www.youtube.com/embed/";
var tail = "?enablejsapi=1&origin=shakeelmohamed.com&autoplay=1";

function getCurrentVideoID() {
    return getParameterByName(window.location.search, "v");
}

$(function() {

    if (getCurrentVideoID()) {
        $("#player").attr("src", head + getCurrentVideoID() + tail);
        $("#query").attr("value", getCurrentVideoID());
    }

    $("#form").submit(function(event) {
        event.preventDefault();
        var formValue = $("#query").val();
        if (formValue) {
            var shortUrlDomain = "youtu.be";
            var videoID = null;
            
            // YouTube video URL string, parse the v parameter
            if (formValue.indexOf("youtube.com") !== -1) {
                 videoID = getParameterByName(formValue, "v");
            }
            else if (formValue.indexOf(shortUrlDomain) !== -1) {
                var endPosition = formValue.indexOf("?") === -1 ? formValue.length : formValue.indexOf("?");
                var offset = formValue.indexOf(shortUrlDomain) + shortUrlDomain.length + 1; // Skip over the slash also
                videoID = formValue.substring(offset, endPosition);
            }
            else {
                // YouTube video ID string
                videoID = formValue;
            }
            if (videoID) {
                // $("#player").attr("src", head + videoID + tail);
                // Do redirect
                var url = window.location.href;
                if (window.location.search.length !== 0) {
                    url = window.location.href.replace(window.location.search, "");
                }
                window.location.href = url + "?v=" + videoID;

            }
            else {
                alert("Wow you found a weird bug, please report it on GitHub!");
            }
        }
        else {
            alert("Try entering a YouTube video id or URL!");
        }
    });
});

// Google Analytics goodness
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36907845-2', 'shakeelmohamed.com');
ga('require', 'displayfeatures');
ga('send', 'pageview');
{'fraction_non_alphanumeric': 0.18938428874734609, 'fraction_numerical': 0.008492569002123142, 'mean_word_length': 2.3530249110320285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6463290', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1429, 'n_words': 263}