Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +466 -94
index.html
CHANGED
|
@@ -1,136 +1,508 @@
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
<meta charset="
|
| 5 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
|
| 7 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script>
|
| 8 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/clike/clike.min.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
<style>
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</style>
|
| 24 |
</head>
|
| 25 |
<body>
|
| 26 |
-
<div
|
| 27 |
-
|
| 28 |
-
<
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
<div
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
</div>
|
| 40 |
-
<pre id="output"></pre>
|
| 41 |
</div>
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
<script>
|
| 44 |
-
|
|
|
|
| 45 |
mode: "text/x-java",
|
| 46 |
-
theme: "default",
|
| 47 |
lineNumbers: true,
|
|
|
|
| 48 |
indentUnit: 4,
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
});
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
list.appendChild(btn);
|
| 64 |
-
});
|
| 65 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 74 |
renderFiles();
|
| 75 |
-
|
| 76 |
}
|
| 77 |
|
| 78 |
-
function
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
alert(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
-
function
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
currentFile = null;
|
| 96 |
-
saveStorage();
|
| 97 |
-
renderFiles();
|
| 98 |
-
editor.setValue("");
|
| 99 |
-
}
|
| 100 |
}
|
| 101 |
|
| 102 |
-
function
|
| 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 |
</script>
|
| 135 |
</body>
|
| 136 |
</html>
|
|
|
|
| 1 |
+
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="en">
|
| 4 |
<head>
|
| 5 |
+
<meta charset="utf-8" />
|
| 6 |
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
| 7 |
+
<title>Java Learner — Mini IDE</title>
|
| 8 |
+
|
| 9 |
+
<!-- Font (modern, clean) -->
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
|
| 11 |
+
|
| 12 |
+
<!-- Font Awesome (free icons) -->
|
| 13 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" integrity="sha512-t9f6b...." crossorigin="anonymous" referrerpolicy="no-referrer" />
|
| 14 |
+
|
| 15 |
+
<!-- CodeMirror 5 -->
|
| 16 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
|
| 17 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script>
|
| 18 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/clike/clike.min.js"></script>
|
| 19 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/closebrackets.min.js"></script>
|
| 20 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/matchbrackets.min.js"></script>
|
| 21 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/indentation.min.js"></script>
|
| 22 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/format/formatting.min.js"></script>
|
| 23 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/indent/auto-indent.min.js"></script>
|
| 24 |
+
<!-- Note: some addons are bundled differently across versions; the code uses indent/auto features -->
|
| 25 |
+
|
| 26 |
<style>
|
| 27 |
+
:root{
|
| 28 |
+
--bg:#0f1720;
|
| 29 |
+
--glass: rgba(255,255,255,0.04);
|
| 30 |
+
--glass-2: rgba(255,255,255,0.025);
|
| 31 |
+
--accent: #6c8cff;
|
| 32 |
+
--accent-2: #8be5d0;
|
| 33 |
+
--muted: #9aa4b2;
|
| 34 |
+
--card-shadow: 0 8px 30px rgba(2,6,23,0.6);
|
| 35 |
+
--radius: 14px;
|
| 36 |
+
}
|
| 37 |
+
*{box-sizing:border-box}
|
| 38 |
+
html,body{height:100%}
|
| 39 |
+
body{
|
| 40 |
+
margin:0;
|
| 41 |
+
font-family:Inter,system-ui,Segoe UI,Roboto,"Helvetica Neue",Arial;
|
| 42 |
+
background: linear-gradient(180deg, #071227 0%, #0d1a2b 100%);
|
| 43 |
+
color:#e6eef8;
|
| 44 |
+
-webkit-font-smoothing:antialiased;
|
| 45 |
+
-moz-osx-font-smoothing:grayscale;
|
| 46 |
+
padding:20px;
|
| 47 |
+
display:flex;
|
| 48 |
+
flex-direction:column;
|
| 49 |
+
gap:14px;
|
| 50 |
+
min-height:100vh;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/* App container */
|
| 54 |
+
.app {
|
| 55 |
+
display:grid;
|
| 56 |
+
grid-template-columns: 260px 1fr;
|
| 57 |
+
gap:18px;
|
| 58 |
+
align-items:stretch;
|
| 59 |
+
width:100%;
|
| 60 |
+
max-width:1200px;
|
| 61 |
+
margin:0 auto;
|
| 62 |
+
flex:1 1 auto;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/* Glass panel */
|
| 66 |
+
.panel {
|
| 67 |
+
background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
|
| 68 |
+
border-radius:var(--radius);
|
| 69 |
+
backdrop-filter: blur(8px) saturate(1.05);
|
| 70 |
+
box-shadow: var(--card-shadow);
|
| 71 |
+
border: 1px solid rgba(255,255,255,0.04);
|
| 72 |
+
padding:14px;
|
| 73 |
+
transition: transform .18s ease, box-shadow .2s ease;
|
| 74 |
+
}
|
| 75 |
+
.panel:hover{ transform: translateY(-4px); box-shadow: 0 16px 40px rgba(8,14,40,0.6); }
|
| 76 |
+
|
| 77 |
+
/* File sidebar */
|
| 78 |
+
.files {
|
| 79 |
+
display:flex;
|
| 80 |
+
flex-direction:column;
|
| 81 |
+
gap:12px;
|
| 82 |
+
min-height:200px;
|
| 83 |
+
}
|
| 84 |
+
.files .top {
|
| 85 |
+
display:flex; gap:8px; align-items:center; justify-content:space-between;
|
| 86 |
+
}
|
| 87 |
+
.brand {
|
| 88 |
+
display:flex; gap:12px; align-items:center;
|
| 89 |
+
font-weight:600; font-size:16px; color:var(--accent);
|
| 90 |
+
}
|
| 91 |
+
.brand i { font-size:20px; opacity:0.95; transform:translateY(-1px) }
|
| 92 |
+
|
| 93 |
+
.file-actions { display:flex; gap:8px; align-items:center; }
|
| 94 |
+
.btn {
|
| 95 |
+
background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
|
| 96 |
+
border: 1px solid rgba(255,255,255,0.04);
|
| 97 |
+
color:var(--muted);
|
| 98 |
+
padding:8px 10px;
|
| 99 |
+
border-radius:10px;
|
| 100 |
+
font-weight:600;
|
| 101 |
+
display:inline-flex; gap:8px; align-items:center;
|
| 102 |
+
cursor:pointer;
|
| 103 |
+
transition: all .14s ease;
|
| 104 |
+
white-space:nowrap;
|
| 105 |
+
}
|
| 106 |
+
.btn:hover{ transform: translateY(-3px); color:#fff; box-shadow: 0 8px 20px rgba(0,0,0,0.4); }
|
| 107 |
+
|
| 108 |
+
/* File list */
|
| 109 |
+
.file-list { display:flex; flex-direction:column; gap:8px; overflow:auto; padding-right:6px; }
|
| 110 |
+
.file-item {
|
| 111 |
+
display:flex; align-items:center; gap:10px; justify-content:space-between;
|
| 112 |
+
padding:8px; border-radius:9px; cursor:pointer; color:#dbe8ff; font-weight:600;
|
| 113 |
+
transition: background .12s ease, transform .12s ease;
|
| 114 |
+
background: linear-gradient(180deg, rgba(255,255,255,0.01), rgba(255,255,255,0.005));
|
| 115 |
+
border:1px solid rgba(255,255,255,0.02);
|
| 116 |
+
}
|
| 117 |
+
.file-item:hover{ transform: translateY(-3px); box-shadow: 0 6px 18px rgba(8,12,32,0.45); }
|
| 118 |
+
.file-item.active { background: linear-gradient(90deg, rgba(108,140,255,0.12), rgba(139,229,208,0.03)); color:#fff; }
|
| 119 |
+
|
| 120 |
+
.file-meta { display:flex; gap:8px; align-items:center; }
|
| 121 |
+
|
| 122 |
+
/* Editor area */
|
| 123 |
+
.editor-area { display:flex; flex-direction:column; gap:10px; min-height:400px; }
|
| 124 |
+
.topbar {
|
| 125 |
+
display:flex; align-items:center; justify-content:space-between; gap:6px;
|
| 126 |
+
}
|
| 127 |
+
.title {
|
| 128 |
+
font-size:14px; color:var(--muted);
|
| 129 |
+
}
|
| 130 |
+
.controls { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
|
| 131 |
+
|
| 132 |
+
.primary {
|
| 133 |
+
background: linear-gradient(90deg,var(--accent), #7bd0ff);
|
| 134 |
+
color:#04253b; padding:10px 14px; border-radius:10px; font-weight:700; border:none; cursor:pointer;
|
| 135 |
+
box-shadow: 0 8px 30px rgba(108,140,255,0.14);
|
| 136 |
+
display:inline-flex; gap:8px; align-items:center;
|
| 137 |
+
}
|
| 138 |
+
.secondary { background: transparent; border:1px solid rgba(255,255,255,0.05); color:var(--muted); padding:8px 12px; border-radius:10px; cursor:pointer; }
|
| 139 |
+
|
| 140 |
+
/* CodeMirror container */
|
| 141 |
+
.cm-wrap { border-radius:12px; overflow:hidden; border:1px solid rgba(255,255,255,0.02); }
|
| 142 |
+
.CodeMirror { height: calc(100vh - 360px); min-height:240px; background: linear-gradient(180deg, rgba(2,6,23,0.6), rgba(2,6,23,0.55)); color:#e8f1ff; font-size:13px; }
|
| 143 |
+
|
| 144 |
+
/* Output console */
|
| 145 |
+
.console {
|
| 146 |
+
margin-top:6px;
|
| 147 |
+
background: linear-gradient(180deg, rgba(0,0,0,0.5), rgba(2,6,23,0.6));
|
| 148 |
+
border-radius:10px; padding:12px; font-family:monospace; color:#cfe7ff; height:140px; overflow:auto;
|
| 149 |
+
border:1px solid rgba(255,255,255,0.02);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/* Footer */
|
| 153 |
+
footer { text-align:center; color:var(--muted); font-size:13px; padding:10px 0; }
|
| 154 |
+
.note { color:#c7d7ff; font-weight:600; }
|
| 155 |
+
|
| 156 |
+
/* Responsive */
|
| 157 |
+
@media (max-width:900px) {
|
| 158 |
+
.app { grid-template-columns: 1fr; padding-bottom:8px; }
|
| 159 |
+
.files { order:2; }
|
| 160 |
+
.editor-area { order:1; }
|
| 161 |
+
.CodeMirror { height: calc(100vh - 420px); }
|
| 162 |
+
}
|
| 163 |
+
@media (max-width:480px) {
|
| 164 |
+
body{padding:12px}
|
| 165 |
+
.brand { font-size:14px }
|
| 166 |
+
.btn { padding:6px 8px; font-size:13px }
|
| 167 |
+
.primary { padding:8px 10px; font-size:14px }
|
| 168 |
+
.CodeMirror { font-size:12px }
|
| 169 |
+
}
|
| 170 |
</style>
|
| 171 |
</head>
|
| 172 |
<body>
|
| 173 |
+
<div class="app">
|
| 174 |
+
<!-- Files Sidebar -->
|
| 175 |
+
<div class="panel files" id="sidebar">
|
| 176 |
+
<div class="top">
|
| 177 |
+
<div class="brand"><i class="fa-solid fa-flask"></i> Java Learner</div>
|
| 178 |
+
<div style="display:flex;gap:8px;align-items:center">
|
| 179 |
+
<button class="btn" id="toggleSidebar" title="Hide files"><i class="fa-solid fa-bars"></i></button>
|
| 180 |
+
<button class="btn" id="newBtn" title="New file"><i class="fa-solid fa-file-circle-plus"></i> New</button>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 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 |
+
</div>
|
| 197 |
+
</div>
|
| 198 |
|
| 199 |
+
<!-- Editor area -->
|
| 200 |
+
<div class="panel editor-area">
|
| 201 |
+
<div class="topbar">
|
| 202 |
+
<div class="title">Interactive Java editor • Friendly for mobile & desktop</div>
|
| 203 |
+
<div class="controls">
|
| 204 |
+
<button class="primary" id="runBtn"><i class="fa-solid fa-play"></i> Run</button>
|
| 205 |
+
<button class="secondary" id="saveBtn" title="Save to device"><i class="fa-solid fa-floppy-disk"></i> Save</button>
|
| 206 |
+
<button class="secondary" id="downloadBtn" title="Download file"><i class="fa-solid fa-download"></i> Download</button>
|
| 207 |
+
<button class="secondary" id="formatBtn" title="Auto-indent / format"><i class="fa-solid fa-align-left"></i> Format</button>
|
| 208 |
+
<button class="secondary" id="cutBtn" title="Cut selection"><i class="fa-solid fa-cut"></i></button>
|
| 209 |
+
<button class="secondary" id="copyBtn" title="Copy selection"><i class="fa-solid fa-copy"></i></button>
|
| 210 |
+
<button class="secondary" id="pasteBtn" title="Paste"><i class="fa-solid fa-clipboard"></i></button>
|
| 211 |
+
<button class="secondary" id="deleteBtn" title="Delete file"><i class="fa-solid fa-trash"></i></button>
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 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 |
</div>
|
| 229 |
|
| 230 |
+
<footer>
|
| 231 |
+
<div>Made with care for <span class="note">Ragini didi — happy learning!</span></div>
|
| 232 |
+
</footer>
|
| 233 |
+
|
| 234 |
+
<!-- Hidden file input for import -->
|
| 235 |
+
<input type="file" id="fileInput" accept=".java" style="display:none" />
|
| 236 |
+
|
| 237 |
<script>
|
| 238 |
+
// ---------- Editor setup ----------
|
| 239 |
+
const editor = CodeMirror(document.getElementById('editor'), {
|
| 240 |
mode: "text/x-java",
|
|
|
|
| 241 |
lineNumbers: true,
|
| 242 |
+
tabSize: 4,
|
| 243 |
indentUnit: 4,
|
| 244 |
+
autoCloseBrackets: true,
|
| 245 |
+
matchBrackets: true,
|
| 246 |
+
theme: "default",
|
| 247 |
+
value: "// Start here\nclass Main {\n public static void main(String[] args) {\n System.out.println(\"Hello from Java Learner\");\n }\n}\n"
|
| 248 |
});
|
| 249 |
|
| 250 |
+
// Keep editor responsive height
|
| 251 |
+
function resizeEditor(){
|
| 252 |
+
const wrap = document.querySelector('.CodeMirror');
|
| 253 |
+
if(wrap) {
|
| 254 |
+
// compute available height
|
| 255 |
+
let vh = window.innerHeight;
|
| 256 |
+
// set a comfortable height based on screen
|
| 257 |
+
const base = Math.max(240, vh - 360);
|
| 258 |
+
wrap.style.height = base + 'px';
|
| 259 |
+
editor.refresh();
|
| 260 |
+
}
|
|
|
|
|
|
|
| 261 |
}
|
| 262 |
+
window.addEventListener('resize', resizeEditor);
|
| 263 |
+
setTimeout(resizeEditor,300);
|
| 264 |
+
|
| 265 |
+
// ---------- Local file storage ----------
|
| 266 |
+
let files = JSON.parse(localStorage.getItem('java_learner_files') || '{}');
|
| 267 |
+
let active = localStorage.getItem('java_learner_active') || null;
|
| 268 |
+
const fileListEl = document.getElementById('fileList');
|
| 269 |
+
const activeFileEl = document.getElementById('activeFile');
|
| 270 |
+
const consoleEl = document.getElementById('console');
|
| 271 |
|
| 272 |
+
// Utilities
|
| 273 |
+
function saveToStorage(){
|
| 274 |
+
localStorage.setItem('java_learner_files', JSON.stringify(files));
|
| 275 |
+
}
|
| 276 |
+
function setActive(name){
|
| 277 |
+
active = name;
|
| 278 |
+
localStorage.setItem('java_learner_active', active);
|
| 279 |
+
activeFileEl.innerText = active || '—';
|
| 280 |
renderFiles();
|
| 281 |
+
if(active) editor.setValue(files[active]);
|
| 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 |
+
// Clipboard actions (cut/copy/paste)
|
| 403 |
+
document.getElementById('cutBtn').addEventListener('click', ()=>{
|
| 404 |
+
const sel = editor.getSelection();
|
| 405 |
+
if(!sel) return;
|
| 406 |
+
navigator.clipboard.writeText(sel).then(()=> {
|
| 407 |
+
editor.replaceSelection('');
|
| 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>
|