// ==UserScript==
// @name Afk Script UPDATED
// @namespace http://tampermonkey.net/
// @version 2
// @description Press F to set the afk location and J to afk
// @author Mi300
// @match https://diep.io/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license dont copy my script thx
// @grant none
// ==/UserScript==
setTimeout (function() {
try{
/*function hookContext(method, callback, target = CanvasRenderingContext2D) {
target.prototype[method] = new Proxy(target.prototype[method], {
apply(method, context, args) {
callback(context, args);
method.apply(context, args);
}
});
};*/
const p = CanvasRenderingContext2D.prototype,
_fill = p.fill,
_fillText = p.fillText,
_strokeText = p.strokeText,
_beginPath = p.beginPath,
_moveTo = p.moveTo,
_lineTo = p.lineTo,
_strokeRect = p.strokeRect,
_rect = p.rect,
_arc = p.arc,
_try_spawn = input.try_spawn,
_toString = Function.prototype.toString;
let fill,
beginPath,
moveTo,
lineTo,
strokeRect,
rect,
try_spawn;
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let distance = [0, 0];
let isActive = false;
let storedPos = [0, 0];
let arrowPos = [0, 0];
let minimapPos = [0, 0];
let minimapDim = [0, 0];
let worldPosition = [0, 0];
let teamSnapshot = false;
let team = '#f14e54';
let drawInstructions = 0;
let vertices = new Array(0);
beginPath = function(...args) {
drawInstructions = 0;
vertices = new Array(0);
_beginPath.call(this, ...args)
}
moveTo = function(...args) {
drawInstructions = 2;
vertices.push(args)
_moveTo.call(this, ...args)
}
lineTo = function(...args) {
if (drawInstructions >= 2 && drawInstructions <= 5) {
drawInstructions++;
vertices.push(args);
_lineTo.call(this, ...args);
return;
}
drawInstructions = 0;
_lineTo.call(this, ...args)
}
fill = function(...args) {
if (this.globalAlpha != 1 || this.fillStyle != '#000000') {
_fill.call(this, ...args)
return;
}
if (drawInstructions === 4) {
const pos = getAverage (vertices);
arrowPos = pos;
}
_fill.call(this, ...args);
}
strokeRect = function(...args) {
const t = this.getTransform();
minimapPos = [t.e, t.f];
minimapDim = [t.a, t.d];
_strokeRect.call(this, ...args)
}
rect = function(...args) {// purple: #bf7ff5, red: #f14e54, blue: #00b2e1, green: #00e16e
const c = this.fillStyle;
if (teamSnapshot) {
if (c == '#f14e54') {
team = c;
}
if (c == '#00b2e1') {
team = c;
}
if (c == '#bf7ff5') {
team = c;
}
if (c == '#00e16e') {
team = c;
}
}
_rect.call(this, ...args)
}
function getAverage(points) {
let ret = [0, 0];
points.forEach (point => {
ret[0] += point[0];
ret[1] += point[1];
});
ret[0] /= points.length;
ret[1] /= points.length;
return ret;
}
function getWorldPos () {
const ret = [
parseFloat((((arrowPos[0] - minimapPos[0] - minimapDim[0] / 2) / minimapDim[0] * 100) * 460).toFixed (3)),
parseFloat((((arrowPos[1] - minimapPos[1] - minimapDim[1] / 2) / minimapDim[1] * 100) * 460).toFixed (3)),
]
return ret;
}
try_spawn = function (...args) {
teamSnapshot = true;
setTimeout(function() {
teamSnapshot = false;
},2500);
_try_spawn.call(this, ...args)
}
function tick() {
window.requestAnimationFrame(tick);
worldPosition = getWorldPos();
distance = getDist(
worldPosition,
storedPos,
)
if (isActive) {
move();
}
drawAfkPos();
}
tick();
function toGrid(dist) {
return [
dist[0] / 4,
dist[1] / 4,
dist[2] / 4,
]
}
function drawAfkPos() {
//distance
const width = canvas.width;
const height = canvas.height;
const grid = toGrid(distance);
const size = 50;
let toDraw = [
width / 2 - grid[1],
height / 2 - grid[2],
]
ctx.beginPath();
ctx.globalAlpha = 0.5;
ctx.fillStyle = team
ctx.arc(...toDraw, size, 0, Math.PI * 2, false);
ctx.fill();
ctx.stroke();
ctx.globalAlpha = 1;
ctx.beginPath();
ctx.lineWidth = 4;
ctx.font = "23px bold arial"
ctx.fillStyle = 'white';
ctx.strokeStyle = 'black';
if (isActive) {
ctx.strokeText('[J] Locked', toDraw[0] - 50, toDraw[1] + 25);
ctx.fillText('[J] Locked', toDraw[0] - 50, toDraw[1] + 25);
} else {
ctx.strokeText('[J] Unlocked', toDraw[0] - 50, toDraw[1] + 25);
ctx.fillText('[J] Unlocked', toDraw[0] - 50, toDraw[1] + 25);
}
}
document.addEventListener('keydown', e => {
if(e.key === 'j') {
isActive = !isActive;
input.key_up (83);
input.key_up (87);
input.key_up (68);
input.key_up (65);
}
if(e.key === 'f') {
storedPos = worldPosition;
}
});
function getDist(t1, t2) {
const distX = t1[0] - t2[0];
const distY = t1[1] - t2[1];
return [Math.hypot(distX, distY), distX, distY];
};
function move() {
if (distance[1] < 0.1) {
input.key_up (65);
input.key_down (68);
} else if (distance[1] > -0.1) {
input.key_up (68);
input.key_down (65);
} else {
input.key_up (68);
input.key_up (65);
}
if (distance[2] < 0.1) {
input.key_up (87);
input.key_down (83);
} else if (distance[2] > 0.1) {
input.key_up (83);
input.key_down (87);
} else {
input.key_up (83);
input.key_up (87);
}
}
let toString = function() {
switch(this) {
case fill: return _toString.call(_fill);
case beginPath: return _toString.call(_beginPath);
case moveTo: return _toString.call(_moveTo);
case lineTo: return _toString.call(_lineTo);
case strokeRect: return _toString.call(_strokeRect);
case rect: return _toString.call(_rect);
case input.try_spawn: return _toString.call(_try_spawn);
case toString: return _toString.call(_toString);
}
return _toString.call(this);
};
p.fill = fill;
p.beginPath = beginPath;
p.moveTo = moveTo;
p.lineTo = lineTo;
p.strokeRect = strokeRect;
p.rect = rect;
input.try_spawn = try_spawn;
Function.prototype.toString = toString;
}
catch(er) {console.log (er)}
},5500);