-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
260 lines (241 loc) · 9.36 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>foolhtml live editor | Live onepage browser based html editor, no installation required.</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/htmlmixed/htmlmixed.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/xml/xml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/javascript/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/css/css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/closetag.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/mode/multiplex.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/theme/material-darker.min.css">
<link rel="icon" href="favi.png" type="image/png">
<style>
body, html {
height: 100%;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.banner {
position: fixed;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: rgba(0, 0, 0, 0.7); /* Dark transparent */
backdrop-filter: blur(200px) brightness(80%);
-webkit-backdrop-filter: blur(200px) brightness(80%);
padding: 10px 25px;
z-index: 1000;
border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* Soft bottom border */
}
.filename {
color: #ffffff;
font-size: 14px;
margin: 0;
}
.button-group {
display: flex;
gap: 10px;
}
.button {
padding: 6px 12px;
border-radius: 6px;
border: none;
font-size: 13px;
cursor: pointer;
transition: background-color 0.2s;
}
.button-secondary {
background-color: #4d4d4d;
color: white;
}
.button-primary {
background-color: #0066cc;
color: white;
}
.button:hover {
opacity: 1; /* Full opacity on hover */
background-color: black; /* Change to black */
animation: darken 0.3s forwards; /* Apply the animation */
}
@keyframes darken {
0% {
background-color: #your-default-color; /* Start with the default color */
}
100% {
background-color: black; /* End with black */
}
}
.container {
display: flex;
height: 100%;
padding-top: 51px;
margin-top: -5px;
}
.editor-container {
width: 50%;
background: black;
position: relative;
}
.CodeMirror {
height: 100%;
background: black;
font-size: 14px;
line-height: 1.5;
caret-color: white;
}
.placeholder {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: rgba(255,255,255,0.2);
font-size: 24px;
pointer-events: none;
}
#output-area {
width: 50%;
height: auto;
margin-top: -5px;
overflow: auto;
padding: 0;
}
#outputIframe {
width: 100%;
height: 100%;
border: none;
}
#fileInput {
display: none;
}
</style>
</head>
<body>
<input type="file" id="fileInput" accept=".html,.htm">
<div class="banner">
<h1 class="filename" id="filename">Untitled.html</h1>
<div class="button-group">
<button class="button button-secondary" id="openBtn">Open</button>
<button class="button button-secondary" id="saveAsBtn">Save As...</button>
<button class="button button-primary" id="saveBtn">Save</button>
</div>
</div>
<div class="container">
<div class="editor-container">
<div id="editor" class="CodeMirror"></div>
<div id="placeholder" class="placeholder">/* CODE <br>SOMETHING<br> FOOL! */</div>
</div>
<div id="output-area">
<iframe id="outputIframe"></iframe>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const placeholder = document.getElementById('placeholder');
const outputArea = document.getElementById('output-area');
const filenameElement = document.getElementById('filename');
filenameElement.style.fontWeight = 'bold';
filenameElement.style.textDecoration = 'underline';
const fileInput = document.getElementById('fileInput');
let currentFileName = 'Untitled.html';
// Initialize CodeMirror
const editor = CodeMirror(document.getElementById('editor'), {
mode: "htmlmixed",
theme: "material-darker",
lineNumbers: true,
autoCloseTags: true,
styleActiveLine: true,
matchBrackets: true
});
function updateOutput() {
const htmlContent = editor.getValue();
const iframe = document.getElementById('outputIframe');
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
iframeDoc.open();
iframeDoc.write(htmlContent);
iframeDoc.close();
// Override window.print in the iframe to communicate with parent
iframeDoc.defaultView.window.print = function() {
window.parent.postMessage('print', '*');
};
placeholder.style.display = htmlContent.trim() ? 'none' : 'block';
}
editor.on('change', updateOutput);
// Open functionality
document.getElementById('openBtn').addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
editor.setValue(e.target.result);
currentFileName = file.name;
filenameElement.textContent = currentFileName;
updateOutput();
};
reader.readAsText(file);
}
fileInput.value = '';
});
// Save As functionality
function downloadFile(filename, content) {
const blob = new Blob([content], { type: 'text/html' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
// Save functionality
document.getElementById('saveBtn').addEventListener('click', () => {
downloadFile(currentFileName, editor.getValue());
});
// Save As functionality
document.getElementById('saveAsBtn').addEventListener('click', () => {
const newFilename = prompt('Enter filename:', currentFileName);
if (newFilename !== null) {
const filename = newFilename.endsWith('.html') ? newFilename : `${newFilename}.html`;
currentFileName = filename;
filenameElement.textContent = currentFileName;
downloadFile(currentFileName, editor.getValue());
}
});
// Listen for messages from the iframe for print commands
window.addEventListener('message', function(event) {
if (event.data === 'print') {
const iframeContent = document.getElementById('outputIframe').contentWindow.document.documentElement.outerHTML;
const printWindow = window.open('', '_blank', 'height=600,width=800');
printWindow.document.write('<html><head><title>Print Preview</title>');
printWindow.document.write('<style>@media print {body {width: 100%; padding: 0; margin: 0;}}</style>');
printWindow.document.write('</head><body>');
printWindow.document.write(iframeContent);
printWindow.document.write('</body></html>');
printWindow.document.close();
// Ensure the print dialog opens after the content is fully loaded
setTimeout(function() {
printWindow.focus(); // Needed for Firefox
printWindow.print();
// Optionally, close the print window if you don't want it to remain open
// printWindow.close();
}, 500);
}
});
});
</script>
</body>
</html>
</body>
</body>
</html>