Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function Run() {
- var config = {
- //координати в грі
- x: 24711,
- y: -18040,
- //посилання на зображення
- //конвертувати зображення можна тут -> https://pixelplanet.fun/convert
- image: "https://i.imgur.com/k1LhvQc.png",
- //токен
- token: null,
- //затримка після появи помилки
- errCooldown: 15 * 1000,
- //початкові позиції на зображенні
- startY: 0,
- startX: 0,
- }
- //вирвано з коду гри
- //індекс - clr в пакетi
- const colors = [
- [202, 227, 255],
- [255, 255, 255],
- [255, 255, 255],
- [228, 228, 228],
- [196, 196, 196],
- [136, 136, 136],
- [78, 78, 78],
- [0, 0, 0],
- [244, 179, 174],
- [255, 167, 209],
- [255, 84, 178],
- [255, 101, 101],
- [229, 0, 0],
- [154, 0, 0],
- [254, 164, 96],
- [229, 149, 0],
- [160, 106, 66],
- [96, 64, 40],
- [245, 223, 176],
- [255, 248, 137],
- [229, 217, 0],
- [148, 224, 68],
- [2, 190, 1],
- [104, 131, 56],
- [0, 101, 19],
- [202, 227, 255],
- [0, 211, 221],
- [0, 131, 199],
- [0, 0, 234],
- [25, 25, 115],
- [207, 110, 228],
- [130, 0, 128]
- ];
- //створення невидимого канвасу для майбутнього зображення
- var canvas = document.createElement('canvas');
- var img = new Image();
- img.crossOrigin = "anonymous";
- img.src = config.image;
- //завантаження зображення на канвас
- var image;
- img.onload = function () {
- canvas.width = img.width;
- canvas.height = img.height;
- image = canvas.getContext('2d');
- image.drawImage(img, 0, 0, img.width, img.height);
- asyncDraw();
- };
- //отримання clr-індексу за координатами на зображенні
- function getClr(coords, image) {
- let pixel = image.getImageData(coords.x, coords.y, 1, 1).data;
- let colorId = -1;
- let valid = false;
- for (let i = 0; i < colors.length; i++) {
- valid = true;
- for (let j = 0; j < 3; j++) {
- if (pixel[j] != colors[i][j]) {
- valid = false;
- break;
- }
- }
- if (valid) {
- colorId = i;
- break;
- }
- }
- if (colorId < 0) {
- console.log("піксель на координатах x:" + coords.x + " y: " + coords.y + " має неприпустимий колір.");
- }
- return colorId;
- }
- //відправка поста
- async function asyncSendReq(x, y, clr, token) {
- let resp = await fetch("https://pixelplanet.fun/api/pixel", {
- method: "post",
- headers: new Headers({
- "content-type": "application/json",
- "pragma": "no-cache"
- }),
- body: JSON.stringify({
- clr: clr,
- x: x,
- y: y,
- token: token, //?
- cn: 0 //?
- })
- });
- return await resp.json();
- }
- async function asyncDraw() {
- let currentY = config.startY;
- let currentX = config.startX;
- for (let _y = Math.min(currentY, canvas.height); _y < canvas.height; _y++) {
- for (let _x = Math.min(currentX, canvas.width); _x < canvas.width; _x++) {
- let coords = {
- x: _x,
- y: _y
- };
- let clr = getClr(coords, image);
- if (clr > 0) {
- let gameX = (config.x + coords.x);
- let gameY = (config.y + coords.y);
- let flag = false;
- do {
- var resp = await asyncSendReq(gameX, gameY, clr, config.token);
- if (resp.errors && resp.errors.length > 0) {
- if (resp.errors[0].msg.includes("Captcha")) {
- console.log("!!! ВВЕДИ КАПЧУ !!!");
- errorShow();
- } else {
- console.log(resp.errors[0].msg);
- break;
- }
- await new Promise((resolve, reject) => setTimeout(resolve, config.errCooldown));
- } else if (resp.coolDownSeconds) {
- await new Promise((resolve, reject) => setTimeout(resolve, Math.abs(resp.coolDownSeconds) * 1000));
- flag = true
- }
- } while (!flag || !resp.success);
- console.log("намальовано (x:" + _x + " y:" + _y + "). на ігрових координатах x:" + gameX + " y:" + gameY);
- }
- }
- currentX = 0;
- }
- console.log("done");
- return;
- }
- function errorShow() {
- alert("Введи капчу!");
- }
- })();
Add Comment
Please, Sign In to add comment