Skip to content

Instantly share code, notes, and snippets.

@KristianFenn
Last active April 2, 2017 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KristianFenn/edbe3e1f2a56877cb9a4ce640256c1f8 to your computer and use it in GitHub Desktop.
Save KristianFenn/edbe3e1f2a56877cb9a4ce640256c1f8 to your computer and use it in GitHub Desktop.
const modhash = window.reddit.modhash;
const width = 82;
const height = 13;
var sec = 0, index = Math.floor(Math.random() * 10) * 100;//Math.floor(Math.random() * (width * height));
const getPrevColor = (x, y) => r.place.state[x + (y * 1000)];
setInterval(() => console.log("Drawing in " + (sec--) + " seconds"), 1e3);
const draw = seconds => {
index++
index = index % (width * height);
sec = seconds;
setTimeout(() => {
const x = index % width;
const y = Math.floor(index / width);
const flagColors =
[[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,0,0,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,0,0,3,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,3,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,0,0,0,0,13,13,13,13,13,13,13,13,13,13,13,0,0,0,0,3,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,3,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,13,0,0,0,0,0,13,13,13,13,13,13,13,0,0,0,0,0,13,3,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,3,0,5,5,5,5,5,0,0,0,0,0,0,0,5,5,5,5,5,0,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,13,13,13,0,0,0,0,0,13,13,13,0,0,0,0,0,13,13,13,3,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,3,0,0,0,5,5,5,5,5,0,0,0,5,5,5,5,5,0,0,0,3],
[3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,13,13,13,13,13,0,0,0,0,0,0,0,0,0,13,13,13,13,13,3,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,3,0,0,0,0,0,5,5,5,5,5,5,5,5,5,0,0,0,0,0,3],
[3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,13,13,13,13,13,13,13,0,0,0,0,0,13,13,13,13,13,13,13,3,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,3,0,0,0,0,0,0,0,5,5,5,5,5,0,0,0,0,0,0,0,3],
[3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,13,13,13,13,13,0,0,0,0,0,0,0,0,0,13,13,13,13,13,3,10,10,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,10,10,3,0,0,0,0,0,5,5,5,5,5,5,5,5,5,0,0,0,0,0,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,13,13,13,0,0,0,0,0,13,13,13,0,0,0,0,0,13,13,13,3,10,10,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,10,10,3,0,0,0,0,5,5,5,5,0,0,0,5,5,5,5,5,0,0,0,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,13,0,0,0,0,0,13,13,13,13,13,13,13,0,0,0,0,0,13,3,10,10,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,10,10,3,0,5,5,5,5,5,0,0,0,0,0,0,0,5,5,5,5,5,0,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,0,0,0,0,13,13,13,13,13,13,13,13,13,13,13,0,0,0,0,3,10,10,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,10,10,3,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,3],
[3,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,0,0,0,3,0,0,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,0,0,3,10,10,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,10,10,3,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,3],
[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]];
const flagColor = flagColors[y][x];
if (flagColor === null) {
return draw(0);
}
const ax = x + 139;
const ay = y + 370;
/*
const oldCol = getPrevColor(ax, ay);
if (flagColor == oldCol) {
return draw(0);
}
*/
$.get("https://www.reddit.com/api/place/pixel.json?x=" + ax + "&y=" + ay)
.then(res => {
if (res.color == flagColor) {
console.log("Skipping " + (ax + ", " + ay) + " because it's already correct");
return draw(0.1);
}
console.log("Drawing at " + ax + ", " + ay + " (https://www.reddit.com/r/place/#x=" + ax + "&y=" + ay + ")");
$.ajax({ url: "https://www.reddit.com/api/place/draw.json", type: "POST",
headers: { "x-modhash": modhash }, data: { x: ax, y: ay, color: flagColor }
})
.done(data => draw(Math.ceil(data.wait_seconds)))
.error(data => draw(Math.ceil(data.responseJSON.wait_seconds)));
});
}, seconds * 1000);
}
draw(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment