Range should be shown when hovering on a (living) pawn

ItsEvil has made a userscript to do this already, so it should be stolen

var lastTempRange = {};
window.lettuce.viewport.on('mousemove', (event) => {
    const pos = window.lettuce.viewport.toWorld(event.global);
    const tile = posToTile(pos);

    if (lastTempRange.x && lastTempRange.y) {
        if (lastTempRange.x === tile.x && lastTempRange.y === tile.y) return; // Ignored

        const existingRange = window.lettuce.temporaryCircles[[lastTempRange.x, lastTempRange.y]];
        if (existingRange) {
            toggleTempRange(lastTempRange);
        }

        lastTempRange = {};
    }

    if (tile.x < 0 || tile.y < 0 || tile.x >= GRID_WIDTH || tile.y >= GRID_HEIGHT) return; // Outside the area, ignored.

    const pawn = window.lettuce.pawns.find(pawn => pawn.x === tile.x && pawn.y === tile.y);
    const existingRange = window.lettuce.temporaryCircles[[tile.x, tile.y]];
    if (!pawn || !pawn.alive || existingRange) return;

    toggleTempRange(tile);
    lastTempRange = { x: tile.x, y: tile.y };
});

updatePawn = ((oldUpdatePawn) => {
    return (id, data) => {
        const pawn = window.lettuce.pawns.find(pawn=>pawn.id===id);
        if (!pawn) return;

        const x = pawn.x;
        const y = pawn.y;

        oldUpdatePawn(id, data);

        if (lastTempRange.x !== x || lastTempRange.y !== y) return; // Was not on the tile, ignore.

        if (x != pawn.x || y != pawn.y || !pawn.alive) {
            toggleTempRange({ x, y });
            lastTempRange = {};
        }
    }
})(updatePawn);