<commit_before>(function() {
    // Get application context
    var app = Sammy.apps['#main'];
    var store = app.store;

    /**
     * Tools
     *
     */

    // Tools list
    app.get('#/tools', function (c) {
        c.view('tools/tools_list');
    });

    // Update administration password
    app.get('#/tools/adminpw', function (c) {
        c.view('tools/tools_adminpw');
    });

    // Update administration password (PUT)
    app.put('#/tools/adminpw', function (c) {
        var params = {};
        $.each(c.params.toHash(), function(key, value) {
            if (value !== '') { params[key] = value; }
        });
        if ($.isEmptyObject(params)) {
            c.flash('fail', y18n.t('error_modify_something'));
            c.refresh();
            return;
        }
        if (params['new_password'] !== params['confirm_new_password']) {
            c.flash('fail', y18n.t('passwords_dont_match'));
            c.refresh();
            return;
        }

        c.api('POST', '/login', { 'password': params['<PASSWORD>'] }, function(data) {
            // Remove useless variable
            delete params['old_password'];
            delete params['confirm_new_password'];

            // Update password and redirect to the home
            c.api('PUT', '/adminpw', params, function(data) {
                c.redirect_to('#/logout');
            });
        }, undefined, false);
    });

    // System update & upgrade
    app.get('#/update', function (c) {
        c.api('PUT', '/update', {}, function(data) {
            c.view('tools/tools_update', data, function() {
                // Configure buttons behaviors
                $("button[data-upgrade]").on("click", function() {

                    var what = $(this).data("upgrade").toLowerCase();

                    // Upgrade all apps or the system

                    if ((what == "system") || (what == "system"))
                    {
                        var confirm_message = y18n.t('confirm_update_' + what);
                        var api_url = '/upgrade?'+what;
                    }

                    // Upgrade a specific apps

                    else
                    {
                        var confirm_message = y18n.t('confirm_update_specific_app', [what]);
                        var api_url = '/upgrade/apps?app='+what;
                    }

                    c.confirm(
                        y18n.t('tools'),
                        confirm_message,
                        function(){
                            c.api('PUT', api_url, {}, function(data) {
                                c.redirect_to('#/tools/logs');
                            });
                        }
                    );
                });
            });
        });
    });

    // Display journals list
    app.get('#/tools/logs', function (c) {
        c.api('GET', "/logs?limit=25&with_details", {}, function(categories) {
            data = [];
            category_icons = {
                'operation': 'wrench',
                'history': 'history',
                'package': 'puzzle-piece',
                'system': 'cogs',
                'access': 'ban',
                'service': 'cog',
                'app': 'cubes'
            }
            success_icons = {
                true: 'check text-success',
                false: 'close text-danger',
                '?': 'question text-warning'
            }
            for (var category in categories) {
                for (var log in categories[category])
                {
                    categories[category][log].success_icon = success_icons[categories[category][log].success]
                }
                if (categories.hasOwnProperty(category)) {
                    data.push({
                        key:category,
                        icon:(category in category_icons)?category_icons[category]:'info-circle',
                        value:categories[category]
                    });
                }
            }

            c.view('tools/tools_logs', {
                "data": data,
                "locale": y18n.locale
            });
        });
    });

    // One journal
    app.get(/\#\/tools\/logs\/(.*)(\?number=(\d+))?/, function (c) {
        var params = "?path=" + c.params["splat"][0];
        var number = (c.params["number"])?c.params["number"]:50;
        params += "&number=" + number;

        c.api('GET', "/logs/display" + params, {}, function(log) {
            if ('metadata' in log) {
                if (!'env' in log.metadata && 'args' in log.metadata) {
                    log.metadata.env = log.metadata.args
                }
            }

            c.view('tools/tools_log', {
                "log": log,
                "next_number": log.logs.length == number ? number * 10:false,
                "locale": y18n.locale
            }, function() {
                log = $("#log").html();
                log = log.replace(/.*: ERROR - .*/g, function (match) { return '<span class="alert-danger">'+match+'</span>'});
                log = log.replace(/.*: WARNING - .*/g, function (match) { return '<span class="alert-warning">'+match+'</span>'});
                log = log.replace(/.*: SUCCESS - .*/g, function (match) { return '<span class="alert-success">'+match+'</span>'});
                log = log.replace(/.*: INFO - .*/g, function (match) { return '<span class="alert-info">'+match+'</span>'});
                $("#log").html(log);

                // Configure behavior for the button to share log on Yunohost (it calls display --share)
                $('button[data-action="share"]').on("click", function() {
                    c.api('GET', '/logs/display?path='+$(this).data('log-id')+'&share', {},
                        function(data) {
                            c.hideLoader();
                            window.open(data.url, '_blank');
                    });
                });
            });
        });
    });<commit_msg>More accurate selector because of asynchronous shit related to slider effect<commit_after>(function() {
    // Get application context
    var app = Sammy.apps['#main'];
    var store = app.store;

    /**
     * Tools
     *
     */

    // Tools list
    app.get('#/tools', function (c) {
        c.view('tools/tools_list');
    });

    // Update administration password
    app.get('#/tools/adminpw', function (c) {
        c.view('tools/tools_adminpw');
    });

    // Update administration password (PUT)
    app.put('#/tools/adminpw', function (c) {
        var params = {};
        $.each(c.params.toHash(), function(key, value) {
            if (value !== '') { params[key] = value; }
        });
        if ($.isEmptyObject(params)) {
            c.flash('fail', y18n.t('error_modify_something'));
            c.refresh();
            return;
        }
        if (params['new_password'] !== params['confirm_new_password']) {
            c.flash('fail', y18n.t('passwords_dont_match'));
            c.refresh();
            return;
        }

        c.api('POST', '/login', { 'password': params['old_password'] }, function(data) {
            // Remove useless variable
            delete params['old_password'];
            delete params['confirm_new_password'];

            // Update password and redirect to the home
            c.api('PUT', '/adminpw', params, function(data) {
                c.redirect_to('#/logout');
            });
        }, undefined, false);
    });

    // System update & upgrade
    app.get('#/update', function (c) {
        c.api('PUT', '/update', {}, function(data) {
            c.view('tools/tools_update', data, function() {
                // Configure buttons behaviors
                $("button[data-upgrade]").on("click", function() {

                    var what = $(this).data("upgrade").toLowerCase();

                    // Upgrade all apps or the system

                    if ((what == "system") || (what == "system"))
                    {
                        var confirm_message = y18n.t('confirm_update_' + what);
                        var api_url = '/upgrade?'+what;
                    }

                    // Upgrade a specific apps

                    else
                    {
                        var confirm_message = y18n.t('confirm_update_specific_app', [what]);
                        var api_url = '/upgrade/apps?app='+what;
                    }

                    c.confirm(
                        y18n.t('tools'),
                        confirm_message,
                        function(){
                            c.api('PUT', api_url, {}, function(data) {
                                c.redirect_to('#/tools/logs');
                            });
                        }
                    );
                });
            });
        });
    });

    // Display journals list
    app.get('#/tools/logs', function (c) {
        c.api('GET', "/logs?limit=25&with_details", {}, function(categories) {
            data = [];
            category_icons = {
                'operation': 'wrench',
                'history': 'history',
                'package': 'puzzle-piece',
                'system': 'cogs',
                'access': 'ban',
                'service': 'cog',
                'app': 'cubes'
            }
            success_icons = {
                true: 'check text-success',
                false: 'close text-danger',
                '?': 'question text-warning'
            }
            for (var category in categories) {
                for (var log in categories[category])
                {
                    categories[category][log].success_icon = success_icons[categories[category][log].success]
                }
                if (categories.hasOwnProperty(category)) {
                    data.push({
                        key:category,
                        icon:(category in category_icons)?category_icons[category]:'info-circle',
                        value:categories[category]
                    });
                }
            }

            c.view('tools/tools_logs', {
                "data": data,
                "locale": y18n.locale
            });
        });
    });

    // One journal
    app.get(/\#\/tools\/logs\/(.*)(\?number=(\d+))?/, function (c) {
        var params = "?path=" + c.params["splat"][0];
        var number = (c.params["number"])?c.params["number"]:50;
        params += "&number=" + number;

        c.api('GET', "/logs/display" + params, {}, function(log) {
            if ('metadata' in log) {
                if (!'env' in log.metadata && 'args' in log.metadata) {
                    log.metadata.env = log.metadata.args
                }
            }

            c.view('tools/tools_log', {
                "log": log,
                "next_number": log.logs.length == number ? number * 10:false,
                "locale": y18n.locale
            }, function() {
                log = $("#main #log").html();
                log = log.replace(/.*: ERROR - .*/g, function (match) { return '<span class="alert-danger">'+match+'</span>'});
                log = log.replace(/.*: WARNING - .*/g, function (match) { return '<span class="alert-warning">'+match+'</span>'});
                log = log.replace(/.*: SUCCESS - .*/g, function (match) { return '<span class="alert-success">'+match+'</span>'});
                log = log.replace(/.*: INFO - .*/g, function (match) { return '<span class="alert-info">'+match+'</span>'});
                $("#main #log").html(log);

                // Configure behavior for the button to share log on Yunohost (it calls display --share)
                $('button[data-action="share"]').on("click", function() {
                    c.api('GET', '/logs/display?path='+$(this).data('log-id')+'&share', {},
                        function(data) {
                            c.hideLoader();
                            window.open(data.url, '_blank');
                    });
                });
            });
        });
    });
{'fraction_non_alphanumeric': 0.16250311229147646, 'fraction_numerical': 0.0034857664536476055, 'mean_word_length': 1.3357239775150223, 'pattern_counts': {'":': 10, '<': 20, '<?xml version=': 0, '>': 20, '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': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '804932', 'n_tokens_mistral': 3275, 'n_tokens_neox': 3073, 'n_words': 612}