|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.find,Number.isFinite,Number.isInteger,console,console.log,document.head,performance.now"></script> |
| 4 | + <head> |
| 5 | + <title>CodeWorld</title> |
| 6 | + <style type="text/css"> |
| 7 | + * { margin: 0; overflow: hidden } |
| 8 | + #screen { |
| 9 | + cursor: default; |
| 10 | + width: 100vw; |
| 11 | + height: 100vw; |
| 12 | + max-height: 100vh; |
| 13 | + max-width: 100vh; |
| 14 | + } |
| 15 | + </style> |
| 16 | + </head> |
| 17 | + <body style="text-align: center"> |
| 18 | + <canvas id="screen"></canvas> |
| 19 | + </body> |
| 20 | + <script type="text/javascript"> |
| 21 | + function addMessage(err, str) { |
| 22 | + if (window.parent && window.parent.addToMessage) { |
| 23 | + var message = window.parent.addToMessage(str); |
| 24 | + |
| 25 | + if (err) { |
| 26 | + var message = window.parent.document.getElementById('message'); |
| 27 | + message.classList.add('error'); |
| 28 | + } |
| 29 | + } else { |
| 30 | + console.log(str); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + function showCanvas() { |
| 35 | + if (!window.parent) { |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + var runner = window.parent.document.getElementById('runner'); |
| 40 | + if (!runner) { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + runner.style.display = ''; |
| 45 | + runner.focus(); |
| 46 | + runner.contentWindow.focus(); |
| 47 | + } |
| 48 | + |
| 49 | + function start() { |
| 50 | + h$base_writeStdout = function(fd, fdo, buf, buf_offset, n, c) { |
| 51 | + addMessage(false, h$decodeUtf8(buf, n, buf_offset)); |
| 52 | + c(n); |
| 53 | + }; |
| 54 | + h$base_writeStderr = function(fd, fdo, buf, buf_offset, n, c) { |
| 55 | + addMessage(false, h$decodeUtf8(buf, n, buf_offset)); |
| 56 | + c(n); |
| 57 | + }; |
| 58 | + h$log = function() { |
| 59 | + var s = ''; |
| 60 | + for(var i=0;i<arguments.length;i++) { s = s + arguments[i]; } |
| 61 | + addMessage(false, s+'\n'); |
| 62 | + }; |
| 63 | + h$errorMsg = function(str) { |
| 64 | + for(var i=1;i<arguments.length;i++) { |
| 65 | + str = str.replace(/%s/, arguments[i]); |
| 66 | + } |
| 67 | + addMessage(true, '\n' + str); |
| 68 | + }; |
| 69 | + h$base_stdout_fd.write = h$base_writeStdout; |
| 70 | + h$base_stderr_fd.write = h$base_writeStderr; |
| 71 | + |
| 72 | + h$run(h$mainZCZCMainzimain); |
| 73 | + } |
| 74 | + |
| 75 | + function reportRuntimeError(err, str) { |
| 76 | + if (window.parent.addToMessage) { |
| 77 | + var message = window.parent.addToMessage('\n' + str); |
| 78 | + |
| 79 | + if (err) { |
| 80 | + var message = window.parent.document.getElementById('message'); |
| 81 | + message.classList.add('error'); |
| 82 | + } |
| 83 | + } else { |
| 84 | + console.log(str); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + var loadScript = document.createElement('script'); |
| 89 | + loadScript.setAttribute('type', 'text/javascript'); |
| 90 | + loadScript.setAttribute('src', 'js/runjs.js'); |
| 91 | + loadScript.onload = function() { |
| 92 | + start(); |
| 93 | + }; |
| 94 | + document.head.appendChild(loadScript); |
| 95 | + </script> |
| 96 | + |
| 97 | +</html> |
| 98 | + |
| 99 | + |
0 commit comments