Advertisement
Guest User

Untitled

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