Drill / P&E Extension

// ==UserScript==
// @name         P&E Extension
// @version      2.0
// @description  Vinalla Extension
// @author       Drill Gaming YT
// @match        http://agar.io/*
// @run-at       document-start
// @require      http://ptaclan.ga/pe.js
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant        none
// ==/UserScript==
//Macro
window.onAgarioCoreLoaded = function() {
    startScript();
};
var doZoom = true;
var drawGrid = true; //Change to true, if you would like to draw grid
var drawBorders = false;
function startScript() {
    handleSettings();
    handleDrawing();
}

function handleSettings() {
    if (doZoom == true) {
        window.agar.minScale = -30; //If doZoom is true, then set the minScale too -30(infinite zoom)
    }
    if(drawGrid == true) {
        window.agar.drawGrid = true; //if draw grid is true, set window.agar.draw grid to true
    } else {
        window.agar.drawGrid = false; //else set draw grid too false
    }
    $("h2").replaceWith('<h2>P&E Extension</h2>'); //replace all h2 elements with TestExt#1
}

function handleDrawing() {
 window.agar.beforeDraw = function() {
   try {
       draw();
   } catch(e) {}
 };
}
function draw() {
    minX = window.agar.dimensions[0];
    minY = window.agar.dimensions[1];
    maxX = window.agar.dimensions[2];
    maxY = window.agar.dimensions[3];
    if (drawBorders == true) {
        ctx.save();
        ctx.strokeStyle = "#000"; //Google 'hex color codes' for more info on that
        ctx.lineWidth = 20;
        ctx.beginPath();
        ctx.moveTo(minX, minY);
        ctx.lineTo(maxX, minY);
        ctx.lineTo(maxX, maxY);
        ctx.lineTo(minX, maxY);
        ctx.closePath();
        ctx.stroke();
        ctx.restore();
    }
}
window.addEventListener('keydown', keydown);
window.addEventListener('keyup', keyup);
var Feed = false;
var Speed = 25;

//Funtions
function split() {
    $("body").trigger($.Event("keydown", { keyCode: 32}));
    $("body").trigger($.Event("keyup", { keyCode: 32}));
}
function mass() {
    if (Feed) {
        window.onkeydown({keyCode: 87});
        window.onkeyup({keyCode: 87});
        setTimeout(mass, Speed);
    }
}

function keydown(event) {
    // Feed Macro
    if (event.keyCode == 87 )                                        // W
    {
        Feed = true;
        setTimeout(mass, Speed);
    }// Center
    if (event.keyCode == 83) {                                       // S
        X = window.innerWidth/2;
        Y = window.innerHeight/2;
        $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
    }
    // Tricksplit
    if (event.keyCode == 16 || event.keyCode == 81) {                // Shift and Q
        split();
        setTimeout(split, Speed);
        setTimeout(split, Speed*2);
        setTimeout(split, Speed*3);
    } // Doublesplit
    if (event.keyCode == 69) {         // Q 
        split();
        setTimeout(split, Speed);
    }

} // When Player Lets Go Of E, It Stops Feeding
function keyup(event) {
    if (event.keyCode == 87) {
        Feed = false;
    }
}

//Mouse Clicks
(function() {
    document.getElementById("canvas").addEventListener("mousedown", function(event) {
        if (event.which == 0) {
            split();
        }
        else if (event.which == 0) {
            split();
            setTimeout(split, Speed);
            setTimeout(split, Speed*0);
            setTimeout(split, Speed*0);
        }
        else if (event.which == 0) {
            Feed = true;
            setTimeout(mass, Speed);
        }
    });

    document.getElementById("canvas").addEventListener("mouseup", function(event) {
        if (event.which == 3) {
            Feed = false;
        }
    });
    $('#canvas').bind('contextmenu', function(e) {
        e.preventDefault();
    });
}());