forked from Tanabe-Yumi/rubyeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
207 lines (193 loc) · 5.62 KB
/
index.html
File metadata and controls
207 lines (193 loc) · 5.62 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ruby エディタ</title>
<link rel="shortcut icon" href="./images/favicon.ico">
<link rel="apple-touch-icon" href="./images/favicon_180.png">
<link rel="icon" href="./images/favicon_192.png">
<link href="https://use.fontawesome.com/releases/v6.2.0/css/all.css" rel="stylesheet">
<style type="text/css" media="screen">
html {
font-size: 55%;
}
* {
margin: 0;
}
body {
margin: 0;
overflow: hidden;
}
.editor {
height: calc(100vh - 80px);
width: 100vh;
margin: 0;
}
#editor {
height: calc(100vh - 80px);
width: 100%;
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.buttons {
height: 80px;
width: 100%;
}
.btn-wrap {
width: 90%;
margin: 1.6rem;
margin-left: 4rem;
}
button.btn, #load-button {
font-size: 1.6rem;
font-weight: 700;
line-height: 1;
position: relative;
display: inline-block;
margin-right: 1.6rem;
margin-bottom: 1.6rem;
padding: 1rem 4rem;
cursor: pointer;
transition: all 0.2s;
text-align: center;
vertical-align: middle;
text-decoration: none;
letter-spacing: 0.1em;
color: #212529;
border-radius: 0.5rem;
}
button.btn-border, #load-button.btn-border {
border: 2px solid #000;
border-radius: 0;
background: #3CDAFF;
}
button.btn-border:hover, #load-button.btn-border:hover {
color: #fff;
background: #6BE3FF;
}
button.btn-icon, #load-button.btn-icon {
font-size: 2rem;
position: relative;
padding: 1.5rem 3rem 1.5rem 2rem;
}
button.btn-icon i.fa-solid {
margin-right: 1rem;
}
#load-button.btn-icon i.fa-solid {
margin-right: 1rem;
}
#load-input{
display: none;
}
</style>
</head>
<body>
<div class="container">
<div class="editor">
<pre id="editor">num = 0
10.times do |i|
puts i + "times"
end
</pre>
</div>
<div class="buttons">
<div class="btn-wrap">
<button class="btn btn-border btn-icon" onclick="compileBtn();">
<i class="fa-solid fa-wrench"></i>
コンパイル
</button>
<button class="btn btn-border btn-icon" onclick="saveBtn();">
<i class="fa-solid fa-download"></i>
保存
</button>
<div id="load-button" class="btn btn-border btn-icon" onclick="loadBtn();">
<i class="fa-solid fa-upload"></i>
読み込み
</div>
<input type="file" id="load-input" accept=".rb,.txt">
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.0/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setFontSize(16); // px
editor.setTheme("ace/theme/solarized_light");
editor.session.setMode("ace/mode/ruby");
function compileBtn() {
/*
var ele = document.createElement('form');
ele.action = 'https://www.epi.it.matsue-ct.jp/j1819/convert/upload.php';
ele.method = 'post';
ele.setAttribute('target', '_blank');
var q = document.createElement('textarea');
q.value = editor.getSession().getValue();
q.name = 'master_code';
ele.appendChild(q);
document.body.appendChild(ele);
ele.submit();
ele.remove();
*/
const masterCode = editor.getSession().getValue();
console.log( masterCode )
const base64MasterCode = btoa(
String.fromCharCode.apply(
null,
new TextEncoder().encode(masterCode)
)
);
const CompileServerURI = 'https://ceres.epi.it.matsue-ct.ac.jp/compile/code';
const res = fetch(CompileServerURI, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
code: base64MasterCode
})
}).then(r => r.json().then(j => {
// console.table(j);
window.open(`https://ceres.epi.it.matsue-ct.ac.jp/writer?id=${j.id}`, '_blank');
}))
.catch(r => {
// eslint-disable-next-line no-console
console.error(r);
});
return res;
}
function saveBtn() {
const downloadLink = document.createElement('a');
document.body.appendChild(downloadLink);
downloadLink.href = "#";
downloadLink.download = 'source.rb';
const content = editor.getSession().getValue();
var blob = new Blob([content], {"type": "text/plain"});
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, "source.rb");
window.navigator.msSaveOrOpenBlob(blob, "source.rb");
} else {
downloadLink.href = window.URL.createObjectURL(blob);
}
downloadLink.click();
document.body.removeChild(downloadLink);
}
function loadBtn() {
document.getElementById('load-input').click();
document.getElementById("load-input").addEventListener('change', function(e){
var file_reader = new FileReader();
file_reader.addEventListener('load', function(e) {
editor.getSession().setValue(e.target.result);
console.log("loaded.");
});
file_reader.readAsText(e.target.files[0]);
});
}
</script>
</body>
</html>