Guest User

Untitled

a guest
May 7th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function Run() {
  2.     var config = {
  3.         //координати в грі
  4.         x: 24711,
  5.         y: -18040,
  6.         //посилання на зображення
  7.         //конвертувати зображення можна тут -> https://pixelplanet.fun/convert
  8.         image: "https://i.imgur.com/k1LhvQc.png",
  9.         //токен
  10.         token: null,
  11.         //затримка після появи помилки
  12.         errCooldown: 15 * 1000,
  13.         //початкові позиції на зображенні
  14.         startY: 0,
  15.         startX: 0,
  16.     }
  17.  
  18.     //вирвано з коду гри
  19.     //індекс - clr в пакетi
  20.     const colors = [
  21.         [202, 227, 255],
  22.         [255, 255, 255],
  23.         [255, 255, 255],
  24.         [228, 228, 228],
  25.         [196, 196, 196],
  26.         [136, 136, 136],
  27.         [78, 78, 78],
  28.         [0, 0, 0],
  29.         [244, 179, 174],
  30.         [255, 167, 209],
  31.         [255, 84, 178],
  32.         [255, 101, 101],
  33.         [229, 0, 0],
  34.         [154, 0, 0],
  35.         [254, 164, 96],
  36.         [229, 149, 0],
  37.         [160, 106, 66],
  38.         [96, 64, 40],
  39.         [245, 223, 176],
  40.         [255, 248, 137],
  41.         [229, 217, 0],
  42.         [148, 224, 68],
  43.         [2, 190, 1],
  44.         [104, 131, 56],
  45.         [0, 101, 19],
  46.         [202, 227, 255],
  47.         [0, 211, 221],
  48.         [0, 131, 199],
  49.         [0, 0, 234],
  50.         [25, 25, 115],
  51.         [207, 110, 228],
  52.         [130, 0, 128]
  53.     ];
  54.  
  55.     //створення невидимого канвасу для майбутнього зображення
  56.     var canvas = document.createElement('canvas');
  57.  
  58.     var img = new Image();
  59.     img.crossOrigin = "anonymous";
  60.     img.src = config.image;
  61.  
  62.     //завантаження зображення на канвас
  63.     var image;
  64.     img.onload = function () {
  65.         canvas.width = img.width;
  66.         canvas.height = img.height;
  67.  
  68.         image = canvas.getContext('2d');
  69.         image.drawImage(img, 0, 0, img.width, img.height);
  70.  
  71.         asyncDraw();
  72.     };
  73.  
  74.     //отримання clr-індексу за координатами на зображенні
  75.     function getClr(coords, image) {
  76.         let pixel = image.getImageData(coords.x, coords.y, 1, 1).data;
  77.         let colorId = -1;
  78.         let valid = false;
  79.         for (let i = 0; i < colors.length; i++) {
  80.             valid = true;
  81.             for (let j = 0; j < 3; j++) {
  82.                 if (pixel[j] != colors[i][j]) {
  83.                     valid = false;
  84.                     break;
  85.                 }
  86.             }
  87.             if (valid) {
  88.                 colorId = i;
  89.                 break;
  90.             }
  91.         }
  92.         if (colorId < 0) {
  93.             console.log("піксель на координатах x:" + coords.x + " y: " + coords.y + " має неприпустимий колір.");
  94.         }
  95.  
  96.         return colorId;
  97.     }
  98.  
  99.     //відправка поста
  100.     async function asyncSendReq(x, y, clr, token) {
  101.         let resp = await fetch("https://pixelplanet.fun/api/pixel", {
  102.             method: "post",
  103.             headers: new Headers({
  104.                 "content-type": "application/json",
  105.                 "pragma": "no-cache"
  106.             }),
  107.             body: JSON.stringify({
  108.                 clr: clr,
  109.                 x: x,
  110.                 y: y,
  111.                 token: token, //?
  112.                 cn: 0 //?
  113.             })
  114.         });
  115.         return await resp.json();
  116.     }
  117.  
  118.     async function asyncDraw() {
  119.         let currentY = config.startY;
  120.         let currentX = config.startX;
  121.  
  122.         for (let _y = Math.min(currentY, canvas.height); _y < canvas.height; _y++) {
  123.             for (let _x = Math.min(currentX, canvas.width); _x < canvas.width; _x++) {
  124.                 let coords = {
  125.                     x: _x,
  126.                     y: _y
  127.                 };
  128.  
  129.                 let clr = getClr(coords, image);
  130.                 if (clr > 0) {
  131.                     let gameX = (config.x + coords.x);
  132.                     let gameY = (config.y + coords.y);
  133.  
  134.                     let flag = false;
  135.                     do {
  136.                         var resp = await asyncSendReq(gameX, gameY, clr, config.token);
  137.                         if (resp.errors && resp.errors.length > 0) {
  138.                             if (resp.errors[0].msg.includes("Captcha")) {
  139.                                 console.log("!!! ВВЕДИ КАПЧУ !!!");
  140.                                 errorShow();
  141.                             } else {
  142.                                 console.log(resp.errors[0].msg);
  143.                                 break;
  144.                             }
  145.                             await new Promise((resolve, reject) => setTimeout(resolve, config.errCooldown));
  146.                         } else if (resp.coolDownSeconds) {
  147.                             await new Promise((resolve, reject) => setTimeout(resolve, Math.abs(resp.coolDownSeconds) * 1000));
  148.                             flag = true
  149.                         }
  150.                     } while (!flag || !resp.success);
  151.                     console.log("намальовано (x:" + _x + " y:" + _y + "). на ігрових координатах x:" + gameX + " y:" + gameY);
  152.                 }
  153.             }
  154.             currentX = 0;
  155.         }
  156.  
  157.         console.log("done");
  158.         return;
  159.     }
  160.  
  161.     function errorShow() {
  162.         alert("Введи капчу!");
  163.     }
  164. })();
Add Comment
Please, Sign In to add comment