parthmax commited on
Commit
6d38145
·
verified ·
1 Parent(s): e957698

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +136 -0
index.html ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Java IDE (HF)</title>
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
+ body { display: flex; margin: 0; font-family: Arial; background: #121212; color: #eee; height: 100vh; }
11
+ #files { width: 200px; background: #1e1e1e; padding: 10px; border-right: 2px solid #333; overflow-y: auto; }
12
+ #files button { display: block; width: 100%; margin: 5px 0; padding: 8px; background: #333; border: none; color: white; cursor: pointer; border-radius: 5px; text-align: left; }
13
+ #files button.active { background: #4CAF50; }
14
+ #editor-container { flex: 1; display: flex; flex-direction: column; }
15
+ #editor { flex: 1; border-bottom: 2px solid #333; }
16
+ #controls { padding: 10px; background: #1e1e1e; display: flex; gap: 10px; }
17
+ button { border: none; padding: 10px; border-radius: 5px; cursor: pointer; }
18
+ #run { background: #4CAF50; color: white; }
19
+ #save { background: #2196F3; color: white; }
20
+ #download { background: #FF9800; color: white; }
21
+ #delete { background: #f44336; color: white; }
22
+ #output { padding: 10px; background: #222; white-space: pre-wrap; height: 150px; overflow-y: auto; }
23
+ </style>
24
+ </head>
25
+ <body>
26
+ <div id="files">
27
+ <h3>Files</h3>
28
+ <button onclick="newFile()">+ New File</button>
29
+ <div id="file-list"></div>
30
+ </div>
31
+
32
+ <div id="editor-container">
33
+ <div id="editor"></div>
34
+ <div id="controls">
35
+ <button id="run" onclick="runCode()">▶ Run</button>
36
+ <button id="save" onclick="saveFile()">💾 Save</button>
37
+ <button id="download" onclick="downloadFile()">⬇ Download</button>
38
+ <button id="delete" onclick="deleteFile()">🗑 Delete</button>
39
+ </div>
40
+ <pre id="output"></pre>
41
+ </div>
42
+
43
+ <script>
44
+ let editor = CodeMirror(document.getElementById("editor"), {
45
+ mode: "text/x-java",
46
+ theme: "default",
47
+ lineNumbers: true,
48
+ indentUnit: 4,
49
+ tabSize: 4
50
+ });
51
+
52
+ let files = JSON.parse(localStorage.getItem("javaFiles") || "{}");
53
+ let currentFile = null;
54
+
55
+ function renderFiles() {
56
+ let list = document.getElementById("file-list");
57
+ list.innerHTML = "";
58
+ Object.keys(files).forEach(name => {
59
+ let btn = document.createElement("button");
60
+ btn.textContent = name;
61
+ if (name === currentFile) btn.classList.add("active");
62
+ btn.onclick = () => openFile(name);
63
+ list.appendChild(btn);
64
+ });
65
+ }
66
+
67
+ function newFile() {
68
+ let name = prompt("Enter file name (with .java):", "Main.java");
69
+ if (!name.endsWith(".java")) return alert("File must end with .java");
70
+ if (files[name]) return alert("File already exists");
71
+ files[name] = "// New Java file\nclass " + name.replace(".java", "") + " {\n public static void main(String[] args) {\n System.out.println(\"Hello " + name + "!\");\n }\n}";
72
+ currentFile = name;
73
+ saveStorage();
74
+ renderFiles();
75
+ openFile(name);
76
+ }
77
+
78
+ function openFile(name) {
79
+ currentFile = name;
80
+ editor.setValue(files[name]);
81
+ renderFiles();
82
+ }
83
+
84
+ function saveFile() {
85
+ if (!currentFile) return alert("No file open");
86
+ files[currentFile] = editor.getValue();
87
+ saveStorage();
88
+ alert("✅ File saved");
89
+ }
90
+
91
+ function deleteFile() {
92
+ if (!currentFile) return;
93
+ if (confirm("Delete " + currentFile + "?")) {
94
+ delete files[currentFile];
95
+ currentFile = null;
96
+ saveStorage();
97
+ renderFiles();
98
+ editor.setValue("");
99
+ }
100
+ }
101
+
102
+ function downloadFile() {
103
+ if (!currentFile) return;
104
+ let blob = new Blob([editor.getValue()], {type: "text/plain"});
105
+ let link = document.createElement("a");
106
+ link.href = URL.createObjectURL(blob);
107
+ link.download = currentFile;
108
+ link.click();
109
+ }
110
+
111
+ async function runCode() {
112
+ if (!currentFile) return alert("No file open");
113
+ saveFile();
114
+ document.getElementById("output").innerText = "⏳ Running...";
115
+ const res = await fetch("/run-java", {
116
+ method: "POST",
117
+ headers: {"Content-Type": "application/json"},
118
+ body: JSON.stringify({code: editor.getValue(), filename: currentFile})
119
+ });
120
+ const data = await res.json();
121
+ document.getElementById("output").innerText = data.output;
122
+ }
123
+
124
+ function saveStorage() {
125
+ localStorage.setItem("javaFiles", JSON.stringify(files));
126
+ }
127
+
128
+ // Load last state
129
+ renderFiles();
130
+ if (Object.keys(files).length > 0) {
131
+ currentFile = Object.keys(files)[0];
132
+ openFile(currentFile);
133
+ }
134
+ </script>
135
+ </body>
136
+ </html>