Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
Created October 16, 2018 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgrahamc/51937a23711370e9d5b93559a9bea602 to your computer and use it in GitHub Desktop.
Save jgrahamc/51937a23711370e9d5b93559a9bea602 to your computer and use it in GitHub Desktop.
Code behind https://jgc.org/lava
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const response = await fetch("https://csprng.xyz/v1/api?length=10")
if (response.status != 200) {
return response
}
const body = await response.text()
const json = JSON.parse(body)
const data = atob(json.Data)
var a = new ArrayBuffer(data.length * 1);
var bytes = new Uint8Array(a);
bytes.forEach((_, i) => {
bytes[i] = data.charCodeAt(i);
console.log(bytes[i])
});
var offset = 0
var html = "<html><head><title>Random Lava Lamps</title></head><body>"
html += "<table>"
for (row = 0; row < 4; row++) {
html += "<tr>\n"
for (col = 0; col < 20; col++) {
html += "<td>"
html += "<img src=\"https://static.jgc.org/"
html += ((bytes[Math.floor(offset/8)] & 0x01) == 0x01)?"orange":"blue"
html += ".png\">"
html += "</td>\n"
bytes[Math.floor(offset/8)] >>>= 1
offset += 1
}
html += "</tr>\n"
}
html += "</table>"
html += "</body></html>"
return new Response(html, {headers: {"Content-Type": "text/html"}})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment