Skip to content

Instantly share code, notes, and snippets.

@nf
Created December 11, 2012 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nf/4255933 to your computer and use it in GitHub Desktop.
Save nf/4255933 to your computer and use it in GitHub Desktop.
new playground api interpreter
<input type="button" value="Stop" id="stop">
<div id="log"></div>
<script src="go/doc/jquery.js"></script>
<script>
var script = [
{"Delay": 0, "Message": "Hello, "},
{"Delay": 1000000000, "Message": "World!\n"},
{"Delay": 2000000000, "Message": "That's it!"}
];
function playback(root, script) {
var pre = $('<pre></pre>').appendTo(root);
var timeout;
var next = function() {
if (script.length == 0) {
return;
}
var msg = script.shift();
timeout = setTimeout(function() {
pre.text(pre.text() + msg.Message);
next();
}, msg.Delay / 1000000);
}
next();
return function() {
clearTimeout(timeout);
}
}
$("#stop").click(playback("#log", script));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment