吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1023|回复: 13
收起左侧

[其他原创] HTML代码-离线预览器,仅13.4 K

  [复制链接]
zhengzhenhui945 发表于 2025-5-6 20:17
本帖最后由 zhengzhenhui945 于 2025-5-7 03:50 编辑

1.输入 HTML 代码实时预览

2.支持下载   .HTML 格式文件
3.历史记录回溯
360截图20250506201601650.jpg

[HTML] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <title>HTML 实时预览器</title>
    <style>
        body {
            font-family: 'Inter', sans-serif;
            background-color: #f4f4f9;
        }
 
        .input-section,
        .preview-section {
            background-color: #fff;
            border-radius: 12px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            transition: width 0.3s ease-in-out;
        }
 
        textarea {
            font-family: 'Courier New', Courier, monospace;
            box-sizing: border-box;
            width: 100%;
            height: calc(100% - 3.5rem);
        }
 
        /* 媒体查询:小屏幕设备 */
        [url=home.php?mod=space&uid=945662]@media[/url] (max-width: 768px) {
            .container {
                flex-direction: column;
                gap: 2rem;
            }
 
            .input-section,
            .preview-section {
                width: 100%;
            }
 
            textarea {
                height: 300px;
            }
        }
 
        /* 全屏样式 */
        .preview-section.fullscreen {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 9999;
            background-color: white;
        }
 
        .preview-section.fullscreen iframe {
            height: calc(100% - 3rem);
        }
 
        .input-section.collapsed {
            width: 0;
            padding: 0;
            overflow: hidden;
        }
 
        .toggle-button {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background-color: #fff;
            border: none;
            cursor: pointer;
            z-index: 10;
            padding: 0.5rem;
            border-radius: 50%;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            transition: left 0.3s ease-in-out;
        }
 
        .input-section.collapsed .toggle-button {
            left: 0.5rem;
        }
 
        .input-section:not(.collapsed) .toggle-button {
            left: 1rem;
        }
 
        .expand-button {
            position: fixed;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
            background-color: #fff;
            border: none;
            cursor: pointer;
            z-index: 10;
            padding: 0.5rem;
            border-radius: 0 50% 50% 0;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            display: none;
        }
 
        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 10000;
            justify-content: center;
            align-items: center;
        }
 
        .modal-content {
            background-color: #fff;
            padding: 1rem;
            border-radius: 12px;
            width: 40%;
            max-height: 80%;
            overflow-y: auto;
        }
 
        .history-item {
            cursor: pointer;
            padding: 0.5rem;
            border-bottom: 1px solid #e5e7eb;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
 
        .history-item:hover {
            background-color: #f3f4f6;
        }
 
        .close-modal {
            position: absolute;
            top: 1rem;
            right: 1rem;
            cursor: pointer;
        }
 
        .clear-history {
            margin-left: auto;
            padding: 0.5rem 1rem;
            background-color: #e53e3e;
            color: white;
            border: none;
            border-radius: 0.25rem;
            cursor: pointer;
        }
 
        .clear-history:hover {
            background-color: #c53030;
        }
 
        .history-header {
            display: flex;
            align-items: center;
            margin-bottom: 1rem;
        }
 
        .threshold-setting {
            margin-left: 1rem;
            display: flex;
            align-items: center;
        }
 
        .threshold-setting input {
            padding: 0.25rem 0.5rem;
            border: 1px solid #e5e7eb;
            border-radius: 0.25rem;
            margin-right: 0.5rem;
            width: 4rem;
        }
 
        .threshold-setting button {
            padding: 0.25rem 0.5rem;
            background-color: #2563eb;
            color: white;
            border: none;
            border-radius: 0.25rem;
            cursor: pointer;
        }
 
        .threshold-setting button:hover {
            background-color: #1d4ed8;
        }
 
        .threshold-label {
            margin-right: 0.5rem;
        }
    </style>
</head>
 
<body class="bg-gray-100">
    <div class="container mx-auto p-8 flex h-screen gap-8 relative">
        <div class="input-section w-1/3 p-6 relative">
            <button class="toggle-button" id="toggleInputSection">
                <i class="fa-solid fa-chevron-left"></i>
            </button>
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-2xl font-bold text-gray-800">输入 HTML 代码</h2>
                <button id="downloadButton" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600">
                    下载 HTML
                </button>
                <button id="toggleHistoryButton" class="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-gray-600">
                    历史记录
                </button>
            </div>
            <textarea id="htmlInput" class="w-full p-4 border border-gray-300 rounded-md resize-none"
                placeholder="在此输入 HTML 代码"></textarea>
        </div>
        <div class="preview-section w-2/3 p-6">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-2xl font-bold text-gray-800">预览</h2>
                <button id="fullscreenButton" class="text-gray-600 hover:text-gray-900">
                    <i class="fa-solid fa-expand"></i>
                </button>
            </div>
            <iframe id="preview" class="w-full h-full border border-gray-300 rounded-md" style="width:100%;height:calc(100% - 3rem);"></iframe>
        </div>
        <button class="expand-button" id="expandInputSection">
            <i class="fa-solid fa-chevron-right"></i>
        </button>
    </div>
    <div class="modal" id="historyModal">
        <div class="modal-content">
            <span class="close-modal" id="closeModal">×</span>
            <div class="history-header">
                <h2 class="text-2xl font-bold text-gray-800">历史记录</h2>
                <button class="clear-history" id="clearHistory">清空记录</button>
                <div class="threshold-setting">
                    <span class="threshold-label">字数保存阈值</span>
                    <input type="number" id="thresholdInput" placeholder="阈值" value="3">
                    <button id="setThresholdButton">设置</button>
                </div>
            </div>
            <div class="history-list" id="historyList"></div>
        </div>
    </div>
    <script>
        const htmlInput = document.getElementById('htmlInput');
        const preview = document.getElementById('preview');
        const fullscreenButton = document.getElementById('fullscreenButton');
        const previewSection = document.querySelector('.preview-section');
        const inputSection = document.querySelector('.input-section');
        const downloadButton = document.getElementById('downloadButton');
        const toggleInputSection = document.getElementById('toggleInputSection');
        const expandInputSection = document.getElementById('expandInputSection');
        const toggleHistoryButton = document.getElementById('toggleHistoryButton');
        const historyModal = document.getElementById('historyModal');
        const closeModal = document.getElementById('closeModal');
        const historyList = document.getElementById('historyList');
        const clearHistory = document.getElementById('clearHistory');
        const thresholdInput = document.getElementById('thresholdInput');
        const setThresholdButton = document.getElementById('setThresholdButton');
 
        let history = JSON.parse(localStorage.getItem('htmlHistory')) || [];
        let CHANGE_THRESHOLD = 3;
 
        function saveToHistory() {
            const code = htmlInput.value;
            if (history.length === 0) {
                const timestamp = new Date().toLocaleString();
                history.push({ code, timestamp });
                localStorage.setItem('htmlHistory', JSON.stringify(history));
                renderHistory();
                return;
            }
            const lastCode = history[history.length - 1].code;
            const diffCount = Math.abs(code.length - lastCode.length);
            if (diffCount >= CHANGE_THRESHOLD) {
                const timestamp = new Date().toLocaleString();
                history.push({ code, timestamp });
                localStorage.setItem('htmlHistory', JSON.stringify(history));
                renderHistory();
            }
        }
 
        function renderHistory() {
            historyList.innerHTML = '';
            history.forEach((entry, index) => {
                const item = document.createElement('div');
                item.classList.add('history-item');
                const historyText = document.createElement('span');
                historyText.textContent = `历史记录 ${index + 1}`;
                const timestampText = document.createElement('span');
                timestampText.textContent = entry.timestamp;
                item.appendChild(historyText);
                item.appendChild(timestampText);
                item.addEventListener('click', () => {
                    htmlInput.value = entry.code;
                    const previewWindow = preview.contentWindow.document;
                    previewWindow.open();
                    previewWindow.write(entry.code);
                    previewWindow.close();
                    historyModal.style.display = 'none';
                });
                historyList.appendChild(item);
            });
        }
 
        htmlInput.addEventListener('input', () => {
            const htmlCode = htmlInput.value;
            const previewWindow = preview.contentWindow.document;
            previewWindow.open();
            previewWindow.write(htmlCode);
            previewWindow.close();
            saveToHistory();
        });
 
        function toggleFullscreen() {
            if (document.fullscreenElement) {
                document.exitFullscreen();
            } else {
                previewSection.requestFullscreen().catch((err) => {
                    console.error(`无法进入全屏模式: ${err.message}`);
                });
            }
        }
 
        fullscreenButton.addEventListener('click', toggleFullscreen);
 
        document.addEventListener('keydown', function (event) {
            if (event.key === 'Escape') {
                if (document.fullscreenElement) {
                    document.exitFullscreen();
                }
                if (inputSection.classList.contains('collapsed')) {
                    inputSection.classList.remove('collapsed');
                    const icon = toggleInputSection.querySelector('i');
                    icon.classList.remove('fa-chevron-right');
                    icon.classList.add('fa-chevron-left');
                    previewSection.style.width = 'calc(100% - 33.333333%)';
                    expandInputSection.style.display = 'none';
                }
            }
        });
 
        downloadButton.addEventListener('click', () => {
            const htmlCode = htmlInput.value;
            const blob = new Blob([htmlCode], { type: 'text/html' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'downloaded_html.html';
            a.click();
            URL.revokeObjectURL(url);
        });
 
        toggleInputSection.addEventListener('click', () => {
            inputSection.classList.toggle('collapsed');
            const icon = toggleInputSection.querySelector('i');
            icon.classList.toggle('fa-chevron-left');
            icon.classList.toggle('fa-chevron-right');
 
            if (inputSection.classList.contains('collapsed')) {
                previewSection.style.width = '100%';
                expandInputSection.style.display = 'block';
            } else {
                previewSection.style.width = 'calc(100% - 33.333333%)';
                expandInputSection.style.display = 'none';
            }
        });
 
        expandInputSection.addEventListener('click', () => {
            inputSection.classList.remove('collapsed');
            const icon = toggleInputSection.querySelector('i');
            icon.classList.remove('fa-chevron-right');
            icon.classList.add('fa-chevron-left');
            previewSection.style.width = 'calc(100% - 33.333333%)';
            expandInputSection.style.display = 'none';
        });
 
        toggleHistoryButton.addEventListener('click', () => {
            historyModal.style.display = 'flex';
        });
 
        closeModal.addEventListener('click', () => {
            historyModal.style.display = 'none';
        });
 
        window.addEventListener('click', (event) => {
            if (event.target === historyModal) {
                historyModal.style.display = 'none';
            }
        });
 
        clearHistory.addEventListener('click', () => {
            history = [];
            localStorage.removeItem('htmlHistory');
            historyList.innerHTML = '';
        });
 
        setThresholdButton.addEventListener('click', () => {
            const newThreshold = parseInt(thresholdInput.value);
            if (!isNaN(newThreshold) && newThreshold > 0) {
                CHANGE_THRESHOLD = newThreshold;
            } else {
                alert('请输入一个有效的正整数作为阈值。');
            }
        });
 
        renderHistory();
    </script>
</body>
 
</html>

HTML预览器.zip

3.44 KB, 下载次数: 37, 下载积分: 吾爱币 -1 CB

售价: 1 CB吾爱币  [记录]

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

dxin11 发表于 2025-5-6 22:33
这个有点脱裤子放屁的感觉(无恶意)
cbnhaier 发表于 2025-5-6 21:50
li000yu 发表于 2025-5-6 23:14
Wodajunge666 发表于 2025-5-7 00:14
难道有隐藏功能
zhouxinhu 发表于 2025-5-7 01:41
隐藏功能在哪呢
 楼主| zhengzhenhui945 发表于 2025-5-7 03:46
li000yu 发表于 2025-5-6 23:14
这个和直接打开html文件有啥区别么

其中区别就是不用打开html文件,粘贴或者编辑代码可以直接预览
MSS 发表于 2025-5-7 07:44
直接修改代码的话,预览那边是实时更新吗?
1045837055lucy 发表于 2025-5-7 08:21
感谢分享!
试了试,还可以,编辑前端会有帮助。
ltgb 发表于 2025-5-7 08:40
用了感觉还行
但不如用浏览器打开html文件
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-23 14:59

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表