★moomoo.io DetailMiniMap Fixed! Working 2021

Add details to the existing mini map. (wood/food/stone/points)

// ==UserScript==
// @name			★moomoo.io DetailMiniMap Fixed! Working 2021
// @version			2.4
// @description		Add details to the existing mini map. (wood/food/stone/points)
// @author			nekosan (Fixed by Jet-X)
// @match			*://*.moomoo.io/*
// @grant			none
// @namespace		https://greasyfork.org/en/scripts/29014-moomoo-io-detailminimap
// @license MIT
// ==/UserScript==

import("https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js");

(function() {
    'use strict';

    var conf = {
        'map': {
            'w': '200',
            'h': '200',
            'bottom': '80',
            'left': '20'
        },
        'resource':{
            'wood': {
                'color': '#8ecc51',
                'w': '3',
                'h': '3'
            },
            'food': {
                'color': '#ff3333',
                'w': '5',
                'h': '5'
            },
            'stone': {
                'color': '#888888',
                'w': '5',
                'h': '5'
            },
            'points': {
                'color': '#ffee33',
                'w': '5',
                'h': '5'
            }
        },
        'scale': 13200.0
    };

    var ws = null;
    WebSocket.prototype.sender = WebSocket.prototype.send;
    WebSocket.prototype.send = function(m){
        if(ws === null){
            ws = this;
            this.addEventListener('message', handleMessage);
        }
        this.sender(...arguments);
    }

    // Change Layout
    let defaultMapCss = document.getElementById('mapDisplay').style
    , defaultScoreCss = document.getElementById('scoreDisplay').style
    $('#mapDisplay').css({
        'bottom': conf.map.bottom + 'px',	// default 20px
        'left': conf.map.left + 'px',		// default 20px
        'width': conf.map.w + 'px',			// default 130px
        'height': conf.map.h + 'px'			// default 130px
    });
    $('#scoreDisplay').css({
        'bottom': '20px',					// default 20px
        'left': '20px'						// default 170px
    });

    function handleMessage(m){
        let temp = msgpack.decode(new Uint8Array(m.data));
        let data;
        if(temp.length > 1) {
            data = [temp[0], ...temp[1]];
            if (data[1] instanceof Array){
                data = data;
            }
        } else {
            data = temp;
        }
        let item = data[0];
        if(!data) {return};
        if(item == '6'){
            for(let t = 0;t<data[1].length;t+=8){
                var locInfo = data[1].slice(t, t+8);
                addItem(...locInfo);
            }
        };
        if(item == '12'){
            document.getElementById('building'+data[1]).remove();
        }
    }


        $('#gameUI').append('<div id="minimap" class=" " ' +
                            'style="' +
                            'position: absolute;' +
                            'bottom: ' + conf.map.bottom + 'px;' +
                            'left: ' + conf.map.left + 'px;' +
                            'display: inline-block;' +
                            'width: ' + conf.map.w + 'px;' +
                            'height: ' + conf.map.h + 'px;' +
                            '"></div>');

        function addItem(sid, x, y, dir, scale, type, item, owner) {
            if (!$('#minimap').length || type === null || $('#resource' + sid).length) return true;

            var name = '';
            var color = '';
            var tx = x * 100 / conf.scale;
            var ty = y * 100 / conf.scale;
            var w;
            var h;

            if(type > 3){
                type += 16;
                let url = document.getElementById(`actionBarItem`+type.toString()).style.backgroundImage;
                $('#minimap').append(`<div id='building${sid}' style='display: block;
                width: 10px; height: 10px; background-image: ${url};
                background-size: 10px;
                left: ${tx}%; top: ${ty}%; position: absolute;'></div>'`)
            }else{
                switch (type) {
                    default:
                        return;
                    case 0:
                        name = 'wood';
                        color = conf.resource.wood.color;
                        w = conf.resource.wood.w;
                        h = conf.resource.wood.h;
                        break;
                    case 1:
                        name = 'food';
                        color = conf.resource.food.color;
                        w = conf.resource.food.w;
                        h = conf.resource.food.h;
                        break;
                    case 2:
                        name = 'stone';
                        color = conf.resource.stone.color;
                        w = conf.resource.stone.w;
                        h = conf.resource.stone.h;
                        break;
                    case 3:
                        name = 'points';
                        color = conf.resource.points.color;
                        w = conf.resource.points.w;
                        h = conf.resource.points.h;
                        break;
                }
                $('#minimap').append('<div id="resource' + sid + '" style="' +
                                     'display: block;' +
                                     'width: ' + w + 'px;' +
                                     'height: ' + h + 'px;' +
                                     'background:' + color + ';' +
                                     'left:' + tx + '%;' +
                                     'top:' + ty + '%;' +
                                     'position: absolute;' +
                                     'border-radius: 9999px;' +
                                     '"></div>');
            }
        }
    let t = !1;
    document.addEventListener('keydown', function (e) {
        if (e.keyCode == 77) {
            $('#minimap').toggle();
            t = !t;
            if(t){
                document.getElementById('mapDisplay').style = defaultMapCss
                document.getElementById('scoreDisplay').style = defaultScoreCss
            }else{
                $('#mapDisplay').css({
                    'bottom': conf.map.bottom + 'px',	// default 20px
                    'left': conf.map.left + 'px',		// default 20px
                    'width': conf.map.w + 'px',			// default 130px
                    'height': conf.map.h + 'px'			// default 130px
                });
                $('#scoreDisplay').css({
                    'bottom': '20px',					// default 20px
                    'left': '20px'						// default 170px
                });
            }
        }
    });
})();