7Placer

typescript pixelplace.io bot

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

您需要先安裝使用者腳本管理器擴展,如 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       1.4.0a
// @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/css/style.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',
};
const canvascss = {
    position: 'absolute',
    pointerEvents: 'none',
    left: '0px',
    top: '0px',
    imageRendering: 'pixelated',
    opacity: '50%',
    animation: 'blink 3s ease-out infinite'
};
const blink = document.createElement("style");
blink.type = "text/css";
blink.innerText = `
@keyframes blink {
  0% { opacity: .30; }
  50% { opacity: .10; }
  100% { opacity: .30; }
}`;
document.head.appendChild(blink);

;// 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(canvascss);
        $('#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 = new Map();
// save changes in localstorage
function storagePush() {
    const obj = Object.fromEntries(LocalAccounts);
    localStorage.setItem('LocalAccounts', JSON.stringify(obj));
}
// restore localstorage to localaccounts
function storageGet() {
    const storedAccounts = localStorage.getItem('LocalAccounts');
    if (storedAccounts) {
        const parsedAccounts = JSON.parse(storedAccounts);
        LocalAccounts = new Map(Object.entries(parsedAccounts));
    }
    else
        LocalAccounts = new Map();
}
async function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
// saves from params
function saveAuth(username, authId, authKey, authToken, print = true) {
    if (!authId || !authKey || !authToken) {
        console.log('[7p] saveAuth usage: saveAuth(username, authId, authKey, authToken)');
        return;
    }
    const account = { authId, authKey, authToken };
    LocalAccounts.set(username, 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 == null || authKey == null || authId == null) {
        console.log('[7p] Please login first!');
        return;
    }
    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
function getAccounts() {
    storageGet();
    if (!LocalAccounts || LocalAccounts.size == 0) {
        console.log('No accounts found');
        return;
    }
    console.log(`Found ${LocalAccounts.size} accounts`);
    console.log(LocalAccounts);
}
// deletes auths
function deleteAccount(identifier) {
    if (identifier == null) {
        console.log('deleteAccount usage: deleteAccount(user or index)');
        return;
    }
    storageGet();
    if (typeof identifier == 'string') {
        if (identifier == 'all') {
            LocalAccounts.forEach((value, key) => {
                LocalAccounts.delete(key);
            });
            return;
        }
        if (!LocalAccounts.has(identifier)) {
            console.log(`[7p] Error deleting: No account with name ${identifier}`);
            return;
        }
        LocalAccounts.delete(identifier);
        console.log(`[7p] Deleted account ${identifier}.`);
        console.log(LocalAccounts);
    }
    if (typeof identifier == 'number') {
        const keys = Array.from(LocalAccounts.keys());
        if (identifier > keys.length) {
            console.log(`[7p] Error deleting: No account with index ${identifier}`);
            return;
        }
        LocalAccounts.delete(keys[identifier]);
        console.log(`Deleted account ${identifier}`);
        console.log(LocalAccounts);
    }
    storagePush();
}
async function connect(username) {
    storageGet();
    const account = LocalAccounts.get(username);
    const connectedbot = window2.seven.bots.find((bot) => bot.generalinfo?.user.name == username);
    if (!username) {
        console.log('[7p] Missing bot username, connect("username")');
        return;
    }
    if (username == 'all') {
        for (const [username, account] of LocalAccounts) {
            // checks if bot is already connected
            const connectedbot = window2.seven.bots.find((bot) => bot.generalinfo?.user.name == username);
            const auth = new Auth(account);
            if (connectedbot) {
                console.log(`[7p] Account ${username} is already connected.`);
                continue;
            }
            new WSBot(auth, username);
            await delay(500);
        }
        return;
    }
    if (!account) {
        console.log(`[7p] No account found with username ${username}`);
        return;
    }
    if (connectedbot) {
        console.log(`[7p] Account ${username} is already connected.`);
        return;
    }
    const auth = new Auth(account);
    new WSBot(auth, username);
}
function disconnect(username) {
    const bot = window2.seven.bots.find((bot) => bot.generalinfo?.user.name == username);
    if (!username) {
        console.log('[7p] disconnect requires a username, disconnect("username")');
        return;
    }
    if (username == 'all') {
        if (window2.seven.bots.length == 1) {
            console.log('[7p] No bots connected.');
            return;
        }
        for (const bot of window2.seven.bots) {
            closeBot(bot);
        }
        return;
    }
    if (!bot) {
        console.log(`[7p] No bot connected with username ${username}`);
        return;
    }
    closeBot(bot);
}

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

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

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






const seven = window.seven;
// client
function onClientMessage(event) {
    const msg = event.data;
    const bot = Client.instance;
    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
async 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];
        const botid = bot.generalinfo.user.id;
        const botname = bot.username;
        switch (type) {
            case "server_time":
                bot.paliveServerTime = message[1]; // stores servertime for palive
                break;
            case "ping.alive":
                const hash = getPalive(bot.paliveServerTime, botid);
                console.log('[7p]', botname, ': pong =', hash, botid);
                bot.emit('pong.alive', `"${hash}"`);
                break;
            case "throw.error":
                if (message[1] == 49) {
                    console.log(`[7p] [Bot ${botname}] Error (${message[1]}): This auth is not valid! Deleting account from saved accounts...`);
                    deleteAccount(botname);
                    closeBot(bot);
                    return;
                }
                console.log(`[7p] [Bot ${botname}] Pixelplace WS error: ${message[1]}`);
                break;
            case "canvas":
                console.log(`[7p] Succesfully connected to bot ${bot.username}`);
                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 = new Client();
    const socket = new customWS(url, protocols);
    socket.addEventListener("message", (event) => { onClientMessage(event); });
    client.ws = socket;
    return socket;
};
// multibot
async function hookBot(bot) {
    console.log(`[7p] Attempting to connect account ${bot.username}`);
    const socket = new customWS("wss://pixelplace.io/socket.io/?EIO=4&transport=websocket");
    socket.addEventListener("message", (event) => { onBotMessage(event, bot); });
    socket.addEventListener("close", () => { Bot.botIndex -= 1; });
    return socket;
}
function closeBot(bot) {
    if (bot instanceof Client)
        return;
    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/bot/Bot.ts






const Bot_seven = window.seven;
class Bot {
    constructor() {
        this.trackeriters = 0;
        this.lastplace = Date.now();
        this.botid = Bot.botIndex;
        Bot.botIndex += 1; // id for next bot
    }
    emit(event, params) {
        this.ws.send(`42["${event}",${params}]`);
    }
    placePixel(x, y, color, tracker = true) {
        const canvas = canvas_Canvas.instance;
        const canvascolor = canvas.getColor(x, y);
        if (Date.now() - this.lastplace < Bot_seven.pixelspeed)
            return false;
        if (canvascolor == color || canvascolor == 50)
            return true;
        if (tracker && this.trackeriters >= 6) {
            $(this.tracker).css({ top: y, left: x, display: 'block' });
            this.trackeriters = 0;
        }
        this.trackeriters += 1;
        this.emit('p', `[${x},${y},${color},1]`);
        this.lastplace = Date.now();
        // console.log(`[7p] placing: ${canvascolor} -> ${color}`)
        return true;
    }
    createTracker() {
        const tracker = $('<div class="track" id="bottracker">').text(`[7P] ${this.username}`).css(trackercss);
        $('#canvas').ready(function () {
            // console.log(`[7p] created tracker: ${name}`)
            $('#painting-move').append(tracker);
        });
        return tracker;
    }
    set ws(wss) {
        this._ws = wss;
    }
    get ws() {
        return this._ws;
    }
}
Bot.botIndex = 0;
class WSBot extends Bot {
    constructor(auth, username) {
        super();
        if (!username || !auth) {
            console.error("[7p ERROR]: 'auth' and 'username' should both be in the constructor arguments.");
            return;
        }
        this._auth = auth;
        this.username = username;
        this.startBot();
    }
    async startBot() {
        this.generalinfo = await getPainting(this.auth.authId, this.auth.authKey, this.auth.authToken);
        this.tracker = this.createTracker();
        this.ws = await hookBot(this);
    }
    get auth() {
        return this._auth;
    }
}
class Client extends Bot {
    constructor() {
        super();
        this.username = 'Client';
        Client.instance = this;
        this.tracker = this.createTracker();
        Bot_seven.bots.push(this);
    }
    static get Client() {
        return Client.instance;
    }
}

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


const SevenQueue_seven = window.seven;
class Queue {
    constructor() {
    }
    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;
        }
        const Bots = SevenQueue_seven.bots;
        var position = 0;
        var tick = 0;
        var botpos = 0;
        await Queue.sort();
        SevenQueue_seven.inprogress = true;
        while (SevenQueue_seven.inprogress == true && SevenQueue_seven.queue.length > 0) {
            if (botpos == Bots.length)
                botpos = 0;
            if (!SevenQueue_seven.protect && position == SevenQueue_seven.queue.length) {
                Queue.stop();
                console.log('[7p] Queue done.');
            }
            else if (SevenQueue_seven.protect == true && position == SevenQueue_seven.queue.length) {
                position = 0;
            }
            const bot = Bots[botpos];
            const pixel = SevenQueue_seven.queue[position];
            const response = bot.placePixel(pixel.x, pixel.y, pixel.color);
            botpos += 1;
            if (response)
                position += 1;
            // tick management 
            if (tick >= SevenQueue_seven.tickspeed) {
                tick = 0;
                await new Promise(resolve => setTimeout(resolve, 0));
            }
            tick += 1;
        }
    }
    static async sort() {
        const array = SevenQueue_seven.queue;
        switch (SevenQueue_seven.order) {
            case 'rand':
                array.sort(() => Math.random() - 0.5);
                break;
            case 'colors':
                array.sort((a, b) => a.color - b.color);
                break;
            case 'vertical':
                array.sort((a, b) => a.x - b.x);
                break;
            case 'horizontal':
                array.sort((a, b) => a.y - b.y);
                break;
            default:
            case 'circle':
                const CX = Math.floor((array[0].x + array[array.length - 1].x) / 2);
                const CY = Math.floor((array[0].y + array[array.length - 1].y) / 2);
                array.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;
                });
                break;
        }
    }
    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
});






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