tzkmx
10/15/2019 - 8:54 PM

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"}})
}