<commit_before>
$(document).ready(function () {
    var clients
    get_clients()
    $('.torrent_search_table').tablesorter();
    // Disables nzb search if torrent search page is open
    if ($('.formsearch').length) {
        $('.formsearch').addClass('disabled');
    } else {
        //pass
    }

    $('.formsearch').submit(function (e) {
        e.preventDefault();
        query = $(e.target).find('.search').val();
        if (query === undefined) return;
        search(query);
    });
});

// Sends torrent to the client on click
$(document).on('click', '.dlt', function (e) {
    e.preventDefault();
    var torrent_name = $(this).attr('data-name');
    var client = $(this).attr('data-client'); //
    var path = $(this).attr('data-path');
    var par = {'cmd':$(this).attr('data-cmd'), 'link':$(this).attr('data-hash'), 'torrentname':$(this).attr('data-name')};
    $.get(WEBDIR + path, par, function(response) {
        notify(torrent_name, 'Sent to ' + client, 'success');
    });
});


// Based on btn for now, should use a generic one..
function search(query) {
    if (query.length === 0) return;
    $('.spinner').show();
    $('#torrent_search_results').empty();
    $('#error_msg').empty();

    $.getJSON(WEBDIR + "torrentsearch/search/" + query, function (response) {

        // Stops the function from running if the search doesn't get any hits
        if (!response.length) {
            $('#error_msg').text('Didnt find any torrents with the query ' + query);
            $('#error_msg').css({"font-weight": "bold"});
            $('.spinner').hide();
            return;
        }

        $.each(response, function (index, torrent) {
            tr = $('<tr>');
            link = $('<a target="_blank">').attr('href', torrent.BrowseURL).text(torrent.ReleaseName)

            tr.append(
            $('<td>').append($('<i>').addClass('rg rg-provider rg-' + torrent.Provider)), // provider icon
            $('<td>').append(link),
            //$('<td class="span3 torrentsearch_releasename">').text(torrent.ReleaseName),
            $('<td>').addClass('torrentsearch_seeders').text(torrent.Seeders),
            $('<td>').addClass('torrentsearch_leechers').text(torrent.Leechers),
            $('<td>').addClass('torrentsearch_size">').text(bytesToSize(torrent.Size, 2)),
            $('<td>').addClass('hidden-phone torrentsearch_source').text(torrent.Source),
            $('<td>').addClass('hidden-phone torrentsearch_resolution').text(torrent.Resolution),
            $('<td>').addClass('hidden-phone torrentsearch_container').text(torrent.Container),
            $('<td>').addClass('hidden-phone torrentsearch_codec').text(torrent.Codec),
            $('<td>').addClass('hidden-phone torrentsearch_snatched').text(torrent.Snatched),
            $('<td>').append(atc(torrent)));
            $('#torrent_search_results').append(tr);


        });
    // Letting sort plugin know that there was a ajax call
    $('.spinner').hide();
    $('.torrent_search_table').trigger('update');
    // sort on seeds 0 based 0 1 2
    $('table').trigger("sorton", [[[2,1]]]);

    });
}

function atc(torrent) {
    var b = $('<div>').addClass('btn-group');
        // Used to check if there is any active clients
        var n = 0;
        $.each(clients, function (i, client) {
            if (client.active === 1) {
                var button = $('<a>').addClass('btn btn-mini dlt').
                attr('data-client', client.title).
                attr('data-path', client.path).
                attr('data-cmd', client.cmd).
                attr('data-name', torrent.ReleaseName). // not correct
                attr('data-hash', torrent.DownloadURL).
                attr('href', "#");
                // If there any active clients add 1 to n
                n += 1;
                // Makes icon and pop title
                var img = makeIcon("fa fa-download", client.title);
                button.append(img);
                b.append(button);
            }
        });
        // Checks if there is any active clients, if it isnt add a error message.
        if (n === 0) { // remove || 1 if needed was to test
            b.append('No active clients').removeClass('btn-group');
            return b;
        }
        else if (n === 1) {
            b.removeClass('btn-group');
        }

    return b;
}

function get_clients() {
    $.getJSON(WEBDIR + "torrentsearch/getclients", function (response) {
        clients = response
    });
}<commit_msg>Replace generic download button in ts with<commit_after>
$(document).ready(function () {
    var clients
    get_clients()
    $('.torrent_search_table').tablesorter();
    // Disables nzb search if torrent search page is open
    if ($('.formsearch').length) {
        $('.formsearch').addClass('disabled');
    } else {
        //pass
    }

    $('.formsearch').submit(function (e) {
        e.preventDefault();
        query = $(e.target).find('.search').val();
        if (query === undefined) return;
        search(query);
    });
});

// Sends torrent to the client on click
$(document).on('click', '.dlt', function (e) {
    e.preventDefault();
    var torrent_name = $(this).attr('data-name');
    var client = $(this).attr('data-client'); //
    var path = $(this).attr('data-path');
    var par = {'cmd':$(this).attr('data-cmd'), 'link':$(this).attr('data-hash'), 'torrentname':$(this).attr('data-name')};
    $.get(WEBDIR + path, par, function(response) {
        notify(torrent_name, 'Sent to ' + client, 'success');
    });
});


// Based on btn for now, should use a generic one..
function search(query) {
    if (query.length === 0) return;
    $('.spinner').show();
    $('#torrent_search_results').empty();
    $('#error_msg').empty();

    $.getJSON(WEBDIR + "torrentsearch/search/" + query, function (response) {

        // Stops the function from running if the search doesn't get any hits
        if (!response.length) {
            $('#error_msg').text('Didnt find any torrents with the query ' + query);
            $('#error_msg').css({"font-weight": "bold"});
            $('.spinner').hide();
            return;
        }

        $.each(response, function (index, torrent) {
            tr = $('<tr>');
            link = $('<a target="_blank">').attr('href', torrent.BrowseURL).text(torrent.ReleaseName)

            tr.append(
            $('<td>').append($('<i>').addClass('rg rg-provider rg-' + torrent.Provider)), // provider icon
            $('<td>').append(link),
            //$('<td class="span3 torrentsearch_releasename">').text(torrent.ReleaseName),
            $('<td>').addClass('torrentsearch_seeders').text(torrent.Seeders),
            $('<td>').addClass('torrentsearch_leechers').text(torrent.Leechers),
            $('<td>').addClass('torrentsearch_size">').text(bytesToSize(torrent.Size, 2)),
            $('<td>').addClass('hidden-phone torrentsearch_source').text(torrent.Source),
            $('<td>').addClass('hidden-phone torrentsearch_resolution').text(torrent.Resolution),
            $('<td>').addClass('hidden-phone torrentsearch_container').text(torrent.Container),
            $('<td>').addClass('hidden-phone torrentsearch_codec').text(torrent.Codec),
            $('<td>').addClass('hidden-phone torrentsearch_snatched').text(torrent.Snatched),
            $('<td>').append(atc(torrent)));
            $('#torrent_search_results').append(tr);


        });
    // Letting sort plugin know that there was a ajax call
    $('.spinner').hide();
    $('.torrent_search_table').trigger('update');
    // sort on seeds 0 based 0 1 2
    $('table').trigger("sorton", [[[2,1]]]);

    });
}

function atc(torrent) {
    var b = $('<div>').addClass('btn-group');
        // Used to check if there is any active clients
        var n = 0;
        $.each(clients, function (i, client) {
            if (client.active === 1) {
                var button = $('<a>').addClass('btn btn-mini dlt').
                attr('data-client', client.title).
                attr('data-path', client.path).
                attr('data-cmd', client.cmd).
                attr('data-name', torrent.ReleaseName). // not correct
                attr('data-hash', torrent.DownloadURL).
                attr('href', "#");
                // If there any active clients add 1 to n
                n += 1;
                // Makes icon and pop title
                var img = makeIcon("rg rg-" + client.title.toLowerCase(), client.title);
                button.append(img);
                b.append(button);
            }
        });
        // Checks if there is any active clients, if it isnt add a error message.
        if (n === 0) { // remove || 1 if needed was to test
            b.append('No active clients').removeClass('btn-group');
            return b;
        }
        else if (n === 1) {
            b.removeClass('btn-group');
        }

    return b;
}

function get_clients() {
    $.getJSON(WEBDIR + "torrentsearch/getclients", function (response) {
        clients = response
    });
}
{'fraction_non_alphanumeric': 0.18730615861763403, 'fraction_numerical': 0.003544528134692069, 'mean_word_length': 2.345313078918118, 'pattern_counts': {'":': 2, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7043800', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2592, 'n_words': 573}