Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active March 20, 2020 06:30
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save ryanflorence/7b174273c7e0787c06649da1535fb3dd to your computer and use it in GitHub Desktop.
Save ryanflorence/7b174273c7e0787c06649da1535fb3dd to your computer and use it in GitHub Desktop.
const { createServer } = require('http');
createServer((req, res) => {
res.writeHead(200, {
Connection: 'Transfer-Encoding',
'Content-Type': 'text/html; charset=utf-8',
'Transfer-Encoding': 'chunked'
});
res.write(`
<!doctype html>
<html>
<head><title>chunky!</title></head>
<body>
<h1>Cool Home Page!</h1>
`);
setTimeout(() => {
res.write('<p id="message">Still thinking...</p>');
setTimeout(() => {
res.write(`
<script>
message.innerText = "Embarassing, sorry... here's a button to click:"
</script>
<button id="btn">click me</button>
<script>
btn.addEventListener('click', () => {
const hue = Math.round(Math.random() * 100)
document.body.style.background = "hsl("+hue+", 50%, 90%)"
}, false)
</script>
`);
setTimeout(() => {
res.write(`
<script>
message.innerText = "Whew! Done!"
btn.parentNode.removeChild(btn)
document.body.style.background = ""
</script>
`);
res.end();
}, 5000);
}, 2000);
}, 2000);
}).listen(5000);
@duanemoody
Copy link

duanemoody commented Oct 2, 2019

Why not
`hsl(${hue}, 50%, 90%)`

@matschik
Copy link

matschik commented Oct 3, 2019

@duanemoody For ES5 compatibility probably or we just do not care haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment