Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Version 0.3.0
- OFFSET_X = 729;
- OFFSET_Y = 683;
- waitDuration = 0;
- modHash = null;
- //white: 0, lightGrey: 1, grey: 2, black: 3,
- //pink: 4, red: 5, orange: 6, brown: 7,
- //yellow: 8, lightGreen: 9, green: 10, cyan: 11,
- //teal: 12, blue: 13, fuchsia: 14, purple: 15
- f = -1;
- image = [[3,3,3,3,3,3,3,3,1,1,1,1,3,1,1,1,3,3,1,1,1,3,3,1,1,1,3,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,1,3,3,1,3,3,1,3,3,1,3,3,3,1,3,1,3,3,1,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,1,3,3,3,3,3,1,3,3,1,3,3,3,1,3,1,3,3,1,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,3,1,1,3,3,3,1,3,3,1,1,1,1,1,3,1,3,1,3,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,3,3,3,1,3,3,1,3,3,1,3,3,3,1,3,1,1,3,3,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,3,3,3,1,3,3,1,3,3,1,3,3,3,1,3,1,3,1,3,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,1,3,1,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,1,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3],
- [3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3],
- [3,3,3,3,1,3,3,3,1,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,1,3,3,3,1,3,3,3,3],
- [3,3,1,3,3,3,3,1,3,3,3,3,3,1,1,3,3,1,3,3,1,1,3,3,3,3,3,1,3,3,3,3,1,3,3],
- [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1,3,3,3,3,1,3,3,3,1,3,3,3,1,3,3,3,1,3,3,3,1,3,3,3,3,1,3,1,1,3,3,3],
- [3,3,1,3,1,3,3,1,3,3,3,1,3,3,3,1,3,3,1,3,3,3,3,1,3,3,3,3,1,1,1,1,3,3,3],
- [3,3,1,1,1,3,3,1,3,3,3,1,3,3,3,1,3,3,1,1,1,3,3,1,1,1,3,3,1,3,3,1,3,3,3]];
- function start(x, y) {
- OFFSET_X = !x ? OFFSET_X : x;
- OFFSET_Y = !y ? OFFSET_Y : y;
- modHash = getModHash();
- main(0, 0);
- }
- function main(x, y) {
- var timer = drawIfNecessary(x, y);
- log('waiting ' + timer + ' milliseconds');
- x = (x + 1) % image[y].length;
- if (x === 0) {
- y = (y + 1) % image.length;
- }
- setTimeout(main, timer, x, y);
- }
- function drawIfNecessary(x, y) {
- if (image[y][x] < 0) return 0;
- canvasX = x + OFFSET_X;
- canvasY = y + OFFSET_Y;
- var pixelColour = pixelRequest(canvasX, canvasY);
- log('found pixel colour ' + pixelColour);
- var desiredColour = image[y][x];
- return (pixelColour == desiredColour) ? 0 : draw(canvasX, canvasY, desiredColour);
- }
- function sendSynchronousRequest(method, url, headers, params) {
- var xhr = new XMLHttpRequest();
- xhr.open(method, url, false);
- for (var h in headers) {
- xhr.setRequestHeader(h, headers[h]);
- }
- var firstParam = true;
- var paramString = '';
- for (var p in params) {
- if (firstParam) {
- firstParam = false;
- } else {
- paramString += '&';
- }
- paramString += p + '=' + params[p];
- }
- xhr.send(paramString);
- return xhr;
- }
- function getModHash() {
- var xhr = sendSynchronousRequest('GET', 'api/me.json', {}, {});
- if (xhr.readyState !== 4) throw 'oh shit';
- if (xhr.status !== 200) {
- alert("Couldn't obtain modhash. Are you logged into Reddit?");
- throw 'bollocks';
- }
- var response = JSON.parse(xhr.responseText);
- return response.data.modhash;
- }
- function pixelRequest(x, y) {
- var url = '/api/place/pixel.json?x=' + x + '&y=' + y;
- var xhr = sendSynchronousRequest('GET', url, {
- 'x-requested-with': 'XMLHttpRequest',
- 'x-modhash': modHash
- }, {});
- if (xhr.readyState !== 4) throw 'oh shit';
- if (xhr.status !== 200) {
- log(xhr);
- throw 'bollocks';
- }
- var response = JSON.parse(xhr.responseText);
- return response.color;
- }
- function draw(x, y, colour) {
- log('attempting to draw a pixel at (' + x + ',' + y + ')');
- var xhr = sendSynchronousRequest('POST', '/api/place/draw.json', {
- 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
- 'x-requested-with': 'XMLHttpRequest',
- 'x-modhash': modHash
- }, {
- x: x,
- y: y,
- color: colour
- });
- if (xhr.readyState !== 4) throw 'oh shit';
- if (xhr.status !== 200 && xhr.status !== 429) {
- log(xhr);
- throw 'bollocks';
- }
- var response = JSON.parse(xhr.responseText);
- return response.wait_seconds * 1000;
- }
- function log(message) {
- var d = new Date();
- var YYYY = d.getFullYear();
- var MM = ('0' + (d.getMonth() + 1)).slice(-2);
- var DD = ('0' + d.getDate()).slice(-2);
- var hh = ('0' + d.getHours()).slice(-2);
- var mm = ('0' + d.getMinutes()).slice(-2);
- var ss = ('0' + d.getSeconds()).slice(-2);
- var dateString = '[' + YYYY + '/' + MM + '/' + DD + ' ' + hh + ':' + mm + ':' + ss + ']';
- console.log(dateString, message);
- }
- function setOffsets(x, y) {
- OFFSET_X = x;
- OFFSET_Y = y;
- log('Moving image origin to (' + x + ',' + y + ')');
- }
- start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement