Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +276 -495
index.html
CHANGED
|
@@ -1,508 +1,289 @@
|
|
| 1 |
-
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="en">
|
| 4 |
<head>
|
| 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 |
</head>
|
| 172 |
<body>
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
<div style="display:flex;gap:8px;align-items:center;">
|
| 185 |
-
<input id="searchFile" placeholder="Search files..." style="flex:1;background:transparent;border:1px solid rgba(255,255,255,0.03);padding:8px;border-radius:8px;color:var(--muted)" />
|
| 186 |
-
<button class="btn" id="importBtn" title="Import .java"><i class="fa-solid fa-file-import"></i></button>
|
| 187 |
-
</div>
|
| 188 |
-
|
| 189 |
-
<div class="file-list" id="fileList" aria-live="polite" style="margin-top:8px;"></div>
|
| 190 |
-
|
| 191 |
-
<div style="margin-top:auto;font-size:13px;color:var(--muted);padding-top:10px">
|
| 192 |
-
<div style="display:flex;gap:8px;align-items:center">
|
| 193 |
-
<i class="fa-solid fa-circle-notch fa-spin" style="opacity:0.18"></i>
|
| 194 |
-
<div>Local-only — your files stay on your device</div>
|
| 195 |
</div>
|
| 196 |
-
|
|
|
|
| 197 |
</div>
|
| 198 |
|
| 199 |
-
<!-- Editor
|
| 200 |
<div class="panel editor-area">
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
| 212 |
</div>
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
<div class="cm-wrap" id="cmWrap">
|
| 216 |
-
<div id="editor"></div>
|
| 217 |
-
</div>
|
| 218 |
-
|
| 219 |
-
<div style="display:flex;gap:10px;align-items:center;justify-content:space-between;">
|
| 220 |
-
<div style="display:flex;gap:8px;align-items:center">
|
| 221 |
-
<div style="font-size:13px;color:var(--muted)">Active file: <span id="activeFile" style="color:#eafbff;font-weight:700">—</span></div>
|
| 222 |
-
</div>
|
| 223 |
-
<div style="font-size:13px;color:var(--muted)">Execution timeout: <strong>5s</strong></div>
|
| 224 |
-
</div>
|
| 225 |
-
|
| 226 |
-
<div class="console" id="console">Console output will appear here.</div>
|
| 227 |
</div>
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
function renderFiles(filter=''){
|
| 285 |
-
fileListEl.innerHTML = '';
|
| 286 |
-
const names = Object.keys(files).filter(n => n.toLowerCase().includes(filter.toLowerCase())).sort();
|
| 287 |
-
if(names.length===0){
|
| 288 |
-
fileListEl.innerHTML = `<div style="color:var(--muted);padding:10px;font-size:13px">No files yet. Create one.</div>`;
|
| 289 |
-
return;
|
| 290 |
-
}
|
| 291 |
-
names.forEach(name=>{
|
| 292 |
-
const div = document.createElement('div');
|
| 293 |
-
div.className = 'file-item' + (name===active ? ' active':'');
|
| 294 |
-
div.innerHTML = `<div class="file-meta"><i class="fa-solid fa-file-code"></i><div style="margin-left:8px">${name}</div></div>
|
| 295 |
-
<div style="display:flex;gap:8px;align-items:center">
|
| 296 |
-
<button class="btn" title="Rename" style="padding:6px 8px" onclick="renameFile(event,'${encodeURIComponent(name)}')"><i class="fa-solid fa-pen"></i></button>
|
| 297 |
-
<button class="btn" title="Duplicate" style="padding:6px 8px" onclick="duplicateFile(event,'${encodeURIComponent(name)}')"><i class="fa-solid fa-clone"></i></button>
|
| 298 |
-
<button class="btn" title="Open" style="padding:6px 8px" onclick="openFile(event,'${encodeURIComponent(name)}')"><i class="fa-solid fa-folder-open"></i></button>
|
| 299 |
-
</div>`;
|
| 300 |
fileListEl.appendChild(div);
|
| 301 |
-
});
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
// Actions
|
| 305 |
-
function newFile(){
|
| 306 |
-
let name = prompt('Filename (end with .java):','Main.java');
|
| 307 |
-
if(!name) return;
|
| 308 |
-
if(!name.endsWith('.java')) { alert('Filename must end with .java'); return; }
|
| 309 |
-
if(files[name]) { alert('File exists'); return; }
|
| 310 |
-
const classname = name.replace('.java','').replace(/[^A-Za-z0-9_]/g,'') || 'Main';
|
| 311 |
-
files[name] = `class ${classname} {\n public static void main(String[] args) {\n System.out.println("Hello ${classname}!");\n }\n}\n`;
|
| 312 |
-
saveToStorage();
|
| 313 |
-
setActive(name);
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
function openFile(e, nameEnc){
|
| 317 |
-
e.stopPropagation();
|
| 318 |
-
const name = decodeURIComponent(nameEnc);
|
| 319 |
-
setActive(name);
|
| 320 |
-
}
|
| 321 |
-
|
| 322 |
-
function renameFile(e,nameEnc){
|
| 323 |
-
e.stopPropagation();
|
| 324 |
-
const oldName = decodeURIComponent(nameEnc);
|
| 325 |
-
const newName = prompt('Rename file to:', oldName);
|
| 326 |
-
if(!newName || newName===oldName) return;
|
| 327 |
-
if(!newName.endsWith('.java')) { alert('Filename must end with .java'); return; }
|
| 328 |
-
if(files[newName]) { alert('A file with this name exists'); return; }
|
| 329 |
-
files[newName] = files[oldName];
|
| 330 |
-
delete files[oldName];
|
| 331 |
-
saveToStorage();
|
| 332 |
-
setActive(newName);
|
| 333 |
-
}
|
| 334 |
-
|
| 335 |
-
function duplicateFile(e,nameEnc){
|
| 336 |
-
e.stopPropagation();
|
| 337 |
-
const name = decodeURIComponent(nameEnc);
|
| 338 |
-
let copyName = name.replace('.java','') + '_copy.java';
|
| 339 |
-
let i=1;
|
| 340 |
-
while(files[copyName]) { copyName = name.replace('.java','') + `_copy${i}.java`; i++; }
|
| 341 |
-
files[copyName] = files[name];
|
| 342 |
-
saveToStorage();
|
| 343 |
-
setActive(copyName);
|
| 344 |
-
}
|
| 345 |
-
|
| 346 |
-
function deleteFile(){
|
| 347 |
-
if(!active) return alert('No file selected');
|
| 348 |
-
if(!confirm(`Delete ${active}?`)) return;
|
| 349 |
-
delete files[active];
|
| 350 |
-
saveToStorage();
|
| 351 |
-
active = null;
|
| 352 |
-
localStorage.removeItem('java_learner_active');
|
| 353 |
-
activeFileEl.innerText = '—';
|
| 354 |
-
editor.setValue('// Create a new file to start coding');
|
| 355 |
-
renderFiles();
|
| 356 |
-
}
|
| 357 |
-
|
| 358 |
-
function saveFile(){
|
| 359 |
-
if(!active) return alert('No file selected');
|
| 360 |
-
files[active] = editor.getValue();
|
| 361 |
-
saveToStorage();
|
| 362 |
-
flashMessage('Saved ✔');
|
| 363 |
-
}
|
| 364 |
-
|
| 365 |
-
function downloadFile(){
|
| 366 |
-
if(!active) return alert('No file selected');
|
| 367 |
-
const blob = new Blob([editor.getValue()], {type:'text/plain'});
|
| 368 |
-
const a = document.createElement('a');
|
| 369 |
-
a.href = URL.createObjectURL(blob);
|
| 370 |
-
a.download = active;
|
| 371 |
-
a.click();
|
| 372 |
-
URL.revokeObjectURL(a.href);
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
// Import from disk
|
| 376 |
-
document.getElementById('importBtn').addEventListener('click', ()=>document.getElementById('fileInput').click());
|
| 377 |
-
document.getElementById('fileInput').addEventListener('change', (e)=>{
|
| 378 |
-
const f = e.target.files[0];
|
| 379 |
-
if(!f) return;
|
| 380 |
-
const reader = new FileReader();
|
| 381 |
-
reader.onload = ()=> {
|
| 382 |
-
let name = f.name;
|
| 383 |
-
if(!name.endsWith('.java')) name = name + '.java';
|
| 384 |
-
files[name] = reader.result;
|
| 385 |
-
saveToStorage();
|
| 386 |
-
setActive(name);
|
| 387 |
-
};
|
| 388 |
-
reader.readAsText(f);
|
| 389 |
-
e.target.value = '';
|
| 390 |
-
});
|
| 391 |
-
|
| 392 |
-
// Search
|
| 393 |
-
document.getElementById('searchFile').addEventListener('input', (e)=>renderFiles(e.target.value));
|
| 394 |
-
|
| 395 |
-
// Toggle sidebar (mobile)
|
| 396 |
-
document.getElementById('toggleSidebar').addEventListener('click', ()=>{
|
| 397 |
-
const sb = document.getElementById('sidebar');
|
| 398 |
-
if(sb.style.display === 'none'){ sb.style.display='flex'; } else { sb.style.display='none'; }
|
| 399 |
-
setTimeout(()=>editor.refresh(),200);
|
| 400 |
});
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
});
|
| 410 |
-
document.getElementById('copyBtn').addEventListener('click', ()=>{
|
| 411 |
-
const sel = editor.getSelection();
|
| 412 |
-
if(!sel) return;
|
| 413 |
-
navigator.clipboard.writeText(sel);
|
| 414 |
-
});
|
| 415 |
-
document.getElementById('pasteBtn').addEventListener('click', async ()=>{
|
| 416 |
-
const txt = await navigator.clipboard.readText();
|
| 417 |
-
editor.replaceSelection(txt);
|
| 418 |
-
});
|
| 419 |
-
|
| 420 |
-
// Format (auto indent)
|
| 421 |
-
document.getElementById('formatBtn').addEventListener('click', ()=>{
|
| 422 |
-
try {
|
| 423 |
-
// basic auto-indent by selecting all and auto indenting
|
| 424 |
-
const total = {line: editor.lastLine()+1};
|
| 425 |
-
editor.execCommand('selectAll');
|
| 426 |
-
if(editor.execCommand('indentAuto')) {
|
| 427 |
-
// indentAuto available
|
| 428 |
-
} else {
|
| 429 |
-
// fallback: indentMore a few times to normalize
|
| 430 |
-
for(let i=0;i<3;i++) editor.execCommand('indentMore');
|
| 431 |
-
}
|
| 432 |
-
editor.execCommand('singleSelection');
|
| 433 |
-
flashMessage('Formatted');
|
| 434 |
-
} catch(e){
|
| 435 |
-
flashMessage('Format not available');
|
| 436 |
-
}
|
| 437 |
-
});
|
| 438 |
-
|
| 439 |
-
// Run code (send to FastAPI)
|
| 440 |
-
async function runCode(){
|
| 441 |
-
if(!active) return alert('No file selected');
|
| 442 |
-
saveFile();
|
| 443 |
-
consoleEl.innerText = '⏳ Running...';
|
| 444 |
-
try {
|
| 445 |
-
const resp = await fetch('/run-java', {
|
| 446 |
-
method:'POST',
|
| 447 |
-
headers:{'Content-Type':'application/json'},
|
| 448 |
-
body: JSON.stringify({ code: editor.getValue(), filename: active })
|
| 449 |
-
});
|
| 450 |
-
const data = await resp.json();
|
| 451 |
-
if(data.output) consoleEl.innerText = data.output;
|
| 452 |
-
else if(data.error) consoleEl.innerText = 'Error:\n' + data.error;
|
| 453 |
-
else consoleEl.innerText = JSON.stringify(data, null, 2);
|
| 454 |
-
} catch(err){
|
| 455 |
-
consoleEl.innerText = 'Network error: ' + err.message;
|
| 456 |
-
}
|
| 457 |
-
}
|
| 458 |
-
|
| 459 |
-
// Hook buttons
|
| 460 |
-
document.getElementById('newBtn').addEventListener('click', newFile);
|
| 461 |
-
document.getElementById('saveBtn').addEventListener('click', saveFile);
|
| 462 |
-
document.getElementById('downloadBtn').addEventListener('click', downloadFile);
|
| 463 |
-
document.getElementById('runBtn').addEventListener('click', runCode);
|
| 464 |
-
document.getElementById('deleteBtn').addEventListener('click', deleteFile);
|
| 465 |
-
|
| 466 |
-
// Shortcut: Ctrl+S save, Ctrl+Enter run
|
| 467 |
-
window.addEventListener('keydown', function(e){
|
| 468 |
-
if((e.ctrlKey || e.metaKey) && e.key.toLowerCase()==='s'){ e.preventDefault(); saveFile(); }
|
| 469 |
-
if((e.ctrlKey || e.metaKey) && e.key==='Enter'){ e.preventDefault(); runCode(); }
|
| 470 |
-
});
|
| 471 |
-
|
| 472 |
-
// Visual flash message
|
| 473 |
-
function flashMessage(msg){
|
| 474 |
-
const el = document.createElement('div');
|
| 475 |
-
el.innerText = msg;
|
| 476 |
-
el.style.position='fixed';
|
| 477 |
-
el.style.right='18px';
|
| 478 |
-
el.style.bottom='18px';
|
| 479 |
-
el.style.background='linear-gradient(90deg, rgba(108,140,255,0.14), rgba(139,229,208,0.04))';
|
| 480 |
-
el.style.border='1px solid rgba(255,255,255,0.04)';
|
| 481 |
-
el.style.padding='10px 14px';
|
| 482 |
-
el.style.borderRadius='10px';
|
| 483 |
-
el.style.color='#eaf6ff';
|
| 484 |
-
el.style.boxShadow='0 8px 26px rgba(0,0,0,0.5)';
|
| 485 |
-
document.body.appendChild(el);
|
| 486 |
-
setTimeout(()=> el.style.opacity='0', 1800);
|
| 487 |
-
setTimeout(()=> el.remove(), 2400);
|
| 488 |
-
}
|
| 489 |
-
|
| 490 |
-
// Initialize app state
|
| 491 |
-
if(Object.keys(files).length === 0) {
|
| 492 |
-
// create default starter file
|
| 493 |
-
files['Main.java'] = editor.getValue();
|
| 494 |
-
saveToStorage();
|
| 495 |
-
}
|
| 496 |
-
if(!active) {
|
| 497 |
-
setActive(Object.keys(files)[0]);
|
| 498 |
-
} else {
|
| 499 |
-
// ensure editor shows active file
|
| 500 |
-
if(files[active]) editor.setValue(files[active]); else setActive(Object.keys(files)[0]);
|
| 501 |
-
}
|
| 502 |
-
renderFiles();
|
| 503 |
-
|
| 504 |
-
// ensure refresh after everything loaded
|
| 505 |
-
setTimeout(()=>editor.refresh(),250);
|
| 506 |
-
</script>
|
| 507 |
-
</body>
|
| 508 |
-
</html>
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>JavaRunner — Learn & Run Java Online</title>
|
| 7 |
+
<meta name="description" content="JavaRunner is a mobile-friendly online Java IDE. Write, run, save, and download Java code. Perfect for beginners like Ragini Didi.">
|
| 8 |
+
<meta name="keywords" content="Java IDE, Online Java compiler, JavaRunner, Learn Java, Java code editor, mobile-friendly IDE, Ragini Didi">
|
| 9 |
+
<meta name="author" content="Saksham Pathak">
|
| 10 |
+
<meta name="robots" content="index, follow">
|
| 11 |
+
|
| 12 |
+
<!-- Open Graph for SEO & social -->
|
| 13 |
+
<meta property="og:title" content="JavaRunner — Learn & Run Java Online">
|
| 14 |
+
<meta property="og:description" content="JavaRunner is a mobile-friendly online Java IDE. Write, run, save, and download Java code. Perfect for beginners like Ragini Didi.">
|
| 15 |
+
<meta property="og:type" content="website">
|
| 16 |
+
|
| 17 |
+
<!-- Font -->
|
| 18 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
|
| 19 |
+
|
| 20 |
+
<!-- Font Awesome -->
|
| 21 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
|
| 22 |
+
|
| 23 |
+
<!-- CodeMirror -->
|
| 24 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
|
| 25 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script>
|
| 26 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/clike/clike.min.js"></script>
|
| 27 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/closebrackets.min.js"></script>
|
| 28 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/matchbrackets.min.js"></script>
|
| 29 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/indentation.min.js"></script>
|
| 30 |
+
|
| 31 |
+
<style>
|
| 32 |
+
:root {
|
| 33 |
+
--bg:#0b1b2b;
|
| 34 |
+
--glass: rgba(255,255,255,0.05);
|
| 35 |
+
--glass-hover: rgba(255,255,255,0.08);
|
| 36 |
+
--accent:#6c8cff;
|
| 37 |
+
--accent-light:#8be5d0;
|
| 38 |
+
--text:#e6eef8;
|
| 39 |
+
--muted:#9aa4b2;
|
| 40 |
+
--radius:14px;
|
| 41 |
+
--shadow:0 8px 30px rgba(2,6,23,0.6);
|
| 42 |
+
}
|
| 43 |
+
*{box-sizing:border-box;}
|
| 44 |
+
body{
|
| 45 |
+
margin:0;
|
| 46 |
+
font-family: 'Inter', sans-serif;
|
| 47 |
+
background: linear-gradient(180deg, #071227, #0d1a2b);
|
| 48 |
+
color:var(--text);
|
| 49 |
+
min-height:100vh;
|
| 50 |
+
display:flex;
|
| 51 |
+
flex-direction:column;
|
| 52 |
+
align-items:center;
|
| 53 |
+
padding:10px;
|
| 54 |
+
}
|
| 55 |
+
h1,h2,h3,h4,h5{margin:0;padding:0;}
|
| 56 |
+
a{text-decoration:none;color:var(--accent);}
|
| 57 |
+
a:hover{color:var(--accent-light);}
|
| 58 |
+
|
| 59 |
+
/* App container */
|
| 60 |
+
.app{
|
| 61 |
+
display:flex;
|
| 62 |
+
flex-direction:row;
|
| 63 |
+
gap:12px;
|
| 64 |
+
width:100%;
|
| 65 |
+
max-width:1200px;
|
| 66 |
+
flex:1;
|
| 67 |
+
}
|
| 68 |
+
.panel{
|
| 69 |
+
background: var(--glass);
|
| 70 |
+
backdrop-filter: blur(12px) saturate(1.1);
|
| 71 |
+
border-radius: var(--radius);
|
| 72 |
+
padding:12px;
|
| 73 |
+
box-shadow: var(--shadow);
|
| 74 |
+
border:1px solid rgba(255,255,255,0.08);
|
| 75 |
+
transition: transform .2s ease, box-shadow .2s ease;
|
| 76 |
+
}
|
| 77 |
+
.panel:hover{transform:translateY(-3px);box-shadow:0 16px 40px rgba(8,14,40,0.5);}
|
| 78 |
+
|
| 79 |
+
/* Sidebar */
|
| 80 |
+
.sidebar{
|
| 81 |
+
flex:0 0 240px;
|
| 82 |
+
display:flex;
|
| 83 |
+
flex-direction:column;
|
| 84 |
+
gap:10px;
|
| 85 |
+
height:calc(100vh - 40px);
|
| 86 |
+
}
|
| 87 |
+
.sidebar-header{
|
| 88 |
+
display:flex;
|
| 89 |
+
justify-content:space-between;
|
| 90 |
+
align-items:center;
|
| 91 |
+
margin-bottom:8px;
|
| 92 |
+
}
|
| 93 |
+
.brand{
|
| 94 |
+
font-weight:700;
|
| 95 |
+
font-size:18px;
|
| 96 |
+
color:var(--accent);
|
| 97 |
+
display:flex;
|
| 98 |
+
align-items:center;
|
| 99 |
+
gap:8px;
|
| 100 |
+
}
|
| 101 |
+
.brand i{font-size:20px;}
|
| 102 |
+
.file-list{
|
| 103 |
+
flex:1;
|
| 104 |
+
overflow-y:auto;
|
| 105 |
+
display:flex;
|
| 106 |
+
flex-direction:column;
|
| 107 |
+
gap:6px;
|
| 108 |
+
}
|
| 109 |
+
.file-item{
|
| 110 |
+
display:flex;
|
| 111 |
+
justify-content:space-between;
|
| 112 |
+
align-items:center;
|
| 113 |
+
padding:6px 8px;
|
| 114 |
+
border-radius:10px;
|
| 115 |
+
cursor:pointer;
|
| 116 |
+
background: rgba(255,255,255,0.02);
|
| 117 |
+
transition:0.15s ease;
|
| 118 |
+
}
|
| 119 |
+
.file-item:hover{background:var(--glass-hover);}
|
| 120 |
+
.file-item.active{background:rgba(108,140,255,0.12);color:#fff;}
|
| 121 |
+
.file-actions{display:flex;gap:6px;align-items:center;}
|
| 122 |
+
|
| 123 |
+
/* Editor area */
|
| 124 |
+
.editor-area{
|
| 125 |
+
flex:1;
|
| 126 |
+
display:flex;
|
| 127 |
+
flex-direction:column;
|
| 128 |
+
gap:8px;
|
| 129 |
+
min-height:400px;
|
| 130 |
+
}
|
| 131 |
+
.cm-wrap{border-radius:12px;overflow:hidden;border:1px solid rgba(255,255,255,0.04);}
|
| 132 |
+
.CodeMirror{height:calc(100vh - 240px);background: rgba(2,6,23,0.7); color:#e8f1ff; font-size:13px;}
|
| 133 |
+
|
| 134 |
+
/* Buttons */
|
| 135 |
+
.btn{
|
| 136 |
+
background: rgba(255,255,255,0.03);
|
| 137 |
+
border:1px solid rgba(255,255,255,0.08);
|
| 138 |
+
color:var(--muted);
|
| 139 |
+
padding:6px 10px;
|
| 140 |
+
border-radius:10px;
|
| 141 |
+
cursor:pointer;
|
| 142 |
+
display:inline-flex;
|
| 143 |
+
align-items:center;
|
| 144 |
+
gap:6px;
|
| 145 |
+
transition:all .15s ease;
|
| 146 |
+
}
|
| 147 |
+
.btn:hover{color:#fff;transform:translateY(-2px);background:var(--glass-hover);}
|
| 148 |
+
.btn-primary{
|
| 149 |
+
background: linear-gradient(90deg,var(--accent),var(--accent-light));
|
| 150 |
+
color:#04253b;
|
| 151 |
+
padding:10px 14px;
|
| 152 |
+
font-weight:700;
|
| 153 |
+
border:none;
|
| 154 |
+
}
|
| 155 |
+
.console{
|
| 156 |
+
margin-top:6px;
|
| 157 |
+
background: rgba(0,0,0,0.5);
|
| 158 |
+
border-radius:10px;
|
| 159 |
+
padding:12px;
|
| 160 |
+
font-family:monospace;
|
| 161 |
+
color:#cfe7ff;
|
| 162 |
+
min-height:120px;
|
| 163 |
+
overflow:auto;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/* Footer */
|
| 167 |
+
footer{
|
| 168 |
+
text-align:center;
|
| 169 |
+
color:var(--muted);
|
| 170 |
+
font-size:14px;
|
| 171 |
+
padding:12px 0 4px 0;
|
| 172 |
+
}
|
| 173 |
+
footer .note{color:#c7d7ff;font-weight:600;}
|
| 174 |
+
|
| 175 |
+
/* Responsive */
|
| 176 |
+
@media (max-width:900px){
|
| 177 |
+
.app{flex-direction:column;}
|
| 178 |
+
.sidebar{width:100%;height:auto;order:2;}
|
| 179 |
+
.editor-area{order:1;}
|
| 180 |
+
.CodeMirror{height:300px;}
|
| 181 |
+
}
|
| 182 |
+
@media (max-width:480px){
|
| 183 |
+
body{padding:6px;}
|
| 184 |
+
.brand{font-size:16px;}
|
| 185 |
+
.btn{padding:5px 8px;font-size:13px;}
|
| 186 |
+
.btn-primary{padding:8px 10px;font-size:14px;}
|
| 187 |
+
}
|
| 188 |
+
</style>
|
| 189 |
</head>
|
| 190 |
<body>
|
| 191 |
+
<header class="sidebar-header">
|
| 192 |
+
<div class="brand"><i class="fa-solid fa-rocket"></i> JavaRunner</div>
|
| 193 |
+
</header>
|
| 194 |
+
|
| 195 |
+
<div class="app">
|
| 196 |
+
<!-- Sidebar -->
|
| 197 |
+
<div class="panel sidebar">
|
| 198 |
+
<div class="sidebar-header">
|
| 199 |
+
<button class="btn" id="newBtn"><i class="fa-solid fa-file-circle-plus"></i> New</button>
|
| 200 |
+
<button class="btn" id="importBtn"><i class="fa-solid fa-file-import"></i> Import</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
</div>
|
| 202 |
+
<input type="text" placeholder="Search files..." id="searchFile" style="width:100%;padding:6px;border-radius:8px;background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.08);color:var(--muted);margin-bottom:6px;">
|
| 203 |
+
<div class="file-list" id="fileList"></div>
|
| 204 |
</div>
|
| 205 |
|
| 206 |
+
<!-- Editor -->
|
| 207 |
<div class="panel editor-area">
|
| 208 |
+
<div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;">
|
| 209 |
+
<div>Active File: <span id="activeFile">—</span></div>
|
| 210 |
+
<div style="display:flex;gap:6px;flex-wrap:wrap;">
|
| 211 |
+
<button class="btn-primary" id="runBtn"><i class="fa-solid fa-play"></i> Run</button>
|
| 212 |
+
<button class="btn" id="saveBtn"><i class="fa-solid fa-floppy-disk"></i> Save</button>
|
| 213 |
+
<button class="btn" id="downloadBtn"><i class="fa-solid fa-download"></i> Download</button>
|
| 214 |
+
<button class="btn" id="formatBtn"><i class="fa-solid fa-align-left"></i> Format</button>
|
| 215 |
+
<button class="btn" id="cutBtn"><i class="fa-solid fa-cut"></i></button>
|
| 216 |
+
<button class="btn" id="copyBtn"><i class="fa-solid fa-copy"></i></button>
|
| 217 |
+
<button class="btn" id="pasteBtn"><i class="fa-solid fa-clipboard"></i></button>
|
| 218 |
+
<button class="btn" id="deleteBtn"><i class="fa-solid fa-trash"></i></button>
|
| 219 |
+
</div>
|
| 220 |
</div>
|
| 221 |
+
<div class="cm-wrap" id="cmWrap"><div id="editor"></div></div>
|
| 222 |
+
<div class="console" id="console">Console output will appear here.</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
</div>
|
| 224 |
+
</div>
|
| 225 |
+
|
| 226 |
+
<footer>
|
| 227 |
+
Made with ❤️ for <span class="note">Ragini Didi</span>
|
| 228 |
+
</footer>
|
| 229 |
+
|
| 230 |
+
<input type="file" id="fileInput" accept=".java" style="display:none">
|
| 231 |
+
|
| 232 |
+
<script>
|
| 233 |
+
// ---------- Editor setup ----------
|
| 234 |
+
const editor = CodeMirror(document.getElementById('editor'),{
|
| 235 |
+
mode:"text/x-java",
|
| 236 |
+
lineNumbers:true,
|
| 237 |
+
tabSize:4,
|
| 238 |
+
indentUnit:4,
|
| 239 |
+
autoCloseBrackets:true,
|
| 240 |
+
matchBrackets:true,
|
| 241 |
+
value:"class Main {\n public static void main(String[] args) {\n System.out.println(\"Hello Ragini!\");\n }\n}"
|
| 242 |
+
});
|
| 243 |
+
|
| 244 |
+
// Resize editor for mobile
|
| 245 |
+
function resizeEditor(){
|
| 246 |
+
const wrap=document.querySelector('.CodeMirror');
|
| 247 |
+
if(!wrap) return;
|
| 248 |
+
let vh=window.innerHeight;
|
| 249 |
+
wrap.style.height=(vh - 280)+'px';
|
| 250 |
+
editor.refresh();
|
| 251 |
+
}
|
| 252 |
+
window.addEventListener('resize',resizeEditor);
|
| 253 |
+
setTimeout(resizeEditor,200);
|
| 254 |
+
|
| 255 |
+
// ---------- Local storage ----------
|
| 256 |
+
let files=JSON.parse(localStorage.getItem('javaRunner_files')||'{}');
|
| 257 |
+
let active=localStorage.getItem('javaRunner_active')||null;
|
| 258 |
+
const fileListEl=document.getElementById('fileList');
|
| 259 |
+
const activeFileEl=document.getElementById('activeFile');
|
| 260 |
+
const consoleEl=document.getElementById('console');
|
| 261 |
+
|
| 262 |
+
function saveToStorage(){localStorage.setItem('javaRunner_files',JSON.stringify(files));}
|
| 263 |
+
function setActive(name){
|
| 264 |
+
active=name;
|
| 265 |
+
localStorage.setItem('javaRunner_active',active);
|
| 266 |
+
activeFileEl.innerText=name||'—';
|
| 267 |
+
renderFiles();
|
| 268 |
+
if(active && files[active]) editor.setValue(files[active]);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
function renderFiles(filter=''){
|
| 272 |
+
fileListEl.innerHTML='';
|
| 273 |
+
const names=Object.keys(files).filter(n=>n.toLowerCase().includes(filter.toLowerCase())).sort();
|
| 274 |
+
if(names.length===0){fileListEl.innerHTML='<div style="color:'+ 'var(--muted)' +';padding:10px;font-size:13px">No files yet.</div>';return;}
|
| 275 |
+
names.forEach(name=>{
|
| 276 |
+
const div=document.createElement('div');
|
| 277 |
+
div.className='file-item'+(name===active?' active':'');
|
| 278 |
+
div.innerHTML=`<div>${name}</div><div style="display:flex;gap:6px;">
|
| 279 |
+
<button class="btn" onclick="openFile('${name}')"><i class="fa-solid fa-folder-open"></i></button></div>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
fileListEl.appendChild(div);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
});
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
function newFile(){
|
| 285 |
+
let name=prompt('Filename (end with .java)','Main.java');
|
| 286 |
+
if(!name) return;if(!name.endsWith('.java')){alert('Filename must end with .java');return;}
|
| 287 |
+
if(files[name]){alert('File exists');return;}
|
| 288 |
+
const classname=name.replace('.java','').replace(/[^A-Za-z0-9_]/g,'')||'Main';
|
| 289 |
+
files[name]=`class ${classname} {\n public static void main(String[] args) {\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|