Skip to content

Instantly share code, notes, and snippets.

@Noxsios
Last active November 23, 2021 16:53
Show Gist options
  • Save Noxsios/487672f6b37582f5d440d8fe8c1d1191 to your computer and use it in GitHub Desktop.
Save Noxsios/487672f6b37582f5d440d8fe8c1d1191 to your computer and use it in GitHub Desktop.
// Inspired by https://github.com/hugomd/parrot.live
// This runs in a Cloudflare worker.
const brown = "\u001b[38;5;94m";
const green = "\u001b[38;5;28m";
const reset = "\u001b[0m";
const frames = [
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}⊃${reset}${brown}且${reset}${green}⊂${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<-->${reset} ::
:: ${green}⊃${reset}${brown}且${reset}${green}⊂${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}⊃${reset}${brown}且${reset}${green}⊂${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<-->${reset} ::
:: ${green}⊃${reset}${brown}且${reset}${green}⊂${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}⊃${reset}${brown}且${reset}${green}⊂${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}╯${reset}${brown}且${reset}${green}╰${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}╯${reset}${brown}旦${reset}${green}╰${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<-->${reset} ::
:: ${green}╯${reset}${brown}旦${reset}${green}╰${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<-->${reset} ::
:: ${green}╯${reset}${brown}旦${reset}${green}╰${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<-->${reset} ::
:: ${green}╯${reset}${brown}ロ${reset}${green}╰${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}╯${reset}${brown}ロ${reset}${green}╰${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
`
::::::::::::
:: ::
:: ${green}<••>${reset} ::
:: ${green}⊃${reset}${brown}ロ${reset}${green}⊂${reset} ::
:: ${brown}(==)${reset} ::
:: ::
:: P1 ::
::::::::::::
`,
];
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const { url } = request;
const userAgent = request.headers.get("User-Agent") || "";
const { pathname } = new URL(url);
switch (pathname) {
case "/":
if (userAgent.includes("curl")) {
return streamAscii();
} else {
return new Response(JSON.stringify("Please use cURL."));
}
case "/healthcheck":
return new Response(JSON.stringify({ status: "ok" }), {
status: 200,
headers: {
"Content-Type": "application/json;charset=UTF-8",
},
});
}
return fetch(request);
}
async function streamAscii() {
let { readable, writable } = new TransformStream();
const writer = writable.getWriter();
let index = 0;
let encoder = new TextEncoder();
setInterval(() => {
writer.write(encoder.encode("\033[2J\033[3J\033[H"));
writer.write(encoder.encode(frames[index]));
index = (index + 1) % frames.length;
}, 500);
const response = new Response(readable);
response.body.pipeTo(writable);
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment