-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
210 lines (154 loc) · 6.89 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
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
208
209
210
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="data/cdn.jsdelivr.net_npm_bootstrap@5.3.0_dist_css_bootstrap.min.css" rel="stylesheet">
<script src="data/cdn.jsdelivr.net_npm_bootstrap@5.3.0_dist_js_bootstrap.bundle.min.js"></script>
<script src="data/code.jquery.com_jquery-3.6.0.min.js"></script>
<script script src="data/js/dark.js" defer></script>
<link rel="stylesheet" type="text/css" href="data/css/ux.css">
</head>
<body class="centered-content">
<h4>{js}-GO</h4>
<div style="text-align: center;">
<br>
<button id="clearButton" class="btn"><img src="data/img/clear.png" width="40" height="40"></button>
<button id="saveButton" class="btn"><img src="data/img/1.png" width="40" height="40"></button>
<button id="openButton" class="btn pop-in"><img src="data/img/0.png" width="40" height="40"></button>
<br><br>
<textarea id="code" rows="10" class="form-control" style="width: 100%;">console.log("Hello world ^_^");</textarea>
<br>
<div style="text-align: center;">
<button id="runButton" class="btn "><img src="data/img/run.png" width="48" height="46"></button>
</div>
<br>
<button id="toggleDarkModeButton" class="btn btn-dark-mode"> Mode Gelap</button><br>
</div>
<!-- Modal untuk Output -->
<div class="modal fade" id="outputModal" tabindex="-1" aria-labelledby="outputModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="outputModalLabel"><img src="data/img/run.png" width="34" height="34"> Output</h5>
</div>
<div class="modal-body">
<pre id="outputModalContent" class="border"></pre>
<button type="button" data-bs-dismiss="modal" class="btn btn-danger" style="width: 100%;">Tutup</button>
</div>
</div>
</div>
</div>
<div >
</div>
<!-- Modal konfirmasi untuk menghapus teks -->
<div class="modal fade" id="clearConfirmationModal" tabindex="-1" aria-labelledby="clearConfirmationModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="clearConfirmationModalLabel"><img src="data/img/clear.png" width="34" height="34"> bersihkan sintaks ?</h5>
</div>
<div class="modal-body">
<p> Apakah kamu yakin ingin menghapus teks dari sintaks yang telah kamu tulis?</p>
</div>
<div class="modal-footer">
<button type="button" id="confirmClearButton" class="btn btn-danger" style="width: 100%;">Ya</button>
<button type="button" id="cancelClearButton" class="btn btn-secondary" data-bs-dismiss="modal" style="width: 100%;">Tidak</button>
</div>
</div>
</div>
</div>
<!-- Modal konfirmasi untuk menghapus teks -->
<div class="modal fade" id="clearConfirmationModal" tabindex="-1" aria-labelledby="clearConfirmationModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="clearConfirmationModalLabel"><img src="data/img/clear.png" width="34" height="34"> Hapus Teks ?</h5>
</div>
<div class="modal-body">
Apakah kamu yakin ingin menghapus teks dari input yang telah kamu tulis?
</div>
<div class="modal-footer">
<button type="button" id="confirmClearButton" class="btn btn-danger" style="width: 100%;">Ya</button>
<button type="button" id="cancelClearButton" class="btn btn-secondary" data-bs-dismiss="modal" style="width: 100%;">Tidak</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
// ...
// Menambahkan event listener untuk tombol "Clear Text"
$('#clearButton').click(function() {
$('#clearConfirmationModal').removeClass('zoom-out').addClass('zoom-in').modal('show');
});
// Event listener untuk tombol "Ya" pada modal konfirmasi
$('#confirmClearButton').click(function() {
$('#code').val(''); // Hapus teks dari textarea
$('#clearConfirmationModal').removeClass('zoom-out').addClass('zoom-out');
});
// Event listener untuk tombol "Tidak" pada modal konfirmasi
$('#cancelClearButton').click(function() {
$('#clearConfirmationModal').removeClass('zoom-out').addClass('zoom-out');
});
// Event listener saat animasi modal selesai untuk menghilangkan modal
$('#clearConfirmationModal').on('animationend', function() {
if ($(this).hasClass('zoom-out')) {
$(this).modal('hide');
}
});
// ...
});
</script>
<script>
$(document).ready(function() {
document.getElementById('runButton').addEventListener('click', function() {
const code = document.getElementById('code').value;
const outputElement = document.getElementById('outputModalContent');
outputElement.textContent = '';
try {
const consoleLogBuffer = [];
const originalConsoleLog = console.log;
console.log = function(...args) {
consoleLogBuffer.push(args.map(arg => String(arg)).join(' '));
originalConsoleLog(...args);
};
eval(code);
outputElement.textContent = consoleLogBuffer.join('\n');
$('#outputModal').modal('show'); // Munculkan modal dengan animasi
} catch (error) {
outputElement.textContent = 'Error: ' + error.message;
$('#outputModal').modal('show'); // Munculkan modal dengan animasi
}
});
document.getElementById('saveButton').addEventListener('click', function() {
const code = document.getElementById('code').value;
const fileName = prompt("Masukkan nama file yang ingin kamu simpan", "");
if (fileName) {
const blob = new Blob([code], { type: 'text/plain;charset=utf-8' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
});
document.getElementById('openButton').addEventListener('click', function() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.txt, .js';
input.addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
document.getElementById('code').value = event.target.result;
};
reader.readAsText(file);
}
});
input.click();
});
});
</script>
</body>
</html>