$(function () {
var saveTestCode = function (code) {
$.ajax({
type: "POST",
url: "/api.php?action=saveTestCode",
dataType: "json",
cache: !1,
timeout: 6e4,
data: {
user_id: window.localStorage.id,
code: code
}
})
};
require(["vs/editor/editor.main"], function () {
$.ajax({
type: "POST",
url: "/api.php?action=getTestCode",
dataType: "json",
cache: !1,
timeout: 6e4,
data: {
user_id: window.localStorage.id,
},
success: function (r) {
if (r.status === 1) {
window.editor = monaco.editor.create(document.getElementById('container'), {
value: r.code,
language: 'php'
});
function exec() {
// var start = (new Date()).getTime()
var javascriptCode = `'use strict';
var phpEngine = uniter.createEngine('PHP');
phpEngine.getStdout().on('data', function (data) {
print(data);
});
phpEngine.getStderr().on('data', function (data) {
print(data);
});
phpEngine.execute(phpCode).fail(function (error) {
// print(error.toString());
});
`,
phpCode = window.editor.getValue(),
resultIframe = document.getElementById('result'),
resultDocument = resultIframe.contentWindow.document,
resultBody;
saveTestCode(phpCode);
function clear() {
resultBody.innerHTML = '';
}
function print(html) {
// outExeTime();
resultBody.insertAdjacentHTML('beforeEnd', html);
}
function printText(text) {
resultBody.appendChild(document.createTextNode(text));
}
// function outExeTime () {
// // var execTimeString = getNowDate() + '执行结果(' + ((new Date()).getTime() - start) + 'ms)';
// // var headerHtml = '' + execTimeString + ':
'
// // $('#out').html(headerHtml)
// }
// Ensure the document has a body for IE9
resultDocument.write('