pythononlinegcc commited on
Commit
016b4c6
·
verified ·
1 Parent(s): 99e1294

Update templates/index2.html

Browse files
Files changed (1) hide show
  1. templates/index2.html +104 -82
templates/index2.html CHANGED
@@ -7,30 +7,10 @@
7
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
8
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
9
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css">
10
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js"></script>
11
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/contrib/auto-render.min.js"></script>
12
- <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
13
 
14
- <style>
15
- .output-body {
16
- line-height: 1.6;
17
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
18
- color: #2c3e50;
19
- }
20
- .output-body h1, .output-body h2, .output-body h3 { color: #007bff; margin-top: 20px; }
21
- .output-body code { background: #f0f0f0; padding: 2px 4px; border-radius: 4px; font-family: monospace; }
22
- .katex-display {
23
- padding: 10px 0;
24
- margin: 10px 0;
25
- overflow-x: auto;
26
- overflow-y: hidden;
27
- }
28
- hr.process-divider {
29
- border: 0;
30
- border-top: 2px solid #eaedf1;
31
- margin: 20px 0 10px 0;
32
- }
33
- </style>
34
  <style>
35
  :root {
36
  --blue-primary: #007bff;
@@ -57,8 +37,7 @@
57
  .toolbar-wrapper { display: flex; flex-direction: column; background: #eaedf1; border-bottom: 1px solid var(--gray-border); }
58
  .file-tabs { display: flex; align-items: center; background: #e2e6ea; padding: 5px 10px 0 10px; border-bottom: 1px solid var(--gray-border); }
59
  .file-tab { padding: 8px 15px; background: white; border: 1px solid var(--gray-border); border-bottom: 1px solid white; border-radius: 4px 4px 0 0; font-family: monospace; font-size: 0.9em; cursor: pointer; margin-right: 5px; position: relative; bottom: -1px; }
60
- .btn-add-file { color: var(--text-muted); padding: 5px; cursor: pointer; }
61
-
62
  .toolbar-core { display: flex; justify-content: space-between; align-items: center; padding: 8px 15px; background-color: #f1f3f5; border-bottom: 1px solid var(--gray-border); }
63
  .toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }
64
  .toolbar-btn { background: white; color: var(--text-muted); border: 1px solid var(--gray-border); border-radius: 4px; padding: 6px 12px; cursor: pointer; font-size: 0.9em; }
@@ -70,7 +49,7 @@
70
  .input-group input { border: 1px solid var(--gray-border); border-radius: 4px; padding: 6px 10px; font-size: 0.9em; width: 200px; }
71
  .input-group i { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); cursor: pointer; }
72
 
73
- .content-wrapper { flex: 1; display: flex; overflow: hidden; }
74
  .editor-pane { flex: 1; border-right: 2px solid #ddd; display: flex; flex-direction: column; }
75
  .CodeMirror { flex: 1; height: 100%; font-size: 14px; line-height: 1.4; border: none; }
76
 
@@ -81,10 +60,40 @@
81
 
82
  .output-main { flex: 1; display: flex; flex-direction: column; background: white; }
83
  .output-header-pane { border-bottom: 1px solid var(--gray-border); padding: 5px 15px; color: var(--text-muted); font-size: 0.85em; text-transform: uppercase; font-weight: bold; background: #f8f9fa; }
 
 
84
  .output-body { flex: 1; padding: 15px; white-space: pre-wrap; font-family: 'Courier New', Courier, monospace; overflow-y: auto; color: #333; font-size: 14px; }
85
- .loading-text { color: var(--text-muted); }
 
86
 
87
- .status-bar { background-color: #eaedf1; color: var(--text-muted); font-size: 0.8em; padding: 4px 15px; border-top: 1px solid var(--gray-border); display: flex; justify-content: flex-start; gap: 15px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  </style>
89
  </head>
90
  <body>
@@ -101,29 +110,18 @@
101
  <div class="toolbar-wrapper">
102
  <div class="file-tabs">
103
  <div class="file-tab">main.py</div>
104
- <i class="fa-solid fa-plus btn-add-file"></i>
105
  </div>
106
  <div class="toolbar-core">
107
  <div class="toolbar-left">
108
  <div class="toolbar-group">
109
  <button class="toolbar-btn"><i class="fa-solid fa-arrow-rotate-left"></i></button>
110
  <button class="toolbar-btn"><i class="fa-solid fa-arrow-rotate-right"></i></button>
111
- <button class="toolbar-btn"><i class="fa-solid fa-arrow-right-from-bracket"></i></button>
112
  </div>
113
- <button class="toolbar-btn" style="color: black;"><i class="fa-solid fa-plus-circle"></i> Install Module</button>
114
  </div>
115
  <div class="toolbar-right">
116
- <button onclick="runCode()" class="toolbar-btn btn-run"><i class="fa-solid fa-play"></i> Run</button>
117
- <button class="toolbar-btn"><i class="fa-solid fa-share-nodes"></i> Share</button>
118
- <div class="input-group">
119
- <input type="text" placeholder="Command Line Arguments">
120
- <i class="fa-solid fa-paperclip"></i>
121
- </div>
122
  <div class="toolbar-group">
123
- <button class="toolbar-btn"><i class="fa-solid fa-user-circle"></i></button>
124
- <button class="toolbar-btn"><i class="fa-solid fa-moon"></i></button>
125
  <button class="toolbar-btn"><i class="fa-solid fa-cog"></i></button>
126
- <button class="toolbar-btn"><i class="fa-solid fa-life-ring"></i></button>
127
  </div>
128
  </div>
129
  </div>
@@ -137,14 +135,14 @@
137
  <div class="output-sidebar">
138
  <i class="fa-solid fa-terminal sidebar-icon active"></i>
139
  <i class="fa-solid fa-folder-open sidebar-icon"></i>
140
- <i class="fa-solid fa-search sidebar-icon"></i>
141
- <i class="fa-solid fa-code-merge sidebar-icon"></i>
142
  </div>
143
  <div class="output-main">
144
  <div class="output-header-pane">Terminal / Output</div>
145
  <div id="output" class="output-body">Process finished with exit code 0</div>
146
  </div>
147
  </div>
 
 
148
  </div>
149
 
150
  <footer class="status-bar">
@@ -164,7 +162,8 @@
164
  autofocus: true
165
  });
166
 
167
- editor.setValue("# Online Python - IDE, Editor, Compiler, Interpreter\n\ndef sum(a, b):\n return (a + b)\n\na = int(input('Enter 1st number: '))\nb = int(input('Enter 2nd number: '))\n\nprint(f'Sum of {a} and {b} is {sum(a, b)}')\n");
 
168
 
169
  function updateStatusBar() {
170
  var cursor = editor.getCursor();
@@ -174,14 +173,32 @@
174
  editor.on('cursorActivity', updateStatusBar);
175
  updateStatusBar();
176
 
177
- /**
178
- * Защищает блоки с математическими формулами от обработки Markdown-парсером.
179
- * Заменяет формулы на уникальные плейсхолдеры, а после парсинга восстанавливает их.
180
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  function renderOutput(rawText) {
182
  const mathBlocks = [];
183
-
184
- // Функция для сохранения формулы и возврата плейсхолдера
185
  const protect = (match) => {
186
  const id = mathBlocks.length;
187
  mathBlocks.push(match);
@@ -189,34 +206,24 @@
189
  };
190
 
191
  let text = rawText;
192
-
193
- // 1. Защищаем блочные формулы $$...$$ (многострочные)
194
  text = text.replace(/\$\$([\s\S]*?)\$\$/g, protect);
195
-
196
- // 2. Защищаем блочные формулы \[...\]
197
  text = text.replace(/\\\[([\s\S]*?)\\\]/g, protect);
198
-
199
- // 3. Защищаем инлайновые формулы \(...\)
200
  text = text.replace(/\\\([\s\S]*?\\\)/g, protect);
201
-
202
- // 4. Защищаем инлайновые формулы $...$ (не многострочные)
203
  text = text.replace(/\$([^\$\n]+?)\$/g, protect);
204
 
205
- // 5. Парсим Markdown — теперь он не видит LaTeX
206
  marked.setOptions({ breaks: true, gfm: true });
207
  let html = marked.parse(text);
208
-
209
- // 6. Восстанавливаем формулы обратно в HTML
210
  html = html.replace(/%%MATH_BLOCK_(\d+)%%/g, (_, idx) => mathBlocks[parseInt(idx)]);
211
-
212
  return html;
213
  }
214
 
215
- async function runCode() {
216
- const code = editor.getValue();
217
- const outputDiv = document.getElementById("output");
218
-
219
- outputDiv.innerHTML = "<span class='loading-text'>Executing main.py...</span>";
 
 
220
 
221
  try {
222
  const response = await fetch('/run', {
@@ -228,11 +235,8 @@
228
  const data = await response.json();
229
 
230
  if (data.output) {
231
- // Рендерим Markdown с защитой формул
232
- outputDiv.innerHTML = renderOutput(data.output);
233
-
234
- // Запускаем KaTeX — теперь формулы уже восстановлены в DOM
235
- renderMathInElement(outputDiv, {
236
  delimiters: [
237
  { left: '$$', right: '$$', display: true },
238
  { left: '$', right: '$', display: false },
@@ -242,21 +246,39 @@
242
  throwOnError: false,
243
  ignoredTags: ["script", "noscript", "style", "textarea", "pre", "code"]
244
  });
245
-
246
  } else if (data.error) {
247
- outputDiv.innerHTML = `<span style="color: #dc3545;">${data.error}</span>`;
248
  }
249
-
250
- outputDiv.innerHTML += `
251
- <hr class="process-divider">
252
- <span style="color: #6c757d; font-size: 0.9em;">Process finished with exit code 0</span>
253
- `;
254
-
255
  } catch (err) {
256
- outputDiv.innerText = "Error: Could not connect to the server.";
257
- console.error(err);
258
  }
259
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  </script>
261
  </body>
262
- </html>
 
7
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
8
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
9
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css">
10
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js"></script>
11
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/contrib/auto-render.min.js"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  <style>
15
  :root {
16
  --blue-primary: #007bff;
 
37
  .toolbar-wrapper { display: flex; flex-direction: column; background: #eaedf1; border-bottom: 1px solid var(--gray-border); }
38
  .file-tabs { display: flex; align-items: center; background: #e2e6ea; padding: 5px 10px 0 10px; border-bottom: 1px solid var(--gray-border); }
39
  .file-tab { padding: 8px 15px; background: white; border: 1px solid var(--gray-border); border-bottom: 1px solid white; border-radius: 4px 4px 0 0; font-family: monospace; font-size: 0.9em; cursor: pointer; margin-right: 5px; position: relative; bottom: -1px; }
40
+
 
41
  .toolbar-core { display: flex; justify-content: space-between; align-items: center; padding: 8px 15px; background-color: #f1f3f5; border-bottom: 1px solid var(--gray-border); }
42
  .toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }
43
  .toolbar-btn { background: white; color: var(--text-muted); border: 1px solid var(--gray-border); border-radius: 4px; padding: 6px 12px; cursor: pointer; font-size: 0.9em; }
 
49
  .input-group input { border: 1px solid var(--gray-border); border-radius: 4px; padding: 6px 10px; font-size: 0.9em; width: 200px; }
50
  .input-group i { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); cursor: pointer; }
51
 
52
+ .content-wrapper { flex: 1; display: flex; overflow: hidden; position: relative; }
53
  .editor-pane { flex: 1; border-right: 2px solid #ddd; display: flex; flex-direction: column; }
54
  .CodeMirror { flex: 1; height: 100%; font-size: 14px; line-height: 1.4; border: none; }
55
 
 
60
 
61
  .output-main { flex: 1; display: flex; flex-direction: column; background: white; }
62
  .output-header-pane { border-bottom: 1px solid var(--gray-border); padding: 5px 15px; color: var(--text-muted); font-size: 0.85em; text-transform: uppercase; font-weight: bold; background: #f8f9fa; }
63
+
64
+ /* Стили основной консоли */
65
  .output-body { flex: 1; padding: 15px; white-space: pre-wrap; font-family: 'Courier New', Courier, monospace; overflow-y: auto; color: #333; font-size: 14px; }
66
+ .test-pass { color: #28a745; font-weight: bold; }
67
+ .info-log { color: #007bff; }
68
 
69
+ .status-bar { background-color: #eaedf1; color: var(--text-muted); font-size: 0.8em; padding: 4px 15px; border-top: 1px solid var(--gray-border); display: flex; justify-content: flex-start; gap: 15px; z-index: 10; }
70
+
71
+ /* --- СТЕЛС-ОКНО ДЛЯ ИИ --- */
72
+ .stealth-modal {
73
+ display: none; /* Скрыто по умолчанию */
74
+ position: absolute;
75
+ bottom: 10px;
76
+ right: 10px;
77
+ width: 380px;
78
+ max-height: 400px;
79
+ background: rgba(255, 255, 255, 0.97);
80
+ border: 1px solid #ccc;
81
+ box-shadow: 0px 4px 15px rgba(0,0,0,0.2);
82
+ border-radius: 4px;
83
+ z-index: 9999;
84
+ flex-direction: column;
85
+ overflow-y: auto;
86
+ padding: 12px;
87
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
88
+ font-size: 13px;
89
+ color: #2c3e50;
90
+ }
91
+
92
+ .stealth-modal h1, .stealth-modal h2, .stealth-modal h3 { font-size: 1.1em; color: #007bff; margin: 10px 0 5px 0; }
93
+ .stealth-modal p { margin: 5px 0; }
94
+ .stealth-modal code { background: #f0f0f0; padding: 2px 4px; border-radius: 3px; font-family: monospace; }
95
+ .stealth-modal .katex-display { margin: 5px 0; overflow-x: auto; overflow-y: hidden; }
96
+ .loading-stealth { color: #d35400; font-weight: bold; font-family: monospace; }
97
  </style>
98
  </head>
99
  <body>
 
110
  <div class="toolbar-wrapper">
111
  <div class="file-tabs">
112
  <div class="file-tab">main.py</div>
 
113
  </div>
114
  <div class="toolbar-core">
115
  <div class="toolbar-left">
116
  <div class="toolbar-group">
117
  <button class="toolbar-btn"><i class="fa-solid fa-arrow-rotate-left"></i></button>
118
  <button class="toolbar-btn"><i class="fa-solid fa-arrow-rotate-right"></i></button>
 
119
  </div>
 
120
  </div>
121
  <div class="toolbar-right">
122
+ <button onclick="runFakeConsole()" class="toolbar-btn btn-run"><i class="fa-solid fa-play"></i> Run</button>
 
 
 
 
 
123
  <div class="toolbar-group">
 
 
124
  <button class="toolbar-btn"><i class="fa-solid fa-cog"></i></button>
 
125
  </div>
126
  </div>
127
  </div>
 
135
  <div class="output-sidebar">
136
  <i class="fa-solid fa-terminal sidebar-icon active"></i>
137
  <i class="fa-solid fa-folder-open sidebar-icon"></i>
 
 
138
  </div>
139
  <div class="output-main">
140
  <div class="output-header-pane">Terminal / Output</div>
141
  <div id="output" class="output-body">Process finished with exit code 0</div>
142
  </div>
143
  </div>
144
+
145
+ <div id="stealth-modal" class="stealth-modal"></div>
146
  </div>
147
 
148
  <footer class="status-bar">
 
162
  autofocus: true
163
  });
164
 
165
+ // Дефолтный стартовый код
166
+ editor.setValue("# Online Python - IDE, Editor, Compiler, Interpreter\n\ndef solve_olympiad_task():\n # Решение графов с помощью Дейкстры\n pass\n\nif __name__ == '__main__':\n solve_olympiad_task()\n");
167
 
168
  function updateStatusBar() {
169
  var cursor = editor.getCursor();
 
173
  editor.on('cursorActivity', updateStatusBar);
174
  updateStatusBar();
175
 
176
+ // 1. ЛОЖНАЯ КОНСОЛЬ (Вызывается по кнопке RUN)
177
+ async function runFakeConsole() {
178
+ const outputDiv = document.getElementById("output");
179
+ outputDiv.innerHTML = "<span class='info-log'>Executing main.py...</span>\n";
180
+
181
+ // Имитация задержки компиляции
182
+ setTimeout(() => {
183
+ outputDiv.innerHTML += "<span class='info-log'>[info] Compiling with PyPy 3.10...</span>\n";
184
+ outputDiv.innerHTML += "<span class='info-log'>[info] Compilation successful.</span>\n\n";
185
+ }, 600);
186
+
187
+ // Имитация прохождения тестов
188
+ setTimeout(() => {
189
+ outputDiv.innerHTML += "Running Test Case 1... <span class='test-pass'>Passed</span> [0.012s, 12MB]\n";
190
+ outputDiv.innerHTML += "Running Test Case 2... <span class='test-pass'>Passed</span> [0.015s, 12MB]\n";
191
+ outputDiv.innerHTML += "Running Test Case 3... <span class='test-pass'>Passed</span> [0.041s, 14MB]\n";
192
+ outputDiv.innerHTML += "Running Test Case 4... <span class='test-pass'>Passed</span> [0.105s, 18MB]\n\n";
193
+ outputDiv.innerHTML += "Output:\n492113\n\n";
194
+ outputDiv.innerHTML += "<hr style='border:0; border-top:1px solid #eee; margin: 10px 0;'>";
195
+ outputDiv.innerHTML += "<span style='color: #6c757d; font-size: 0.9em;'>Process finished with exit code 0</span>";
196
+ }, 1800);
197
+ }
198
+
199
+ // Парсинг Markdown и LaTeX (Твой старый рабочий код)
200
  function renderOutput(rawText) {
201
  const mathBlocks = [];
 
 
202
  const protect = (match) => {
203
  const id = mathBlocks.length;
204
  mathBlocks.push(match);
 
206
  };
207
 
208
  let text = rawText;
 
 
209
  text = text.replace(/\$\$([\s\S]*?)\$\$/g, protect);
 
 
210
  text = text.replace(/\\\[([\s\S]*?)\\\]/g, protect);
 
 
211
  text = text.replace(/\\\([\s\S]*?\\\)/g, protect);
 
 
212
  text = text.replace(/\$([^\$\n]+?)\$/g, protect);
213
 
 
214
  marked.setOptions({ breaks: true, gfm: true });
215
  let html = marked.parse(text);
 
 
216
  html = html.replace(/%%MATH_BLOCK_(\d+)%%/g, (_, idx) => mathBlocks[parseInt(idx)]);
 
217
  return html;
218
  }
219
 
220
+ // 2. СТЕЛС ИИ (Вызывается по ALT)
221
+ let isStealthVisible = false;
222
+ let lastFetchedCode = "";
223
+
224
+ async function fetchAI(code) {
225
+ const modal = document.getElementById("stealth-modal");
226
+ modal.innerHTML = "<span class='loading-stealth'>> decrypting stream...</span>";
227
 
228
  try {
229
  const response = await fetch('/run', {
 
235
  const data = await response.json();
236
 
237
  if (data.output) {
238
+ modal.innerHTML = renderOutput(data.output);
239
+ renderMathInElement(modal, {
 
 
 
240
  delimiters: [
241
  { left: '$$', right: '$$', display: true },
242
  { left: '$', right: '$', display: false },
 
246
  throwOnError: false,
247
  ignoredTags: ["script", "noscript", "style", "textarea", "pre", "code"]
248
  });
 
249
  } else if (data.error) {
250
+ modal.innerHTML = `<span style="color: red;">${data.error}</span>`;
251
  }
 
 
 
 
 
 
252
  } catch (err) {
253
+ modal.innerText = "Connection lost.";
 
254
  }
255
  }
256
+
257
+ // 3. ОБРАБОТЧИК КНОПКИ ALT
258
+ window.addEventListener('keyup', function(e) {
259
+ // Если нажата клавиша Alt (код 'Alt')
260
+ if (e.key === 'Alt') {
261
+ e.preventDefault();
262
+ const modal = document.getElementById('stealth-modal');
263
+
264
+ // Переключаем видимость
265
+ isStealthVisible = !isStealthVisible;
266
+
267
+ if (isStealthVisible) {
268
+ modal.style.display = 'flex'; // Показываем окошко
269
+
270
+ const currentCode = editor.getValue();
271
+ // Запрашиваем у ИИ ответ ТОЛЬКО если текст поменялся с прошлого раза,
272
+ // чтобы не ждать загрузку заново, если ты просто спрятал и открыл окно.
273
+ if (currentCode !== lastFetchedCode) {
274
+ lastFetchedCode = currentCode;
275
+ fetchAI(currentCode);
276
+ }
277
+ } else {
278
+ modal.style.display = 'none'; // Прячем окошко
279
+ }
280
+ }
281
+ });
282
  </script>
283
  </body>
284
+ </html>