Guest User

forsenE

a guest
Apr 3rd, 2017
9,540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. OFFSET_X = 879;
  2. OFFSET_Y = 93;
  3.  
  4. waitDuration = 0;
  5. modHash = null;
  6.  
  7. //white: 0, lightGrey: 1, grey: 2, black: 3,
  8. //pink: 4, red: 5, orange: 6, brown: 7,
  9. //yellow: 8, lightGreen: 9, green: 10, cyan: 11,
  10. //teal: 12, blue: 13, fuchsia: 14, purple: 15
  11. f = -1;
  12.  
  13. image = [[0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1],
  14. [4,4,4,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1],
  15. [4,4,1,1,3,3,3,2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1],
  16. [4,1,2,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,4,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1],
  17. [4,0,1,4,4,4,4,3,3,3,2,0,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1],
  18. [4,0,4,4,4,0,4,4,0,1,1,1,0,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,1,1,1,1,1,1,1,1],
  19. [4,4,4,0,1,2,2,1,1,1,0,0,0,0,4,4,4,4,4,0,0,4,4,4,4,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1],
  20. [4,4,0,0,2,4,4,4,4,0,1,4,4,4,4,4,4,0,0,0,0,0,4,0,1,1,2,2,1,2,1,1,1,1,1,1,1,1,1,1],
  21. [4,4,0,1,4,4,4,0,0,0,1,0,4,4,4,4,4,0,1,1,0,0,1,3,3,3,3,3,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0,1,1,1,1,1,2,2],
  46. [4,0,0,0,0,4,1,4,0,4,4,4,0,1,1,2,2,2,2,2,2,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,2,2,2],
  47. [0,0,0,0,1,2,0,2,4,0,4,4,4,4,1,2,2,2,2,2,1,1,0,0,0,1,0,0,1,1,1,1,2,2,1,1,2,2,2,2],
  48. [4,0,0,1,2,2,2,1,1,4,4,4,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,2,2],
  49. [4,4,0,1,2,2,2,2,2,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3],
  50. [4,0,1,2,2,3,3,3,2,0,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,1,2,2,3,2,2,2,2,2,2,2,3,3,3,3],
  51. [4,0,2,2,3,3,2,3,2,1,4,4,4,4,4,4,4,0,0,0,0,0,0,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3],
  52. [4,2,3,3,3,3,3,2,3,2,1,0,4,4,4,0,0,0,0,0,1,1,2,2,2,3,3,3,3,3,3,2,2,3,3,3,3,3,3,3]];
  53.  
  54.  
  55. function start() {
  56. modHash = getModHash();
  57. main(0, 0);
  58. }
  59.  
  60. function main(x, y) {
  61. var timer = drawIfNecessary(x, y);
  62. console.log('waiting ' + timer + ' milliseconds');
  63. x = (x + 1) % image[y].length;
  64. if (x === 0) {
  65. y = (y + 1) % image.length;
  66. }
  67. setTimeout(main, timer, x, y);
  68. }
  69.  
  70. function drawIfNecessary(x, y) {
  71. if (image[y][x] < 0) return 0;
  72. canvasX = x + OFFSET_X;
  73. canvasY = y + OFFSET_Y;
  74. var pixelColour = pixelRequest(canvasX, canvasY);
  75. console.log('found pixel colour ' + pixelColour);
  76. var desiredColour = image[y][x];
  77. return (pixelColour == desiredColour) ? 0 : draw(canvasX, canvasY, desiredColour);
  78. }
  79.  
  80.  
  81. function sendSynchronousRequest(method, url, headers, params) {
  82. var xhr = new XMLHttpRequest();
  83. xhr.open(method, url, false);
  84. for (var h in headers) {
  85. xhr.setRequestHeader(h, headers[h]);
  86. }
  87. var firstParam = true;
  88. var paramString = '';
  89. for (var p in params) {
  90. if (firstParam) {
  91. firstParam = false;
  92. } else {
  93. paramString += '&';
  94. }
  95. paramString += p + '=' + params[p];
  96. }
  97. xhr.send(paramString);
  98. return xhr;
  99. }
  100.  
  101.  
  102. function getModHash() {
  103. var xhr = sendSynchronousRequest('GET', 'api/me.json', {}, {});
  104.  
  105. if (xhr.readyState !== 4) throw 'oh shit';
  106. if (xhr.status !== 200) {
  107. alert("Couldn't obtain modhash. Are you logged into Reddit?");
  108. throw 'bollocks';
  109. }
  110. var response = JSON.parse(xhr.responseText);
  111. return response.data.modhash;
  112. }
  113.  
  114.  
  115. function pixelRequest(x, y) {
  116. var url = '/api/place/pixel.json?x=' + x + '&y=' + y;
  117.  
  118. var xhr = sendSynchronousRequest('GET', url, {
  119. 'x-requested-with': 'XMLHttpRequest',
  120. 'x-modhash': modHash
  121. }, {});
  122.  
  123. if (xhr.readyState !== 4) throw 'oh shit';
  124. if (xhr.status !== 200) {
  125. console.log(xhr);
  126. return "jews";
  127. }
  128. var response = JSON.parse(xhr.responseText);
  129. return response.color;
  130. }
  131.  
  132.  
  133. function draw(x, y, colour) {
  134. console.log('attempting to draw a pixel at (' + x + ',' + y + ')');
  135. var xhr = sendSynchronousRequest('POST', '/api/place/draw.json', {
  136. 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  137. 'x-requested-with': 'XMLHttpRequest',
  138. 'x-modhash': modHash
  139. }, {
  140. x: x,
  141. y: y,
  142. color: colour
  143. });
  144.  
  145. if (xhr.readyState !== 4) throw 'oh shit';
  146. if (xhr.status !== 200 && xhr.status !== 429) {
  147. console.log(xhr);
  148. throw 'bollocks';
  149. }
  150. var response = JSON.parse(xhr.responseText);
  151. return response.wait_seconds * 1000;
  152. }
  153.  
  154.  
  155. start();
Advertisement
Add Comment
Please, Sign In to add comment