-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
604 lines (498 loc) · 22.7 KB
/
index.html
File metadata and controls
604 lines (498 loc) · 22.7 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta description="SIMpliCode is the fastest, easiest way to sample your code online, with a built-in AI editor and instant preview">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta property="og:title" content="SIMpliCode">
<meta property="og:description" content="Sample and preview your code instantly with SIMpliCode’s AI-powered editor.">
<meta property="og:image" content="https://sim3-14159.github.io/simplicode/assets/og-image.png">
<meta property="og:url" content="https://sim3-14159.github.io/simplicode">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
<title>SIMpliCode</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="style.css">
<!-- Marked.js for Markdown parsing -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- Highlight.js for code syntax highlighting -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- CodeMirror for live syntax highlighting -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/theme/monokai.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/javascript/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/xml/xml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/css/css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/htmlmixed/htmlmixed.min.js"></script>
<!-- DOMPurify for AI output -->
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.6/dist/purify.min.js"></script>
</head>
<body>
<nav class="options-menubar">
<ul>
<li>
<button>
<img
src="https://img.icons8.com/?size=128&id=uVgsZ6Ybur44&format=png"
class="settings-icon"
alt="Settings">
</button>
</li>
<li>
<button>
<span>File</span>
<img src="https://img.icons8.com/?size=96&id=ENKyxGggqj1D&format=png" alt="">
</button>
<ul>
<li>
<a href="#">Export Project</a>
</li>
<li><a href="#">Import Project</a></li>
<li>
<a href="#">New Project</a>
<ul>
<li><a href="#">Blank Project</a></li>
<li>
<a href="#">Example</a>
<ul>
<li><a href="#">From GitHub</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>
<button>
<span>Edit</span>
<img src="https://img.icons8.com/?size=128&id=MCdDfCTzd5GC&format=png" alt="">
</button>
<ul>
<li><a href="#">Undo</a></li>
<li><a href="#">Redo</a></li>
<li><a href="#">Cut</a></li>
<li><a href="#">Copy</a></li>
<li><a href="#">Paste</a></li>
</ul>
</li>
<li>
<button>
<span>Editor</span>
<img src="https://img.icons8.com/?size=128&id=jQqkFm4H3JUl&format=png" alt="">
</button>
<ul>
<li><a href="#">Undo</a></li>
<li><a href="#">Redo</a></li>
<li><a href="#">Cut</a></li>
<li><a href="#">Copy</a></li>
<li><a href="#">Paste</a></li>
<li><a href="#">Auto-Align</a></li>
<li>
<a href="#">Download</a>
<ul>
<li><a href="#">Entire Project</a></li>
<li><a href="#">This File (<code>index.html</code>)</a></li>
</ul>
</li>
</ul>
</li>
<li>
<button>
<span>Chat</span>
<img src="https://img.icons8.com/?size=60&id=59753&format=png" alt="">
</button>
<ul>
<li><a href="#">Save Chat</a></li>
</ul>
</li>
<li>
<button>
<span>Preview</span>
<img src="https://img.icons8.com/?size=48&id=yqFu2G7MJ61B&format=png" alt="">
</button>
<ul>
<li><a href="#">View in Fullscreen</a></li>
<li><a href="#">Open in New Tab</a></li>
</ul>
</li>
</ul>
</nav>
<div class="main-container">
<!-- Toggle button (fixed at top-right) -->
<!-- Toggle button (fixed at top-right) -->
<button id="sidebarToggle"><strong><§></strong></button>
<!-- Pop-out sidebar -->
<aside id="sidebar">
<div class="sidebar-header">
<span>Options</span>
</div>
<div class="sidebar-content">
<span style="float: right;">General</span>
<button id="settings-button" title="Open SIMpliCode settings"><img src="https://img.icons8.com/?size=100&id=2969&format=png" class="sidebar-img"><span>Settings</span></button>
<button id="help-button" title="How to use SIMpliCode"><img src="https://img.icons8.com/ios-filled/help" class="sidebar-img"><span>Help</span></button><br><br>
<span style="float: right;">Chat</span>
<a href=''><button id="clear-chat" title="Reload the page and clear the chat"><img src="https://img.icons8.com/?size=100&id=35635&format=png" class="sidebar-img"><span>Reload Page</span></button></a>
<button id="download" onclick="downloadChat()" title="Download the chat as an .rtf file"><img src="https://img.icons8.com/?size=100&id=18764&format=png" class="sidebar-img"> <span>Save Chat</span></button>
<button id="import-chat" title="Import a chat from file"><img src="https://img.icons8.com/?size=100&id=8301&format=png" class="sidebar-img"> <span>Import Chat</span></button><br><br>
<span style="float: right;">Code</span>
<button id="save" onclick="openPopup()" title="Download the HTML"><img src="https://img.icons8.com/?size=100&id=2945&format=png" class="sidebar-img"> <span>Download Code</span></button>
<button id="import-code" title="Import the code from a file"><img src="https://img.icons8.com/?size=100&id=RljciFZGONCD&format=png" class="sidebar-img"> <span>Import Code</span></button>
</div>
</aside>
<div class="title">SIMpliCode</div>
<div class="bottom-section">
<div class="chat-container" id="chatContainer">
<div id="conversation-container">
<div id="conversation"></div>
</div>
<textarea id="input" placeholder="Ask SIMpliCode..."></textarea>
<span>
<button class="chat-button-left" id="attach" title="Attach a File"><img src="https://img.icons8.com/50/attach" class="chat-img"></button></button>
<button class="chat-button-right" id="send" title="Send Message"><img src="https://img.icons8.com/50/up" class="chat-img"></button>
</span>
</div>
<div class="divider-horizontal" id="horizontalDivider"></div>
<div class="editor-container" id="editorContainer">
<nav class="actions"><button title="Find"><img src="https://img.icons8.com/ios-filled/search"></button><button title="Replace"><img src="https://img.icons8.com/ios-filled/swap"></button><button title="Comment"><img src="https://img.icons8.com/?size=100&id=37966&format=png"></button><button title="Undo" onclick="codeMirror.undo()"><img src="https://img.icons8.com/ios-filled/undo"></button><button title="Redo" onclick="codeMirror.redo()"><img src="https://img.icons8.com/ios-filled/redo"></button><button title="Automatically indent everything perfectly" onclick='codeMirror.execCommand("selectAll"); codeMirror.execCommand("indentAuto"); codeMirror.setSelection(codeMirror.getCursor());'><img src="https://img.icons8.com/?size=100&id=8068&format=png"></button>
<span id="cursor-pos" class="code-count"></span><span class="code-count">|</span><span id="chr-count" class="code-count"></span><span class="code-count">•</span><span id="line-num" class="code-count">289 lines</span></nav>
<navbar><button>index.html</button><button>style.css</button><button style="float: right;">+</button></navbar>
<textarea id="codespace"></textarea>
</div>
</div>
<div class="divider-vertical" id="verticalDivider"></div>
<nav class="tab">
<span>
<img id="favicon-img"><span id="preview-title">No Title</span>
</span>
<button title="Reload Preview" onclick="reloadPreview()">
<!--<img src="https://img.icons8.com/?size=100&id=90922&format=png&color=222222">-->
<img src="https://img.icons8.com/?size=100&id=12494&format=png&color=222222">
</button>
<button onclick="document.getElementById('fill').requestFullscreen()">
<img src="https://img.icons8.com/?size=80&id=aZytKIbf5DGB&format=png">
</button>
</nav>
<iframe srcdoc="" id="fill" class="preview-container"></iframe>
<footer class="copyright" title="Copyright © 2025 Sim3-14159. Icons by Icons8.">
Copyright © 2025 Sim3-14159. Icons by Icons8.
</footer>
</div>
<div id="popup" class="popup-overlay">
<div class="popup-content">
<h2>Download As</h2>
<input type="text" id="popup-input" placeholder="Enter a filename..." value="SIMpliCode.html" onclick="this.select();"><br><br>
<button onclick="closePopup()" class="fineButton">Cancel</button>
<button onclick="downloadCode()" class="goodButton">Download</button>
<p id="notificationMessage"></p>
</div>
</div>
<script>
const systemPromptDefault = `You are the **SIMpliCode AI**. You are a helpful HTML, CSS, and JavaScript coding assistant. You always give concise, well thought out answers. Any time you give code, you put it into a code block with a backtick (\`) or triple backtick (\`\`\`), and respond to the user. Never show the raw HTML, CSS, or JavaScript outside of a code block. If the user asks a question like "Can you do this?", then do not just give a generic answer like "Yes", but actually do the thing that they ask. Format your responses richly.`;
// Function to show thinking animation
function showThinkingMessage() {
const conversation = document.getElementById('conversation');
const thinkingDiv = document.createElement('div');
thinkingDiv.className = 'thinking-message';
thinkingDiv.innerHTML = `
<span>AI is thinking</span>
<div class="thinking-dots">
<span></span>
<span></span>
<span></span>
</div>
`;
thinkingDiv.id = 'thinking-indicator';
conversation.appendChild(thinkingDiv);
conversation.parentElement.scrollTop = conversation.parentElement.scrollHeight;
return thinkingDiv;
}
// Function to remove thinking animation
function removeThinkingMessage() {
const thinkingIndicator = document.getElementById('thinking-indicator');
if (thinkingIndicator) {
thinkingIndicator.remove();
}
}
async function sendToAI(userMessage, currentCode) {
const responseDiv = document.getElementById('conversation');
const combinedPrompt = `System: ${systemPromptDefault}\nCurrent code:\n${currentCode}\nUser: ${userMessage}`;
try {
const res = await fetch("https://apifreellm.com/api/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: combinedPrompt })
});
if (!res.ok) throw new Error(`HTTP error ${res.status}`);
const data = await res.json();
removeThinkingMessage();
const p = document.createElement('p');
p.className = 'bot-message';
if (data.response && data.response.includes('429')) {
p.innerHTML = "Uh oh, it looks like you've reached your current limit. Please try again later.";
} else {
const html = marked.parse(data.response); // todo: sanitize with DOMPurify
p.innerHTML = html;
}
// Highlight code blocks
p.querySelectorAll('pre code').forEach((block) => {
hljs.highlightElement(block);
});
responseDiv.appendChild(p);
responseDiv.parentElement.scrollTop = responseDiv.parentElement.scrollHeight;
} catch (err) {
removeThinkingMessage();
const p = document.createElement('p');
p.className = 'bot-message';
p.innerHTML = `<div style="color: red;">Error: ${err.message || 'Something went wrong'}</div>`;
responseDiv.appendChild(p);
responseDiv.parentElement.scrollTop = responseDiv.parentElement.scrollHeight;
}
}
// --- REPLACE WizardOrpheus sendMessage calls ---
document.getElementById('input').addEventListener('keyup', function (e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
let userInput = this.value.trim();
if (!userInput) return;
const currentCode = codeMirror.getValue();
showThinkingMessage();
sendToAI(userInput, currentCode);
const conversation = document.getElementById('conversation');
const pUser = document.createElement('p');
pUser.className = 'user-message';
pUser.textContent = userInput;
conversation.appendChild(pUser);
conversation.parentElement.scrollTop = conversation.parentElement.scrollHeight;
this.value = '';
}
});
document.getElementById('send').addEventListener('click', () => {
const input = document.getElementById('input');
const userInput = input.value.trim();
if (!userInput) return;
showThinkingMessage();
sendToAI(userInput, codeMirror.getValue());
const conversation = document.getElementById('conversation');
const pUser = document.createElement('p');
pUser.className = 'user-message';
pUser.textContent = userInput;
conversation.appendChild(pUser);
conversation.parentElement.scrollTop = conversation.parentElement.scrollHeight;
input.value = '';
});
// --- ORIGINAL SCRIPT BELOW (unchanged) ---
// Resizable functionality - improved and fixed
let isResizingHorizontal = false;
let isResizingVertical = false;
const horizontalDivider = document.getElementById('horizontalDivider');
const verticalDivider = document.getElementById('verticalDivider');
const chatContainer = document.getElementById('chatContainer');
const editorContainer = document.getElementById('editorContainer');
const bottomSection = document.querySelector('.bottom-section');
const previewContainer = document.getElementById('fill');
horizontalDivider.addEventListener('mousedown', (e) => {
isResizingHorizontal = true;
document.body.style.cursor = 'col-resize';
e.preventDefault();
});
verticalDivider.addEventListener('mousedown', (e) => {
isResizingVertical = true;
document.body.style.cursor = 'row-resize';
e.preventDefault();
});
document.addEventListener('mousemove', (e) => {
if (!isResizingHorizontal && !isResizingVertical) return;
if (isResizingHorizontal) {
const containerRect = bottomSection.getBoundingClientRect();
const containerLeft = containerRect.left;
const containerWidth = containerRect.width;
const mouseX = e.clientX;
const relativeX = mouseX - containerLeft;
let chatPercentage = (relativeX / containerWidth) * 100;
chatPercentage = Math.max(25, Math.min(75, chatPercentage));
chatContainer.style.flex = `0 0 ${chatPercentage}%`;
editorContainer.style.flex = `0 0 ${96.8 - chatPercentage}%`;
}
if (isResizingVertical) {
const containerRect = document.querySelector('.main-container').getBoundingClientRect();
const titleHeight = document.querySelector('.title').offsetHeight + 40;
const totalHeight = window.innerHeight - titleHeight - 20;
const mouseY = e.clientY - titleHeight - 20;
let bottomPercentage = (mouseY / totalHeight) * 100;
bottomPercentage = Math.max(25, Math.min(75, bottomPercentage));
bottomSection.style.height = `${bottomPercentage}vh`;
previewContainer.style.height = `${100 - bottomPercentage}vh`;
}
});
document.addEventListener('mouseup', () => {
isResizingHorizontal = false;
isResizingVertical = false;
document.body.style.cursor = 'default';
});
document.addEventListener('mouseleave', () => {
isResizingHorizontal = false;
isResizingVertical = false;
document.body.style.cursor = 'default';
});
// Initialize CodeMirror
const codeMirror = CodeMirror.fromTextArea(document.getElementById('codespace'), {
lineNumbers: true,
mode: 'htmlmixed',
theme: 'monokai',
lineWrapping: true,
autoCloseTags: true,
autoCloseBrackets: true,
matchBrackets: true,
indentUnit: 2,
tabSize: 2,
indentWithTabs: false,
viewportMargin: Infinity,
smartIndent: true
});
codeMirror.on("cursorActivity", function(instance) {
const cursor = instance.doc.getCursor();
document.getElementById("cursor-pos").textContent = (cursor.line + 1) + ":" + cursor.ch;
});
codeMirror.on('change', function(cm) {
const lineCount = cm.lineCount();
const newHeight = Math.max(300, lineCount * 24 + 50);
cm.setSize(null, (newHeight - 110) + 'px');
const code = cm.getValue();
const iframe = document.getElementById("fill");
iframe.srcdoc = code;
document.getElementById("chr-count").textContent = code.length + " chr";
document.getElementById("chr-count").title = code.length + " characters";
document.getElementById("line-num").textContent = lineCount + " ln";
document.getElementById("line-num").title = lineCount + " lines";
iframe.onload = () => {
const iframeTitle = iframe.contentDocument.title || 'No Title';
document.getElementById("preview-title").textContent = iframeTitle;
const doc = iframe.contentDocument;
const iconLink = doc.querySelector('link[rel~="icon"]');
let faviconUrl;
if (iconLink) {
faviconUrl = new URL(iconLink.getAttribute('href'), doc.baseURI).href;
} else {
faviconUrl = new URL('./favicon.ico', doc.baseURI).href;
}
document.getElementById("favicon-img").src = faviconUrl;
};
saveData();
});
loadData();
const toggleBtn = document.getElementById('sidebarToggle');
const sidebar = document.getElementById('sidebar');
let rotation = 0;
toggleBtn.addEventListener('click', () => {
sidebar.classList.toggle('open');
rotation += 360;
toggleBtn.style.transform = `rotate(${rotation}deg)`;
});
function openPopup() {
document.getElementById("popup").style.display = "flex";
document.getElementById("popup-input").value = localStorage.getItem("last-download-file-name") || "SIMpliCode.html";
}
function closePopup() {
document.getElementById("popup").style.display = "none";
document.getElementById("popup-input").value = "";
document.getElementById("notificationMessage").textContent = "";
}
function downloadCode() {
const text = codeMirror.getValue().trim();
if (!text) {
alert("Empty code!");
return;
}
const blob = new Blob([text], { type: 'text/html' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const inputArea = document.getElementById("popup-input");
a.href = url;
a.download = inputArea.value;
a.click();
URL.revokeObjectURL(url);
localStorage.setItem("last-download-file-name", inputArea.value);
closePopup();
}
function downloadChat() {
const conversation = document.getElementById('conversation');
const messages = conversation.querySelectorAll('p');
let rtfContent = `{\\rtf1\\ansi\\deff0\n`;
messages.forEach((msg) => {
if (msg.classList.contains('user-message')) {
rtfContent += `\\b You said:\\b0\\line\n${escapeRtf(msg.textContent.trim())}\\line\\line\n`;
} else if (msg.classList.contains('bot-message')) {
rtfContent += `\\b SIMpliCode said:\\b0\\line\n${escapeRtf(msg.textContent.trim())}\\line\\line\n`;
} else if (msg.classList.contains('win-message')) {
rtfContent += `\\b System Message:\\b0\\line\n${escapeRtf(msg.textContent.trim())}\\line\\line\n`;
}
});
rtfContent += `}`;
if (rtfContent === '{\\rtf1\\ansi\\deff0\n}') {
alert("There is nothing in the chat!");
return;
}
const blob = new Blob([rtfContent], { type: 'application/rtf' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'SIMpleChat.rtf';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
function escapeRtf(text) {
let rtf = '';
for (let i = 0; i < text.length; i++) {
const char = text[i];
const code = char.charCodeAt(0);
if (char === '\\') {
rtf += '\\\\';
} else if (char === '{') {
rtf += '\\{';
} else if (char === '}') {
rtf += '\\}';
} else if (code > 127) {
rtf += `\\u${code}?`;
} else if (char === '\n') {
rtf += '\\line\n';
} else {
rtf += char;
}
}
return rtf;
}
function saveData() {
const input = codeMirror.getValue();
localStorage.setItem('myData', input);
}
function loadData() {
const storedData = localStorage.getItem('myData');
codeMirror.setValue(storedData ? storedData : `<!--Welcome to the codespace! Write your code here and the AI will be able to help you with it! This is some example HTML to get you started.-->
<!DOCTYPE html>
<html lang='en'>
<meta charset="UTF-8">
<head>
<title>Basic Example</title>
<style>
/* Put your styles here. */
</style>
</head>
<body>
<h1>Basic Example</h1>
<p>This is a paragraph of words in the basic example</p>
<script>
/*Any JavaScript you create will go here*/
</s\cript>
</body>
</html>`);
}
function reloadPreview() {
previewContainer.srcdoc = codeMirror.getValue();
}
</script>
</body>
</html>