<commit_before>$(document).ready(function(){


    $('#t_inc').tagsInput({'defaultText': '…'});
    $('#t_exc').tagsInput({'defaultText': '…'});
    $('#l_inc').tagsInput({'defaultText': '…'});
    $('#l_exc').tagsInput({'defaultText': '…'});

    set_submit(false)
    $('#rss_url').blur(check_url)
    check_url()

})

set_feedback = function (value) {
    feedback = $('#url_feedback')
    fieldset = $('#rss_url_fieldset')
    if ( value ) {
        fieldset.addClass('has-success').removeClass('has-error')
        feedback.show().addClass('glyphicon-ok').removeClass('glyphicon-remove')
        set_submit(true)
    } else {
        fieldset.addClass('has-error').removeClass('has-success')
        feedback.show().addClass('glyphicon-remove').removeClass('glyphicon-ok')
        set_submit(false)

    }

}

set_submit = function (value) {
    btn = $('#submit_btn')
    if ( value ) {
        btn.removeAttr('disabled')
    } else {
        btn.attr('disabled', 'disabled')
    }
}

check_url = function () {
    url = $('#rss_url').val()
    $.get( "/check_url?&url=" + escape(url), function( data ) {
        if (data == 'False') {
            set_feedback(false)
        } else {
            set_feedback(true)
            if (data != 'True') {
                $('#rss_url').val(data)
            }
        }
    });
}<commit_msg>Implement URL check via JS<commit_after>$(document).ready(function(){

    $('#t_inc').tagsInput({'defaultText': '…'});
    $('#t_exc').tagsInput({'defaultText': '…'});
    $('#l_inc').tagsInput({'defaultText': '…'});
    $('#l_exc').tagsInput({'defaultText': '…'});

    set_submit(false);
    $('#rss_url').blur(check_url);
    if ($('#rss_url').val() != '') {
        check_url();
    }

})

set_feedback = function (value) {
    feedback = $('#url_feedback');
    fieldset = $('#rss_url_fieldset');
    if ( value ) {
        fieldset.addClass('has-success').removeClass('has-error');
        feedback.show().addClass('glyphicon-ok').removeClass('glyphicon-remove');
        set_submit(true);
    } else {
        fieldset.addClass('has-error').removeClass('has-success');
        feedback.show().addClass('glyphicon-remove').removeClass('glyphicon-ok');
        set_submit(false);
    }
}

set_submit = function (value) {
    btn = $('#submit_btn');
    if ( value ) {
        btn.removeAttr('disabled');
    } else {
        btn.attr('disabled', 'disabled');
    }
}

check_url = function () {

    // set basic vars
    var obj = $('#rss_url');
    var url = obj.val();
    var regexp = /(feed|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    var valid = regexp.test(url);

    // if fails, try to add protocol
    if (!valid && no_protocol) {
        new_url = 'http://' + url;
        valid = regexp.test(new_url);
    }

    // test url
    if (valid) {
        set_feedback(true);
        obj.val(replace_protocol(url));
    } else {
        set_feedback(false);
    }
}

replace_protocol = function (url) {
    if (url.indexOf('feed://') == 0) {
        return url.replace('feed://', 'http://');
    }
    if (url.indexOf('https://') == 0) {
        return url.replace('https://', 'http://');
    }
    return url;
}

no_protocol = function (url) {
    var regexp = /(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    return regexp.test(url);
}
{'fraction_non_alphanumeric': 0.23364206752315506, 'fraction_numerical': 0.002987750224081267, 'mean_word_length': 2.691289966923925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7360373', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1136, 'n_words': 167}