7Placer

typescript pixelplace.io bot

目前為 2024-06-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          7Placer
// @description   typescript pixelplace.io bot
// @version       v1.3.1a
// @author        Azti
// @match         https://pixelplace.io/*
// @require       https://update.greasyfork.org/scripts/498080/1395134/Hacktimer.js
// @require       https://pixelplace.io/js/jquery.min.js?v2=1
// @require       https://pixelplace.io/js/jquery-ui.min.js?v2=1
// @grant         none
// @run-at        document-start
// @namespace https://greasyfork.org/users/374503
// ==/UserScript==

/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
var __webpack_exports__ = {};

// UNUSED EXPORTS: Bot, BotSquare, Canvas, ImageToPixels, Queue, botImage

;// CONCATENATED MODULE: ./src/canvas/util/canvasloader.ts

function loadcanvas(canvas) {
    canvasworker.onmessage = function (event) {
        if (Array.isArray(event.data)) {
            canvas.CanvasArray = event.data; // sets canvas
        }
        else {
            console.log(`[7placer] Processing took: ${Math.round(event.data)}ms`);
        }
    };
    canvasworker.postMessage(canvas_Canvas.ID);
}
const cloadercode = `
const canvasworkerTimet = performance.now();
const colors = [
    0xFFFFFF, 0xC4C4C4, 0x888888, 0x555555, 0x222222, 0x000000, 0x006600, 0x22B14C,
    0x02BE01, 0x51E119, 0x94E044, 0xFBFF5B, 0xE5D900, 0xE6BE0C, 0xE59500, 0xA06A42,
    0x99530D, 0x633C1F, 0x6B0000, 0x9F0000, 0xE50000, 0xFF3904, 0xBB4F00, 0xFF755F,
    0xFFC49F, 0xFFDFCC, 0xFFA7D1, 0xCF6EE4, 0xEC08EC, 0x820080, 0x5100FF, 0x020763,
    0x0000EA, 0x044BFF, 0x6583CF, 0x36BAFF, 0x0083C7, 0x00D3DD, 0x45FFC8, 0x003638,
    0x477050, 0x98FB98, 0xFF7000, 0xCE2939, 0xFF416A, 0x7D26CD, 0x330077, 0x005BA1,
    0xB5E8EE, 0x1B7400, 0xCCCCCC
];

self.addEventListener('message', async (event) => {
    const imageResponse = await fetch('https://pixelplace.io/canvas/' + event.data + '.png?t200000=' + Date.now());
    const imageBlob = await imageResponse.blob();
    const imageBitmap = await createImageBitmap(imageBlob);

    const canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
    const ctx = canvas.getContext('2d');
    ctx.drawImage(imageBitmap, 0, 0, imageBitmap.width, imageBitmap.height);

    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const pixelData = imageData.data;
    const CanvasArray = Array.from({ length: canvas.width }, () => Array.from({ length: canvas.height }, () => 50));

    for (let y = 0; y < canvas.height; y++) {
        for (let x = 0; x < canvas.width; x++) {
            const pixelIndex = (y * canvas.width + x) * 4;
            const a = pixelData[pixelIndex + 3];

            if (a < 1) {
                continue; // water (Be careful on canvasses without preset.)
            }

            const r = pixelData[pixelIndex];
            const g = pixelData[pixelIndex + 1];
            const b = pixelData[pixelIndex + 2];
            const colornum = (r << 16) | (g << 8) | b;

            const colorIndex = colors.indexOf(colornum);
            CanvasArray[x][y] = colorIndex
        }
    }

    self.postMessage(CanvasArray);
    const canvasworkerendTime = performance.now();
    var processingTime = canvasworkerendTime - canvasworkerTimet;
    self.postMessage(processingTime);
});
`;
const cloaderblob = new Blob([cloadercode], {
    type: 'application/javascript'
});
const canvasworker = new Worker(URL.createObjectURL(cloaderblob));

;// CONCATENATED MODULE: ./src/canvas/Canvas.ts

class Canvas {
    constructor() {
        Canvas.ID = this.ParseID();
        Canvas.isProcessed = false;
        loadcanvas(this);
        Canvas.customCanvas = this.createPreviewCanvas();
    }
    ParseID() {
        return parseInt(window.location.href.split("/").slice(-1)[0].split("-")[0]);
    }
    static get instance() {
        if (!Canvas._instance)
            Canvas._instance = new Canvas;
        return Canvas._instance;
    }
    set CanvasArray(array) {
        this._CanvasArray = array;
        Canvas.isProcessed = true;
    }
    get CanvasArray() {
        return this._CanvasArray;
    }
    getColor(x, y) {
        try {
            return this._CanvasArray[x][y];
        }
        catch {
            return 50;
        }
        ;
    }
    updatePixel(x, y, color) {
        if (!Canvas.isProcessed)
            return;
        this.CanvasArray[x][y] = color;
        // console.log(this.getColor(x, y), "->", color) 
    }
    createPreviewCanvas() {
        const canvas = $(`<canvas width="2500" height="2088">`).css({ position: 'absolute', pointerEvents: 'none', left: '0px', top: '0px', imageRendering: 'pixelated', opacity: '50%' });
        $('#canvas').ready(function () {
            $('#painting-move').append(canvas);
        });
        const ctx = canvas[0].getContext("2d");
        return ctx;
    }
}
/* harmony default export */ const canvas_Canvas = (Canvas);

;// CONCATENATED MODULE: ./src/bot/util/palive.ts
// credits to symmetry
function randomString(charList, num) {
    return Array.from({ length: num }, () => charList.charAt(Math.floor(Math.random() * charList.length))).join('');
}
function randomString1(num) {
    const charList = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    return randomString(charList, num);
}
function randomString2(num) {
    const charList = 'gmbonjklezcfxta1234567890GMBONJKLEZCFXTA';
    return randomString(charList, num);
}
function randInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
const paliveCharmap = {
    "0": "g",
    "1": "n",
    "2": "b",
    "3": "r",
    "4": "z",
    "5": "s",
    "6": "l",
    "7": "x",
    "8": "i",
    "9": "o",
};
function getPalive(serverTime, userId) {
    const tDelay = getTDelay(serverTime);
    const sequenceLengths = [6, 5, 9, 4, 5, 3, 6, 6, 3];
    const currentTimestamp = Math.floor(Date.now() / 1000) + tDelay - 5400;
    const timestampString = currentTimestamp.toString();
    const timestampCharacters = timestampString.split('');
    let result = '';
    for (let i = 0; i < sequenceLengths.length; i++) {
        const sequenceNumber = sequenceLengths[i];
        result += randInt(0, 1) == 1 ? randomString2(sequenceNumber) : randomString1(sequenceNumber);
        const letter = paliveCharmap[parseInt(timestampCharacters[i])];
        result += randInt(0, 1) == 0 ? letter.toUpperCase() : letter;
    }
    result += userId.toString().substring(0, 1) + (randInt(0, 1) == 1 ? randomString2(randInt(4, 20)) : randomString1(randInt(4, 25)));
    return result + "0=";
}
function getTDelay(serverTime) {
    const currentTime = new Date().getTime() / 1e3;
    return Math.floor(serverTime - currentTime);
}

;// CONCATENATED MODULE: ./src/auth/Auth.ts
class Auth {
    constructor(authObj) {
        this.authKey = authObj.authKey;
        this.authId = authObj.authId;
        this.authToken = authObj.authToken;
    }
}

;// CONCATENATED MODULE: ./src/requests/getCookie.ts
function getCookie(name) {
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2)
        return parts.pop().split(';').shift();
}

;// CONCATENATED MODULE: ./src/requests/get-painting.ts


async function getPainting(authId, authKey, authToken) {
    const originalAuthId = getCookie('authId');
    const originalAuthKey = getCookie('authKey');
    const originalAuthToken = getCookie('authToken');
    document.cookie = `authId=${authId}; path=/`;
    document.cookie = `authKey=${authKey}; path=/`;
    document.cookie = `authToken=${authToken}; path=/`;
    try {
        const response = await fetch(`https://pixelplace.io/api/get-painting.php?id=${canvas_Canvas.ID}&connected=1`, {
            headers: {
                'Accept': 'application/json, text/javascript, */*; q=0.01',
            },
            credentials: 'include'
        });
        const json = response.json();
        return json;
    }
    finally {
        document.cookie = `authId=${originalAuthId}; path=/`;
        document.cookie = `authKey=${originalAuthKey}; path=/`;
        document.cookie = `authToken=${originalAuthToken}; path=/`;
    }
}

;// CONCATENATED MODULE: ./src/auth/util/commands.ts




const window2 = window;
var LocalAccounts = [];
// save changes in localstorage
async function storagePush() {
    localStorage.setItem('LocalAccounts', JSON.stringify(LocalAccounts));
}
// restore localstorage to localaccounts
async function storageGet() {
    LocalAccounts = JSON.parse(localStorage.getItem('LocalAccounts'));
    if (LocalAccounts === null) {
        LocalAccounts = [];
    }
}
async function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
// saves from params
async function saveAuth(username, authId, authKey, authToken, print = true) {
    if (!authId || !authKey || !authToken) {
        console.log('[7p] saveAuth ussage: saveAuth(authId, authKey, authToken)');
        return;
    }
    const account = { username, authId, authKey, authToken };
    LocalAccounts.push(account);
    storagePush();
    if (print)
        console.log('Auth saved. Saved list: ', LocalAccounts);
}
// returns client's auth
async function getAuth(print = true) {
    const cookieStore = window2.cookieStore;
    const authToken = await cookieStore.get("authToken");
    const authKey = await cookieStore.get("authKey");
    const authId = await cookieStore.get("authId");
    if (!authToken || !authKey || !authId)
        return;
    // const userinfo = await getPainting(authId.value, authKey.value, authToken.value)
    if (print)
        console.log(`authId = "${authId.value}", authKey = "${authKey.value}", authToken = "${authToken.value}"`);
    return { authToken: authToken.value, authKey: authKey.value, authId: authId.value };
}
// saves auth from client cookies
async function saveAccount() {
    storageGet();
    const AuthObj = await getAuth(false);
    const userinfo = await getPainting(AuthObj.authId, AuthObj.authKey, AuthObj.authToken);
    saveAuth(userinfo.user.name, AuthObj.authId, AuthObj.authKey, AuthObj.authToken, false);
    console.log('Auth saved. Saved list: ', LocalAccounts);
}
// logs saved auths
async function getAccounts() {
    storageGet();
    console.log(LocalAccounts);
    if (LocalAccounts == null) {
        console.log('No accounts found');
        return;
    }
    console.log(`Found ${LocalAccounts.length} acccounts`);
}
// deletes auths
async function deleteAccount(input) {
    if (input === undefined) {
        console.log('deleteAccount usage: deleteAccount(name or index)');
    }
    storageGet();
    if (typeof input == 'string') {
        const index = LocalAccounts.findIndex((account) => account.username.toLowerCase() == input.toLowerCase());
        if (index == -1) {
            console.log(`[7p] Error deleting: Found no accounts with name ${input}`);
            return;
        }
        LocalAccounts.splice(index, 1);
    }
    else if (typeof input == 'number') {
        LocalAccounts.splice(input, 1);
    }
    console.log(`Deleted account ${input}`);
    console.log(LocalAccounts);
    storagePush();
}
// connection controls
async function multibot(param, index) {
    storageGet();
    if (!param) {
        console.log('multiBot usage: ("connectall"), ("connect", index), ("disconnectall"), ("disconnect", index)');
        return;
    }
    switch (param.toLowerCase()) {
        case "connectall":
            for (const account of LocalAccounts) {
                // checks if bot is already connected
                const connectedbot = window2.seven.bots.find((bot) => bot.generalinfo?.user.name == account.username);
                if (connectedbot) {
                    console.log(`[7p] Account ${account.username} is already connected.`);
                    return;
                }
                const auth = new Auth(account);
                new bot_Bot(auth);
                await delay(500);
            }
            break;
        case "connect":
            if (index != undefined) {
                console.log('Missing bot number');
                return;
            }
            ;
            const account = LocalAccounts[index];
            const connectedbot = window2.seven.bots.find((bot) => bot.generalinfo?.user.name == account.username);
            if (connectedbot) {
                console.log(`[7p] Account ${account.username} is already connected.`);
                return;
            }
            const auth = new Auth(account);
            new bot_Bot(auth);
            break;
        case "disconnectall":
            if (window2.seven.bots.length == 1)
                return;
            index = 0;
            for (const bot of window2.seven.bots) {
                if (!bot.isClient)
                    disconnect(bot);
            }
            break;
        case "disconnect":
            if (index == undefined) {
                console.log('[7p] disconnect requires an index.');
                return;
            }
            ;
            if (index == 0) {
                console.log('[7p] You cannot disconnect the client');
                return;
            }
            disconnect(window2.seven.bots[index]);
            break;
    }
}

;// CONCATENATED MODULE: ./src/variables.ts

/* harmony default export */ const variables = (window.seven = {
    bots: [],
    pixelspeed: 21,
    queue: [],
    inprogress: false,
    protect: false,
    tickspeed: 1000,
    saveAuth: saveAuth,
    getAuth: getAuth,
    saveAccount: saveAccount,
    getAccounts: getAccounts,
    deleteAccount: deleteAccount,
    multibot: multibot,
});

;// CONCATENATED MODULE: ./src/bot/util/onmessage.ts





const seven = window.seven;
// client
function onClientMessage(event) {
    const msg = event.data;
    const bot = bot_Bot.botClient;
    if (msg.startsWith("42")) {
        const msg = JSON.parse(event.data.substr(2));
        const type = msg[0];
        switch (type) {
            case "p":
                for (const pixel of msg[1]) {
                    const canvas = canvas_Canvas.instance;
                    const x = pixel[0];
                    const y = pixel[1];
                    const color = pixel[2];
                    const id = pixel[4];
                    canvas.updatePixel(x, y, color);
                }
                break;
            case "canvas":
                for (const pixel of msg[1]) {
                    const canvas = canvas_Canvas.instance;
                    const x = pixel[0];
                    const y = pixel[1];
                    const color = pixel[2];
                    canvas.updatePixel(x, y, color);
                }
                break;
        }
    }
}
// multibot
function onBotMessage(event, bot) {
    const message = event.data;
    // game packets
    if (message.startsWith("42")) {
        const message = JSON.parse(event.data.substr(2));
        const type = message[0];
        switch (type) {
            case "server_time":
                bot.paliveServerTime = message[1]; // stores servertime for palive
                break;
            case "ping.alive":
                const hash = getPalive(bot.paliveServerTime, bot.generalinfo.user.id);
                console.log('[7p]', bot.generalinfo.user.name, ': pong =', hash, bot.generalinfo.user.id);
                bot.emit('pong.alive', `"${hash}"`);
                break;
            case "throw.error":
                console.log(`[7p] [Bot ${bot.botid}] Pixelplace WS error: ${message[1]}`);
                disconnect(bot);
                break;
            case "canvas":
                seven.bots.push(bot);
                break;
        }
    }
    // start
    if (message.startsWith("0"))
        bot.ws.send('40');
    // auth
    if (message.startsWith("40"))
        bot.ws.send(`42["init",{"authKey":"${bot.auth.authKey}","authToken":"${bot.auth.authToken}","authId":"${bot.auth.authId}","boardId":${canvas_Canvas.ID}}]`);
    // keep alive
    if (message.startsWith("2"))
        bot.ws.send('3');
}

;// CONCATENATED MODULE: ./src/bot/util/websocket.ts



const websocket_seven = window.seven;
// client
const customWS = window.WebSocket;
window.WebSocket = function (url, protocols) {
    const client = bot_Bot.botClient;
    const socket = new customWS(url, protocols);
    socket.addEventListener("message", (event) => { onClientMessage(event); });
    client.ws = socket;
    return socket;
};
// multibot
async function connect(bot) {
    console.log(`[7p] Attempting to connect account ${bot.generalinfo.user.name}`);
    const socket = new customWS("wss://pixelplace.io/socket.io/?EIO=4&transport=websocket");
    socket.addEventListener("message", (event) => { onBotMessage(event, bot); });
    return socket;
}
function disconnect(bot) {
    if (!bot) {
        console.log('[7p] Cannot close bot that doesnt exist.');
        return;
    }
    bot.ws.close();
    const result = websocket_seven.bots.filter((checkedBot) => checkedBot.botid != bot.botid);
    websocket_seven.bots = result;
    console.log('[7placer] Ended bot ', bot.botid);
}

;// CONCATENATED MODULE: ./src/css/css.ts
const trackercss = {
    top: '0px',
    left: '0px',
    borderColor: 'rgb(138,43,226)',
    color: 'rgb(138,43,226)',
    backgroundColor: 'black',
    opacity: '60%',
    display: 'none',
    transition: 'all 0.06s ease-in-out',
    pointerEvents: 'none'
};
// design by 0vc4
const drop = {
    width: 'calc(100% - 2em)',
    height: 'calc(100% - 2em)',
    position: 'fixed',
    left: '0px',
    top: '0px',
    backgroundColor: 'rgba(0, 0, 0, 0.533)',
    zIndex: '9999-',
    display: 'flex',
    color: 'white',
    fontSize: '48pt',
    justifyContent: 'center',
    alignItems: 'center',
    border: '3px white dashed',
    borderRadius: '18px',
    margin: '1em'
};

;// CONCATENATED MODULE: ./src/bot/Bot.ts






const Bot_seven = window.seven;
class Bot {
    constructor(auth) {
        this.isClient = false;
        this.lastplace = Date.now();
        this._canvas = canvas_Canvas.instance;
        this.botid = Bot.botIndex;
        Bot.botIndex += 1; // id for next bot
        if (!auth) {
            Bot._client = this;
            this.isClient = true;
            this.tracker = this.createGUItracker(true);
            Bot_seven.bots.push(this);
        }
        else {
            this._auth = auth;
            this.startBot();
        }
        ;
    }
    async startBot() {
        this.generalinfo = await getPainting(this.auth.authId, this.auth.authKey, this.auth.authToken);
        this.tracker = this.createGUItracker();
        this._ws = await connect(this);
    }
    emit(event, params) {
        this.ws.send(`42["${event}",${params}]`);
    }
    placePixel(x, y, color, tracker = true) {
        const canvascolor = this._canvas.getColor(x, y);
        if (Date.now() - this.lastplace < Bot_seven.pixelspeed)
            return false;
        if (canvascolor == color || canvascolor == 50)
            return true;
        if (tracker)
            $(this.tracker).css({ top: y, left: x, display: 'block', });
        // console.log(`[7p] placing: ${canvascolor} -> ${color}`)
        this.emit('p', `[${x},${y},${color},1]`);
        this.lastplace = Date.now();
        return true;
    }
    createGUItracker(client = false) {
        var name = client == true ? 'Client' : this.generalinfo.user.name;
        const tracker = $('<div class="track" id="bottracker">').text(`[7P] ${name}`).css(trackercss);
        $('#canvas').ready(function () {
            // console.log(`[7p] created tracker: ${name}`)
            $('#painting-move').append(tracker);
        });
        return tracker;
    }
    static get botClient() {
        if (!Bot._client)
            new Bot();
        return Bot._client;
    }
    get auth() {
        return this._auth;
    }
    set ws(wss) {
        this._ws = wss;
    }
    get ws() {
        return this._ws;
    }
}
Bot.botIndex = 0;
/* harmony default export */ const bot_Bot = (Bot);

;// CONCATENATED MODULE: ./src/modules/defaultModules/SevenQueue.ts


const SevenQueue_seven = window.seven;
class Queue {
    constructor() {
        Queue.queueindex = 0;
        Queue.botindex = 0;
        Queue.tick = 0;
    }
    static add(x, y, color) {
        SevenQueue_seven.queue.push({ x: x, y: y, color: color });
    }
    static clear() {
        // console.log('Queue cleared: ', seven.queue)
        SevenQueue_seven.queue = [];
    }
    static async start() {
        if (!canvas_Canvas.isProcessed) {
            console.log('[7p] Error starting queue: Canvas has not been processed yet.');
            Queue.stop();
            return;
        }
        Queue.queueindex = 0;
        Queue.botindex = 0;
        Queue.tick = 0;
        const Bots = SevenQueue_seven.bots;
        // seven.queue.sort(() => Math.random() - 0.5); - rand
        // seven.queue.sort((a: { color: number }, b: { color: number }) => a.color - b.color); - colors
        // circle
        let CX = Math.floor((SevenQueue_seven.queue[0].x + SevenQueue_seven.queue[SevenQueue_seven.queue.length - 1].x) / 2);
        let CY = Math.floor((SevenQueue_seven.queue[0].y + SevenQueue_seven.queue[SevenQueue_seven.queue.length - 1].y) / 2);
        SevenQueue_seven.queue.sort((a, b) => {
            const distanceA = Math.sqrt((a.x - CX) ** 2 + (a.y - CY) ** 2);
            const distanceB = Math.sqrt((b.x - CX) ** 2 + (b.y - CY) ** 2);
            return distanceA - distanceB;
        });
        SevenQueue_seven.inprogress = true;
        while (SevenQueue_seven.inprogress == true && SevenQueue_seven.queue.length > 0) {
            const bot = Bots[Queue.botindex];
            const pixel = SevenQueue_seven.queue[Queue.queueindex];
            const response = bot.placePixel(pixel.x, pixel.y, pixel.color);
            Queue.botindex += 1;
            if (Queue.botindex == Bots.length)
                Queue.botindex = 0;
            if (response && Queue.queueindex < SevenQueue_seven.queue.length)
                Queue.queueindex += 1; // next pixel
            // handles depending on protect or not
            if (!SevenQueue_seven.protect && Queue.queueindex == SevenQueue_seven.queue.length) {
                Queue.stop();
                console.log('[7p] Queue done.');
            }
            else if (SevenQueue_seven.protect == true && Queue.queueindex == SevenQueue_seven.queue.length) {
                Queue.queueindex = 0;
            }
            // tick management 
            if (Queue.tick >= SevenQueue_seven.tickspeed) {
                Queue.tick = 0;
                await new Promise(resolve => setTimeout(resolve, 0));
            }
            Queue.tick += 1;
        }
    }
    static stop() {
        SevenQueue_seven.inprogress = false;
        canvas_Canvas.customCanvas.clearRect(0, 0, 3000, 3000);
        Queue.clear();
    }
}
/* harmony default export */ const SevenQueue = (Queue);

;// CONCATENATED MODULE: ./src/modules/defaultModules/SevenImageTools.ts



const SevenImageTools_seven = window.seven;
const colors = [
    0xFFFFFF, 0xC4C4C4, 0x888888, 0x555555, 0x222222, 0x000000, 0x006600, 0x22B14C,
    0x02BE01, 0x51E119, 0x94E044, 0xFBFF5B, 0xE5D900, 0xE6BE0C, 0xE59500, 0xA06A42,
    0x99530D, 0x633C1F, 0x6B0000, 0x9F0000, 0xE50000, 0xFF3904, 0xBB4F00, 0xFF755F,
    0xFFC49F, 0xFFDFCC, 0xFFA7D1, 0xCF6EE4, 0xEC08EC, 0x820080, 0x5100FF, 0x020763,
    0x0000EA, 0x044BFF, 0x6583CF, 0x36BAFF, 0x0083C7, 0x00D3DD, 0x45FFC8, 0x003638,
    0x477050, 0x98FB98, 0xFF7000, 0xCE2939, 0xFF416A, 0x7D26CD, 0x330077, 0x005BA1,
    0xB5E8EE, 0x1B7400
];
function getColorDistance(c1, c2) {
    // Image Color
    const r1 = (c1 >> 16) & 0xFF;
    const g1 = (c1 >> 8) & 0xFF;
    const b1 = c1 & 0xFF;
    // Pixelplace Color
    const r2 = (c2 >> 16) & 0xFF;
    const g2 = (c2 >> 8) & 0xFF;
    const b2 = c2 & 0xFF;
    return (r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2;
}
function findClosestColor(color) {
    let minDistance = Infinity;
    let colorNumber;
    let index = 0;
    for (const pxpColor of colors) {
        const distance = getColorDistance(color, pxpColor);
        if (distance < minDistance) {
            minDistance = distance;
            colorNumber = index;
        }
        index += 1;
    }
    return colorNumber;
}
function previewCanvasImage(x, y, image) {
    const ctx = canvas_Canvas.customCanvas;
    const img = new Image();
    img.onload = function () {
        ctx.drawImage(img, x, y);
    };
    img.src = URL.createObjectURL(image);
}
async function ImageToPixels(image) {
    const result = [];
    const canvas = new OffscreenCanvas(image.width, image.height);
    const ctx = canvas.getContext('2d');
    ctx.drawImage(image, 0, 0, image.width, image.height);
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const pixelData = imageData.data;
    for (let y = 0; y < canvas.height; y++) {
        for (let x = 0; x < canvas.width; x++) {
            const pixelIndex = (y * canvas.width + x) * 4;
            const r = pixelData[pixelIndex];
            const g = pixelData[pixelIndex + 1];
            const b = pixelData[pixelIndex + 2];
            const a = pixelData[pixelIndex + 3];
            const colornum = (r << 16) | (g << 8) | b;
            if (a < 1) {
                continue; // ignore transparent pixels
            }
            const color = findClosestColor(colornum);
            result.push({ x, y, color });
        }
    }
    return result;
}
async function botImage(x, y, image) {
    const bitmap = await createImageBitmap(image);
    const processed = await ImageToPixels(bitmap);
    previewCanvasImage(x, y, image);
    processed.forEach((pixel) => SevenQueue.add(pixel.x + x, pixel.y + y, pixel.color));
    SevenQueue.start();
}

;// CONCATENATED MODULE: ./src/modules/defaultModules/SevenSquareMaker.ts

function BotSquare(x1, y1, x2, y2, color) {
    if (x2 < x1)
        [x1, x2] = [x2, x1];
    if (y2 < y1)
        [y1, y2] = [y2, y1];
    for (let x = x1; x <= x2; x++) {
        for (let y = y1; y <= y2; y++) {
            SevenQueue.add(x, y, color);
        }
    }
    SevenQueue.start();
}

;// CONCATENATED MODULE: ./src/modules/util/getClientMouse.ts
function getClientMouse() {
    const coordinates = $('#coordinates').text();
    const [x, y] = coordinates.split(',').map(coord => parseInt(coord.trim()));
    const selectedcolor = $('#palette-buttons a.selected').data('id');
    return [x, y, selectedcolor];
}

;// CONCATENATED MODULE: ./src/css/drop.ts



function createDropArea() {
    const dropobject = $('<div>').text('Drop Image').css(drop);
    const [x, y] = getClientMouse();
    $('body').append(dropobject);
    dropobject.on("click", function () {
        dropobject.remove();
    });
    dropobject.on("drop", async function (event) {
        event.preventDefault();
        event.stopPropagation();
        const image = event.originalEvent.dataTransfer.files[0];
        dropobject.remove();
        await botImage(x, y, image);
        // console.log(image)
    }).on('dragover', false);
}

;// CONCATENATED MODULE: ./src/modules/defaultModules/defaultKeys.ts




var coord1 = null;
$(document).on('keyup', function (event) {
    if ($(':input[type="text"]').is(':focus'))
        return; //; prevent with chat open
    switch (event.which) {
        case (87):
            if (!event.altKey)
                return;
            SevenQueue.stop();
            break;
        case (66):
            if (!event.altKey)
                return;
            createDropArea();
            break;
        case 88:
            const [x, y, color] = getClientMouse();
            if (coord1 == null) {
                coord1 = { x: x, y: y };
                return;
            }
            BotSquare(coord1.x, coord1.y, x, y, color);
            coord1 = null;
            break;
        // add more 
    }
});

;// CONCATENATED MODULE: ./src/modules/defaultModules/index.ts





;// CONCATENATED MODULE: ./src/modules/index.ts

// custom exports

;// CONCATENATED MODULE: ./src/index.ts






Object.defineProperty(window.console, 'log', {
    configurable: false,
    enumerable: true,
    writable: false,
    value: console.log
});






/******/ })()
;