<commit_before>// ==UserScript==
// @name         agar-mini-map
// @namespace    http://github.com/dimotsai/
// @version      0.30
// @description  This script will show a mini map and your location on agar.io
// @author       dimotsai
// @license      MIT
// @match        http://agar.io/
// @grant        none
// @run-at       document-body
// ==/UserScript==

(function() {
    var _WebSocket = window.WebSocket;
    var $ = window.jQuery;

    var cells = [];
    var my_cell_ids = [];

    var options = {
        enableMultiCells: true,
        enablePosition: true
    };

    function miniMapCreateToken(id, color) {
        var mini_map_token = $('<div>').attr('id', 'mini-map-token-' + id).css({
            position: 'absolute',
            width: '5%',
            height: '5%',
            background: color,
            top: '0%',
            left: '0%',
            borderRadius: '50%'
        });
        return mini_map_token;
    }

    function miniMapRegisterToken(id, token) {
        if (window.mini_map_tokens[id] === undefined) {
            window.mini_map.append(token);
            window.mini_map_tokens[id] = token;
        }
    }

    function miniMapUnregisterToken(id) {
        if (window.mini_map_tokens[id] !== undefined) {
            window.mini_map_tokens[id].detach();
            delete window.mini_map_tokens[id];
        }
    }

    function miniMapIsRegisteredToken(id) {
        return window.mini_map_tokens[id] !== undefined;
    }

    function miniMapUpdateToken(id, x, y, size) {
        if (window.mini_map_tokens[id] !== undefined) {
            window.mini_map_tokens[id]
            .css({
                left:   x    * 100 + '%',
                top:    y    * 100 + '%',
                width:  size * 100 + '%',
                height: size * 100 + '%'
            });
            return true;
        } else {
            return false;
        }
    }

    function miniMapUpdatePos(x, y) {
        window.mini_map_pos.text('x: ' + x.toFixed(0) + ', y: ' + y.toFixed(0));
    }

    function miniMapInit() {
        var $ = window.jQuery;
        window.mini_map_tokens = {};

        if ($('#mini-map-wrapper').length === 0) {
            var wrapper = $('<div>').attr('id', 'mini-map-wrapper').css({
                position: 'fixed',
                bottom: 10,
                right: 10,
                width: 300,
                height: 300,
                background: 'rgba(128, 128, 128, 0.58)'
            });

            var mini_map = $('<div>').attr('id', 'mini-map').css({
                width: '100%',
                height: '100%',
                position: 'relative'
            });

            wrapper.append(mini_map).appendTo(document.body);

            window.mini_map = mini_map;
        }

        if ($('#mini-map-pos').length === 0) {
            window.mini_map_pos = $('<div>').attr('id', 'mini-map-pos').css({
                bottom: 10,
                right: 10,
                color: 'white',
                fontSize: 15,
                fontWeight: 800,
                position: 'fixed',
                padding: '0px 10px'
            }).appendTo(document.body);
        }

    }
<commit_msg>Render the mini map on a canvas<commit_after>// ==UserScript==
// @name         agar-mini-map
// @namespace    http://github.com/dimotsai/
// @version      0.30
// @description  This script will show a mini map and your location on agar.io
// @author       dimotsai
// @license      MIT
// @match        http://agar.io/
// @grant        none
// @run-at       document-body
// ==/UserScript==

(function() {
    var _WebSocket = window.WebSocket;
    var $ = window.jQuery;

    var cells = [];
    var my_cell_ids = [];

    var options = {
        enableMultiCells: true,
        enablePosition: false
    };

    function miniMapCreateToken(id, color) {
        var mini_map_token = {
            id: id,
            color: color,
            x: 0,
            y: 0,
            size: 0
        };
        return mini_map_token;
    }

    function miniMapRegisterToken(id, token) {
        if (window.mini_map_tokens[id] === undefined) {
            // window.mini_map.append(token);
            window.mini_map_tokens[id] = token;
        }
    }

    function miniMapUnregisterToken(id) {
        if (window.mini_map_tokens[id] !== undefined) {
            // window.mini_map_tokens[id].detach();
            var x = window.mini_map_tokens[id].x;
            var y = window.mini_map_tokens[id].y;
            var size = window.mini_map_tokens[id].size;
            var canvas = window.mini_map;
            var ctx = canvas.getContext('2d');

            ctx.globalCompositeOperation = 'destination-out';
            ctx.beginPath();
            ctx.arc(x * canvas.width , y * canvas.height, size * canvas.width, 0 ,2 * Math.PI, false);
            ctx.closePath();
            ctx.fillStyle = window.mini_map_tokens[id].color;
            ctx.fill();
            delete window.mini_map_tokens[id];
        }
    }

    function miniMapIsRegisteredToken(id) {
        return window.mini_map_tokens[id] !== undefined;
    }

    function miniMapUpdateToken(id, x, y, size) {
        if (window.mini_map_tokens[id] !== undefined) {

            var draw = function(clear) {

                var canvas = window.mini_map;
                var ctx = canvas.getContext('2d');

                if (clear) {
                    ctx.globalCompositeOperation = 'destination-out';
                } else {
                    ctx.globalCompositeOperation = 'source-over';
                }
                ctx.lineWidth = 0;
                ctx.beginPath();
                ctx.arc(
                    window.mini_map_tokens[id].x * canvas.width,
                    window.mini_map_tokens[id].y * canvas.height, 
                    window.mini_map_tokens[id].size * canvas.width, 
                    0,
                    2 * Math.PI,
                    false
                );
                ctx.closePath();
                ctx.fillStyle = window.mini_map_tokens[id].color;
                ctx.fill();
            }

            draw(true);

            window.mini_map_tokens[id].x = x;
            window.mini_map_tokens[id].y = y;
            window.mini_map_tokens[id].size = size;

            draw(false);



            // window.mini_map_tokens[id]
            // .css({
            //     left:   x    * 100 + '%',
            //     top:    y    * 100 + '%',
            //     width:  size * 100 + '%',
            //     height: size * 100 + '%'
            // });

            return true;
        } else {
            return false;
        }
    }

    function miniMapUpdatePos(x, y) {
        window.mini_map_pos.text('x: ' + x.toFixed(0) + ', y: ' + y.toFixed(0));
    }

    function miniMapInit() {
        var $ = window.jQuery;
        window.mini_map_tokens = {};

        if ($('#mini-map-wrapper').length === 0) {
            var wrapper = $('<div>').attr('id', 'mini-map-wrapper').css({
                position: 'fixed',
                bottom: 10,
                right: 10,
                width: 300,
                height: 300,
                background: 'rgba(128, 128, 128, 0.58)'
            });

            var mini_map = $('<canvas>').attr({
                id: 'mini-map',
                width: 300,
                height: 300
            }).css({
                width: '100%',
                height: '100%',
                position: 'relative'
            });

            wrapper.append(mini_map).appendTo(document.body);

            window.mini_map = mini_map[0];
        }

        if ($('#mini-map-pos').length === 0) {
            window.mini_map_pos = $('<div>').attr('id', 'mini-map-pos').css({
                bottom: 10,
                right: 10,
                color: 'white',
                fontSize: 15,
                fontWeight: 800,
                position: 'fixed',
                padding: '0px 10px'
            }).appendTo(document.body);
        }

    }

{'fraction_non_alphanumeric': 0.13869158878504673, 'fraction_numerical': 0.017570093457943924, 'mean_word_length': 1.3752589523527672, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5648599', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2290, 'n_words': 459}