Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Pixel Bot
  3. // @namespace    http://tampermonkey.net/
  4. // @version      999
  5. // @description  try to take over the world!
  6. // @author       Flyink13, DarkKeks
  7. // @match        https://pixel.vkforms.ru/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. function MyPixelBot() {
  12.     window.MyPixelBot = MyPixelBot;
  13.  
  14.     MyPixelBot.url = {
  15.         script: 'https://raw.githubusercontent.com/DarkKeks/PublicPixelBot/master/PixelBot.user.js',
  16.         image:  'https://i.imgur.com/XxFmnVC.png'
  17.     };
  18.  
  19.     MyPixelBot.refreshTime = 300;
  20.  
  21.     MyPixelBot.pts = 30;
  22.     MyPixelBot.tc = "rgb(0, 0, 0)";
  23.  
  24.     MyPixelBot.debug = false;
  25.     MyPixelBot.doCoordLog = true;
  26.  
  27.     MyPixelBot.urlGen = {
  28.         script: function() {
  29.             return MyPixelBot.url.script + '?v=' + Math.random();
  30.         },
  31.         image: function() {
  32.             return MyPixelBot.url.image;
  33.         }
  34.     };
  35.  
  36.     MyPixelBot.state = document.createElement("div");
  37.     MyPixelBot.state.onclick = MyPixelBot.reload;
  38.     MyPixelBot.state.textContent = "Загрузка приложения...";
  39.     Object.assign(MyPixelBot.state.style, {
  40.         background: "rgba(0,0,0,0.5)",
  41.         bottom: "0px",
  42.         right: "0px",
  43.         width: "100%",
  44.         height: "100%",
  45.         lineHeight: "500px",
  46.         textAlign: "center",
  47.         color: "#fff",
  48.         position: "fixed",
  49.         zIndex: 10000
  50.     });
  51.     document.body.appendChild(MyPixelBot.state);
  52.  
  53.  
  54.     MyPixelBot.loger = document.createElement("div");
  55.     MyPixelBot.loger.onclick = MyPixelBot.reload;
  56.     Object.assign(MyPixelBot.loger.style, {
  57.         background: "rgba(0,0,0,0)",
  58.         top: "0px",
  59.         left: "0px",
  60.         width: "250px",
  61.         height: "100%",
  62.         color: "#fff",
  63.         position: "fixed",
  64.         borderRight: "1px solid #fff",
  65.         fontSize: "11px",
  66.         padding: "12px",
  67.         zIndex: 10001
  68.     });
  69.     document.body.appendChild(MyPixelBot.loger);
  70.  
  71.     MyPixelBot.log = function(x) {
  72.         MyPixelBot.loger.innerHTML += x + "<br>";
  73.         MyPixelBot.loger.scrollTo(0, 10000);
  74.     };
  75.  
  76.     MyPixelBot.setState = function(s) {
  77.         MyPixelBot.state.innerHTML = "MyPixelBot " + s;
  78.         MyPixelBot.log(s);
  79.     };
  80.  
  81.  
  82.     MyPixelBot.reloadImage = function() {
  83.         MyPixelBot.img = new Image();
  84.         MyPixelBot.img.crossOrigin = "Anonymous";
  85.         MyPixelBot.img.onload = function() {
  86.             MyPixelBot.setState("Перезагрузил зону защиты.");
  87.             if (MyPixelBot.inited) MyPixelBot.getFullData();
  88.         };
  89.         MyPixelBot.img.src = MyPixelBot.urlGen.image();
  90.     };
  91.  
  92.     MyPixelBot.canvasEvent = function(type, q) {
  93.         if (!MyPixelBot.canvas) return;
  94.         if (type == "mousewheel") {
  95.             MyPixelBot.canvas.dispatchEvent(new WheelEvent("mousewheel", q));
  96.         } else {
  97.             MyPixelBot.canvas.dispatchEvent(new MouseEvent(type, q));
  98.         }
  99.     };
  100.  
  101.     MyPixelBot.canvasClick = function(x, y, color) {
  102.         var offset = 0;
  103.         MyPixelBot.resetZoom();
  104.         if (x > 795) {
  105.             MyPixelBot.canvasMoveTo(795, 0);
  106.             offset = 795;
  107.             x = x - offset;
  108.         } else {
  109.             MyPixelBot.canvasMoveTo(0, 0);
  110.         }
  111.         var q = {
  112.             bubbles: true,
  113.             cancelable: true,
  114.             button: 1,
  115.             clientX: x,
  116.             clientY: y + 1,
  117.             layerX: x,
  118.             layerY: y + 1
  119.         };
  120.  
  121.         var pxColor = MyPixelBot.getColor(MyPixelBot.ctx.getImageData(x, y + 1, 1, 1).data, 0);
  122.         var colorEl = document.querySelectorAll('[style="background-color: ' + color + ';"]')[0];
  123.         if (!colorEl) {
  124.             console.log("color error %c " + color, 'background:' + color + ';');
  125.             MyPixelBot.setState("Ошибка подбора цвета " + color);
  126.             return;
  127.         } else if (pxColor == color) {
  128.             if(MyPixelBot.doCoordLog) {
  129.                 console.log("== " + x + offset  + "x" + y + "%c " + pxColor, 'background:' + pxColor + ';');
  130.                 MyPixelBot.setState("Пропускаю " + (x + offset + 1) + "x" + (y + 1) + " совпал цвет");
  131.             } else {
  132.                 console.log("==");
  133.                 MyPixelBot.setState("Пропускаю, совпал цвет");
  134.             }
  135.             return;
  136.         } else {
  137.             if(MyPixelBot.doCoordLog) {
  138.                 console.log(x + offset  + "x" + y + "%c " + pxColor + " -> %c " + color, 'background:' + pxColor + ';', 'background:' + color + ';');
  139.                 MyPixelBot.setState("Поставил точку " + (x + offset + 1) + "x" + (y + 1));
  140.             } else {
  141.                 console.log(" -> ");
  142.                 MyPixelBot.setState("Поставил точку");
  143.             }
  144.         }
  145.         colorEl.click();
  146.         MyPixelBot.canvasEvent("mousedown", q);
  147.         MyPixelBot.canvasEvent("click", q);
  148.         q.button = 0;
  149.         MyPixelBot.canvasEvent("mouseup", q);
  150.         document.querySelectorAll(".App__confirm button")[0].click();
  151.     };
  152.  
  153.     MyPixelBot.draw = function() {
  154.         var px = MyPixelBot.pixs.shift();
  155.         if (!px) {
  156.             MyPixelBot.setState("Точек нет");
  157.         } else {
  158.             MyPixelBot.canvasClick(px[0], px[1], px[2]);
  159.         }
  160.     };
  161.  
  162.     MyPixelBot.canvasMove = function(x, y) {
  163.         var q = {
  164.             bubbles: true,
  165.             cancelable: true,
  166.             button: 1,
  167.             clientX: 0,
  168.             clientY: 0
  169.         };
  170.         MyPixelBot.canvasEvent("mousedown", q);
  171.         q.clientY = y;
  172.         q.clientX = x;
  173.         MyPixelBot.canvasEvent("mousemove", q);
  174.         MyPixelBot.canvasEvent("mouseup", q);
  175.     };
  176.  
  177.     MyPixelBot.canvasMoveTo = function(x, y) {
  178.         MyPixelBot.canvasMove(10000, 10000);
  179.         MyPixelBot.canvasMove(-40 - x, -149 - y);
  180.     };
  181.  
  182.     MyPixelBot.getImageData = function() {
  183.         var data = MyPixelBot.ctx.getImageData(0, 1, 795, 400).data;
  184.         return data;
  185.     };
  186.  
  187.     MyPixelBot.getColor = function(data, i) {
  188.         return "rgb(" + data[i] + ", " + data[i + 1] + ", " + data[i + 2] + ")";
  189.     };
  190.  
  191.     MyPixelBot.getFullData = function() {
  192.         MyPixelBot.pixs = [];
  193.         MyPixelBot.pixs = MyPixelBot.randomShuffle(MyPixelBot.getData(0)
  194.             .concat(MyPixelBot.getData(795)));
  195.         MyPixelBot.setState("осталось точек:" + MyPixelBot.pixs.length);
  196.         return MyPixelBot.pixs.length;
  197.     };
  198.  
  199.     MyPixelBot.getData = function(offsetX) {
  200.         MyPixelBot.resetZoom();
  201.         MyPixelBot.canvasMoveTo(offsetX, 0);
  202.         var id1 = MyPixelBot.getImageData();
  203.         MyPixelBot.ctx.drawImage(MyPixelBot.img, -offsetX, 1);
  204.         var id2 = MyPixelBot.getImageData();
  205.         var data = [];
  206.         for (var i = 0; i < id1.length; i += 4) {
  207.             var x = offsetX + (i / 4) % 795,
  208.                 y = ~~((i / 4) / 795);
  209.             if (MyPixelBot.getColor(id1, i) !== MyPixelBot.getColor(id2, i) && MyPixelBot.getColor(id2, i) !== MyPixelBot.tc) {
  210.                 data.push([x, y, MyPixelBot.getColor(id2, i), MyPixelBot.getColor(id1, i)]);
  211.             }
  212.         }
  213.         return data;
  214.     };
  215.  
  216.     MyPixelBot.randomShuffle = function(data) {
  217.         var currentIndex = data.length, temporaryValue, randomIndex;
  218.         while (0 !== currentIndex) {
  219.             randomIndex = Math.floor(Math.random() * currentIndex);
  220.             currentIndex -= 1;
  221.             temporaryValue = data[currentIndex];
  222.             data[currentIndex] = data[randomIndex];
  223.             data[randomIndex] = temporaryValue;
  224.         }
  225.         return data;
  226.     };
  227.  
  228.     MyPixelBot.resetZoom = function() {
  229.         MyPixelBot.canvasEvent("mousewheel", {
  230.             deltaY: 100000,
  231.             deltaX: 0,
  232.             clientX: 100,
  233.             clientY: 100,
  234.         });
  235.     };
  236.  
  237.     MyPixelBot.init = function() {
  238.         MyPixelBot.inited = 1;
  239.         MyPixelBot.getFullData();
  240.         MyPixelBot.setState("Запущен.");
  241.     };
  242.  
  243.     MyPixelBot.wait = setInterval(function() {
  244.         if(MyPixelBot.debug)
  245.             debugger;
  246.         if (window.localStorage.getItem('DROP_FIRST_TIME') != '1') {
  247.             document.querySelectorAll(".App__advance > .Button.primary")[0].click();
  248.         } else if (window.localStorage.getItem('DROP_HEADER') != '1') {
  249.             document.querySelectorAll(".Header__close")[0].click();
  250.         } else if (!MyPixelBot.inited && MyPixelBot.canvas) {
  251.             MyPixelBot.ctx = MyPixelBot.canvas.getContext("2d");
  252.             MyPixelBot.init();
  253.         } else if (MyPixelBot.canvas && document.querySelectorAll(".Ttl > .Ttl__wait").length) {
  254.             MyPixelBot.timer = 1;
  255.         } else if (!MyPixelBot.canvas) {
  256.             var all = document.querySelectorAll("canvas");
  257.             for(var i = 0; i < all.length; ++i) {
  258.                 if(all[i].style.display != 'none') {
  259.                     MyPixelBot.canvas = all[i];
  260.                 }
  261.             }
  262.         } else if (!MyPixelBot.pts) {
  263.             MyPixelBot.reload();
  264.             MyPixelBot.pts = 30;
  265.         } else if (MyPixelBot.inited && MyPixelBot.canvas) {
  266.             MyPixelBot.pts--;
  267.             MyPixelBot.draw();
  268.         }
  269.     }, 1000);
  270.  
  271.     MyPixelBot.refresh = setTimeout(function() {
  272.         location.reload();
  273.     }, MyPixelBot.refreshTime * 1e3);
  274.  
  275.     MyPixelBot.reload = function() {
  276.         MyPixelBot.state.outerHTML = "";
  277.         MyPixelBot.loger.outerHTML = "";
  278.         clearInterval(MyPixelBot.wait);
  279.         var script = document.createElement('script');
  280.         script.src = MyPixelBot.urlGen.script();
  281.         document.body.appendChild(script);
  282.     };
  283.  
  284.     MyPixelBot.reloadImage();
  285.     console.log("MyPixelBot loaded");
  286. }
  287.  
  288. if (window.loaded) {
  289.     MyPixelBot();
  290. } else {
  291.     var inject = function() {
  292.         window.loaded = 1;
  293.         var script = document.createElement('script');
  294.         script.appendChild(document.createTextNode('(' + MyPixelBot + ')();'));
  295.         (document.body || document.head || document.documentElement).appendChild(script);
  296.     };
  297.  
  298.     if (document.readyState == 'complete') {
  299.         inject();
  300.     } else {
  301.         window.addEventListener("load", function() {
  302.             inject();
  303.         });
  304.     }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement