<commit_before>// ==UserScript==
// @name         Slither.io-bot
// @namespace    http://slither.io/
// @version      0.1.9
// @description  Slither.io bot
// @author       <NAME> & <NAME>
// @match        http://slither.io/
// @grant        none
// ==/UserScript==
// Functions needed for the bot
// Set fake mouse coordinates
window.setMouseCoordinates = function(x, y) {
    window.xm = x;
    window.ym = y;
};
// Return the coordinates relative to the center (snake position).
window.mouseRelativeToCenter = function(x, y) {
    mapX = x - getHeight() / 2;
    mapY = y - getWidth() / 2;
    return [mapX, mapY];
};
// Map to mouse coordinates
window.mapToMouse = function(x, y) {
    mouseX = (x - getX()) * gsc;
    mouseY = (y - getY()) * gsc;
    return [mouseX, mouseY];
};
// Canvas width
window.getWidth = function() {
    return window.ww;
};
// Canvas height
window.getHeight = function() {
    return window.hh;
};
// X coordinates on the screen
window.getX = function() {
    return window.px;
};
// Y coordinates on the screen
window.getY = function() {
    return window.py;
};
// Get scaling ratio
window.getScale = function() {
    return window.gsc;
};
isBotRunning = false;
// Starts the bot
window.launchBot = function(d) {
    console.log("Starting Bot.");
    isBotRunning = true;
    // Save the original slither.io onmousemove function so we can re enable it back later
    window.mousemovelistener = window.onmousemove;
    // Removed the onemousemove listener so we can move the snake manually by setting coordinates
    window.onmousemove = undefined;
    return window.botInterval = setInterval(window.loop, d);
};
// Stops the bot
window.stopBot = function() {
    console.log("Stopping Bot.");
    // Re enable the original onmousemove function
    window.onmousemove = window.mousemovelistener;
    isBotRunning = false;
    // Clear the interval which starts the bot
    return clearInterval(window.botInterval);
};

window.connectBot = function() {
    console.log("Connecting");
    window.stopBot();
    window.connect();
    setTimeout(window.launchBot(), 1000);
};
// Save the original slither.io onkeydown function so we can add stuff to it
document.oldKeyDown = document.onkeydown;
// Re write the function with our function
document.onkeydown = function(e) {
    // Original slither.io onkeydown function + whatever is under it
    document.oldKeyDown(e);
    // If the letter "t" is pressed, check if the bot is running. If it is, stop the bot. If it isn't, start the bot.
    if (e.keyCode === 84) isBotRunning ? window.stopBot() : window.launchBot(5);
};

// Sorting function, from property 'distance'
window.sortFood = function(a, b) {<commit_msg>Added mouse support :) - Toggling works perfect<commit_after>// ==UserScript==
// @name         Slither.io-bot
// @namespace    http://slither.io/
// @version      0.2.0
// @description  Slither.io bot
// @author       <NAME> & <NAME>
// @match        http://slither.io/
// @grant        none
// ==/UserScript==
// Functions needed for the bot
// Set fake mouse coordinates
window.setMouseCoordinates = function(x, y) {
    window.xm = x;
    window.ym = y;
};
// Return the coordinates relative to the center (snake position).
window.mouseRelativeToCenter = function(x, y) {
    mapX = x - getHeight() / 2;
    mapY = y - getWidth() / 2;
    return [mapX, mapY];
};
// Map to mouse coordinates
window.mapToMouse = function(x, y) {
    mouseX = (x - getX()) * gsc;
    mouseY = (y - getY()) * gsc;
    return [mouseX, mouseY];
};
// Canvas width
window.getWidth = function() {
    return window.ww;
};
// Canvas height
window.getHeight = function() {
    return window.hh;
};
// X coordinates on the screen
window.getX = function() {
    return window.px;
};
// Y coordinates on the screen
window.getY = function() {
    return window.py;
};
// Get scaling ratio
window.getScale = function() {
    return window.gsc;
};
isBotRunning = false;
// Save the original slither.io onmousemove function so we can re enable it back later
window.mousemovelistener = window.onmousemove;
// Starts the bot
window.launchBot = function(d) {
    console.log("Starting Bot.");
    isBotRunning = true;
    // Removed the onemousemove listener so we can move the snake manually by setting coordinates
    window.onmousemove = undefined;
    return window.botInterval = setInterval(window.loop, d);
};
// Stops the bot
window.stopBot = function() {
    console.log("Stopping Bot.");
    // Re enable the original onmousemove function
    window.onmousemove = window.mousemovelistener;
    isBotRunning = false;
    // Clear the interval which starts the bot
    return clearInterval(window.botInterval);
};

window.connectBot = function() {
    console.log("Connecting");
    window.stopBot();
    window.connect();
    setTimeout(window.launchBot(5), 1000);
};
// Save the original slither.io onkeydown function so we can add stuff to it
document.oldKeyDown = document.onkeydown;
// Re write the function with our function
document.onkeydown = function(e) {
    // Original slither.io onkeydown function + whatever is under it
    document.oldKeyDown(e);
    // If the letter "t" is pressed, check if the bot is running. If it is, stop the bot. If it isn't, start the bot.
    if (e.keyCode === 84) isBotRunning ? window.stopBot() : window.launchBot(5);
};

// Sorting function, from property 'distance'
window.sortFood = function(a, b) {
{'fraction_non_alphanumeric': 0.12871652816251153, 'fraction_numerical': 0.0046168051708217915, 'mean_word_length': 3.1123766135155657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7002319', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1647, 'n_words': 533}