-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
94 lines (86 loc) · 2.15 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html>
<head>
<title>JSCode</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="normalize.css">
<style>
html, body {
height: 100%;
}
#code {
margin: 0;
padding: 0;
border: 0;
width: 100%;
height: 100%;
}
.button {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 1rem;
padding: 0.7rem 1.5rem;
border: 0;
border-radius: 4px;
}
#run-code {
position: fixed;
bottom: 2rem;
right: 2rem;
color: white;
background-color: #3a3c4c;
}
.monaco-editor .parameter-hints-widget {
border: 0px;
}
.monaco-editor .parameter-hints-widget .signature {
padding: 0px;
}
.monaco-editor .suggest-widget {
border: 0px;
}
.monaco-editor.vs-dark .suggest-widget {
border: 0px;
}
.monaco-editor .rename-box {
top: 0;
}
</style>
</head>
<body>
<div id="code"></div>
<button id="run-code" class="button" type="button" onclick="runCode()">Run code (Alt + Enter)</button>
<script src="vs/loader.js"></script>
<script>
'use strict';
require.config({ paths: { 'vs': 'vs' }});
require(['vs/editor/editor.main'], function() {
window.$editor = monaco.editor.create(document.getElementById('code'), {
theme: 'vs-dark',
automaticLayout: true,
scrollBeyondLastLine: false,
fontSize: '18px',
value: window.localStorage.getItem('code') || '// code\n',
language: 'javascript'
});
});
function runCode() {
try {
eval(`(function() { ${window.$editor.getValue()} })()`);
} catch (err) {
alert('❌ ' + err.message);
}
}
document.addEventListener('keydown', function(e) {
if (e.keyCode == 13 && e.altKey) {
runCode();
}
}, false)
window.onbeforeunload = function() {
window.localStorage.setItem('code', window.$editor.getValue());
};
</script>
</body>
</html>