-
-
Save tzkmx/d6e0f45f246fd0534cd4ddddee83f53b to your computer and use it in GitHub Desktop.
Code behind https://jgc.org/lava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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