Revision control
+ <html>
+ <head>
+ <script>
+ function exec(data, cb)
+ {
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", "../e/" + data, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState != 4 || xhr.status != 200)
+ return;
+ cb(xhr.responseText);
+ };
+ xhr.send();
+ }
+
+ function poll(id, callback)
+ {
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", "../s/" + id, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState != 4 || xhr.status != 200)
+ return;
+ (callback)(xhr.responseText);
+ setTimeout(function() { poll(id, callback); }, 0);
+ }
+ xhr.send();
+ }
+
+ window.addEventListener("message", function(event) {
+ var data = JSON.parse(event.data);
+ function callback(r) { window.parent.postMessage(JSON.stringify({ id: data.id, payload: r }), "*"); }
+ if (data.type == "exec")
+ exec(JSON.stringify(data.payload), callback);
+ else if (data.type == "subscribe")
+ poll(data.id, callback);
+ });
+ </script>
+ </head>
+ <body>
+ </body>
+ </html>