Advertisement
Guest User

Untitled

a guest
Apr 1st, 2017
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.33 KB | None | 0 0
  1. (function() {
  2.  
  3.  
  4. var data =
  5. [34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255]
  6.  
  7. var canvas = document.getElementById('place-canvasse');
  8. var container = document.getElementById('place-container');
  9.  
  10. var select_color = function(index) {
  11. var colored_square = document.getElementsByClassName('place-swatch')[index];
  12. colored_square.dispatchEvent(make_event('click', 0, 0, 0));
  13. };
  14.  
  15. var get_place_coordinates = function() {
  16. var coord_string = document.getElementById('place-camera').style.transform;
  17. var paren_index = coord_string.indexOf('(');
  18. var comma_index = coord_string.indexOf(',');
  19. var px_index = coord_string.indexOf('px', comma_index);
  20. var x = parseInt(coord_string.substring(paren_index+1, comma_index));
  21. var y = parseInt(coord_string.substring(comma_index+2, px_index));
  22.  
  23. x = 500.0 - x;
  24. y = 500.0 - y;
  25.  
  26. return {x:x,y:y};
  27. };
  28.  
  29. var make_event = function(type, button, x, y) {
  30. var rect = container.getBoundingClientRect();
  31. x += rect.left;
  32. y += rect.top;
  33.  
  34. var ev = document.createEvent('MouseEvent');
  35. ev.initMouseEvent(type,true,true,window,1,0,0,x,y,false,false,false,false,0,null);
  36. return ev;
  37. };
  38. var send_event = function(ev) {
  39. canvas.dispatchEvent(ev);
  40. };
  41.  
  42. // Look at the existing canvas to find pixels that should be changed
  43. var X = 517;
  44. var Y = 139;
  45. var W = 55;
  46. var H = 10;
  47. var game_data;
  48.  
  49. // Returns a color-index value if the pixel should be changed, otherwise null
  50. var check_pixel = function(x, y) {
  51. var k = 4*x + 4*W*y;
  52. if( game_data[k ] !== data[k ]
  53. || game_data[k+1] !== data[k+1]
  54. || game_data[k+2] !== data[k+2] ) {
  55. if(data[k] === 34) // Black
  56. return 3;
  57. else // Orange
  58. return 6;
  59. }
  60. return null;
  61. };
  62.  
  63. var do_a_pixel = function() {
  64.  
  65. // Find a pixel that needs to be changed
  66. game_data = canvas.getContext('2d').getImageData(X, Y, W, H).data;
  67. var i = null;
  68. var j = null;
  69. var color_index = null;
  70. // Try searching randomly at first
  71. for(var n=0; n<100; ++n) {
  72. j = Math.floor(Math.random() * W);
  73. i = Math.floor(Math.random() * H);
  74. color_index = check_pixel(j, i);
  75. if(color_index !== null) {
  76. console.log('Found a pixel randomly');
  77. break;
  78. }
  79. }
  80. if(color_index === null) { // Haven't found one yet; search linearly now
  81. for(i=0; i<H; ++i) {
  82. var should_break = false;
  83.  
  84. for(j=0; j<W; ++j) {
  85. color_index = check_pixel(j, i);
  86. if(color_index !== null) {
  87. console.log('Found a pixel linearly');
  88. should_break = true;
  89. break;
  90. }
  91. }
  92.  
  93. if(should_break)
  94. break;
  95. }
  96. }
  97.  
  98. if(color_index === null) {
  99. console.log('No pixels need to be changed');
  100. return false;
  101. }
  102.  
  103. var px = j + X;
  104. var py = i + Y;
  105.  
  106. console.log('Trying to set ' + px + ' ' + py + ' to ' + color_index);
  107.  
  108. // Right click to cancel the paintbrush, if necessary
  109. send_event(make_event('contextmenu', 2, 10, 10));
  110.  
  111. // Right click again to zoom in, if necessary
  112. if(document.getElementsByClassName('place-zoomed-out').length === 1)
  113. send_event(make_event('contextmenu', 2, 10, 10));
  114.  
  115. setTimeout(function() {
  116.  
  117. var coord = get_place_coordinates();
  118. var x = coord.x;
  119. var y = coord.y;
  120.  
  121. // Scroll to origin
  122. send_event(make_event('mousemove', 0, 0 , 0 ));
  123. send_event(make_event('mousedown', 0, 0 , 0 ));
  124. send_event(make_event('mousemove', 0, x*40 , y*40));
  125. send_event(make_event('mouseup' , 0, x*40 , y*40));
  126.  
  127. // Scroll to Factorio
  128. send_event(make_event('mousemove', 0, px*40, py*40));
  129. send_event(make_event('mousedown', 0, px*40, py*40));
  130. send_event(make_event('mousemove', 0, 0 , 0 ));
  131. send_event(make_event('mouseup' , 0, 0 , 0 ));
  132.  
  133. // Get coordinates of center of canvas.
  134. var rect = container.getBoundingClientRect();
  135. x = (rect.right-rect.left)/2;
  136. y = (rect.bottom-rect.top)/2;
  137.  
  138. select_color(color_index);
  139.  
  140. send_event(make_event('mousemove', 0, x, y));
  141. // Something weird about the coordinates ...
  142. x -= 20;
  143. y -= 40;
  144. send_event(make_event('mousedown', 0, x, y));
  145. send_event(make_event('mouseup' , 0, x, y));
  146.  
  147. }, 1000);
  148.  
  149. return true;
  150.  
  151. };
  152.  
  153.  
  154. var f = function() {
  155. do_a_pixel();
  156. setTimeout(f, 30000);
  157. };
  158. f();
  159.  
  160.  
  161. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement