Last active
December 23, 2019 18:39
-
-
Save rainydio/6ebeef45dc4874703bba4e3be883e05f to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<style type="text/css"> | |
#lines { | |
position: fixed; | |
top: 0; | |
left: 0; | |
white-space: pre; | |
font-family: monospace; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="lines"></div> | |
<script> | |
let n = 0; | |
let lines = []; | |
window.addEventListener("message", evt => { | |
if (evt.data.startsWith("dt=")) { | |
n++; | |
lines.unshift(`n=${n};${evt.data}`); | |
lines = lines.slice(0, 25); | |
document.getElementById("lines").innerHTML = lines.join("\n"); | |
} | |
}); | |
const script = ` | |
let prev = Date.now(); | |
const fn = () => { | |
const now = Date.now(); | |
const dt = now - prev; | |
prev = now; | |
requestAnimationFrame(fn); | |
window.parent.postMessage("dt=" + dt, "*"); | |
}; | |
requestAnimationFrame(fn); | |
`; | |
const iframe = document.createElement("iframe"); | |
iframe.sandbox = "allow-scripts"; | |
iframe.style.marginTop = "1200px"; | |
iframe.srcdoc = "<script" + `>${script}<` + "/script>"; | |
document.body.appendChild(iframe); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment