Greasy Fork

BMO BOT 9000

Print Images!!!!!!

目前为 2023-08-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         BMO BOT 9000
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Print Images!!!!!!
// @author       Bambi1
// @match        https://pixelplace.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
// @run-at       document-start
// @grant        none
// ==/UserScript==


// Your pixel array here(delete the brackets[])
const pixelArray = [] 
//^^^^^^^^^^^^^^^^^^^^^
function fix(a, b) {
    Object.defineProperty(window.console, a, {configurable:false,enumerable:true,writable:false,value:b});
}

fix('log', console.log);
fix('warn', console.warn);
fix('error', console.error);
fix('info', console.info);
const originalWebSocket = window.WebSocket;
var socket;

class WebSocketHook extends originalWebSocket {
    constructor(a, b) {
        super(a, b);
        socket = this;
    }
}

window.WebSocket = WebSocketHook;

document.addEventListener('keydown', function(event) {
    // Check if the pressed key is 'j'
    if (event.key === 'j') {
        // Get the element with the id "coordinates"
        var coordinatesElement = document.getElementById('coordinates');
        var coordinatesValue = coordinatesElement.textContent;
        // Split the coordinates value into x and y parts
        var [x, y] = coordinatesValue.split(',');
        // Call the BMO function with the extracted x and y values
        console.log(parseInt(x), parseInt(y));
        image(parseInt(x), parseInt(y));
    }
});

function placePix(x, y, col) {
    socket.send(`42["p",[${x},${y},${col},1]]`);
}

document.addEventListener('keydown', function(event) {
    // Check if the pressed key is 'j'
    if (event.key === 'j') {
        // Get the element with the id "coordinates"
        var coordinatesElement = document.getElementById('coordinates');
        var coordinatesValue = coordinatesElement.textContent;
        // Split the coordinates value into x and y parts
        var [x, y] = coordinatesValue.split(',');
        // Call the BMO function with the extracted x and y values
        console.log(parseInt(x), parseInt(y));
        image(parseInt(x), parseInt(y));
    }
});


function image(SX, SY) {
    
    const delayBetweenPixels = 25; // Adjust this value as needed

    let rowIndex = 0;
    function placeNextRow() {
        if (rowIndex < pixelArray.length) {
            const row = pixelArray[rowIndex];
            let columnIndex = 0;

            function placeNextPixel() {
                if (columnIndex < row.length) {
                    const col = row[columnIndex];
                    // Check if the color is not 50 before placing the pixel
                    if (col !== 50) {
                        placePix(SX + columnIndex, SY + rowIndex, col);
                    }
                    columnIndex++;
                    if (col === 50) {
                        placeNextPixel(); // Skip the delay for color 50
                    } else {
                        setTimeout(placeNextPixel, delayBetweenPixels);
                    }
                } else {
                    rowIndex++;
                    placeNextRow();
                }
            }

            placeNextPixel();
        }
    }

    // Start placing pixels
    placeNextRow();
}