предпросмотр и скрипт для сборки бинарей

This commit is contained in:
2025-11-21 02:27:55 +08:00
parent 4159637b83
commit 0fdfb09fa0
4 changed files with 464 additions and 31 deletions

View File

@@ -80,6 +80,17 @@
<button class="scroll-top" onclick="scrollToTop()"></button>
<!-- Модальное окно предпросмотра -->
<div id="previewModal" class="preview-modal">
<div class="preview-content" id="previewContent">
<div class="preview-header">
<h3 class="preview-title" id="previewTitle">Предпросмотр файла</h3>
<button class="close-preview" onclick="closePreview()">×</button>
</div>
<iframe id="previewFrame" class="preview-iframe" sandbox="allow-scripts allow-same-origin"></iframe>
</div>
</div>
<script>
function scrollToTop() {
window.scrollTo({
@@ -112,6 +123,106 @@
document.cookie = `theme=${newTheme}; expires=${date.toUTCString()}; path=/`;
}
// Функции для предпросмотра файлов
function openPreview(fileUrl) {
const modal = document.getElementById('previewModal');
const frame = document.getElementById('previewFrame');
const content = document.getElementById('previewContent');
const title = document.getElementById('previewTitle');
// Получаем имя файла из URL
const fileName = fileUrl.split('/').pop();
title.textContent = `Предпросмотр: ${fileName}`;
// Определяем тип файла для адаптивного масштабирования
const fileExt = fileName.split('.').pop().toLowerCase();
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg', 'ico'];
const textTypes = ['txt', 'md', 'html', 'htm', 'css', 'js', 'json', 'xml', 'csv'];
const audioTypes = ['mp3', 'wav', 'ogg', 'flac', 'm4a', 'aac'];
const videoTypes = ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv'];
const isPDF = fileExt === 'pdf';
// Устанавливаем размеры в зависимости от типа файла
if (imageTypes.includes(fileExt)) {
// Для изображений - автоматический размер
content.style.width = 'auto';
content.style.height = 'auto';
content.style.maxWidth = '90vw';
content.style.maxHeight = '90vh';
} else if (textTypes.includes(fileExt)) {
// Для текстовых файлов - компактное окно
content.style.width = '80vw';
content.style.height = '70vh';
content.style.maxWidth = '800px';
content.style.maxHeight = '600px';
} else if (audioTypes.includes(fileExt)) {
// Для аудио - маленькое окно
content.style.width = '500px';
content.style.height = '300px';
content.style.maxWidth = '90vw';
content.style.maxHeight = '400px';
} else if (videoTypes.includes(fileExt)) {
// Для видео - большое окно
content.style.width = '90vw';
content.style.height = '80vh';
content.style.maxWidth = '1200px';
content.style.maxHeight = '800px';
} else if (isPDF) {
// Для PDF - большое окно
content.style.width = '90vw';
content.style.height = '90vh';
content.style.maxWidth = '1200px';
content.style.maxHeight = '900px';
frame.classList.add('pdf');
} else {
// По умолчанию - средний размер
content.style.width = '80vw';
content.style.height = '80vh';
content.style.maxWidth = '1000px';
content.style.maxHeight = '800px';
}
// Просто открываем файл напрямую в iframe
frame.src = fileUrl;
// Показываем модальное окно
modal.style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closePreview() {
const modal = document.getElementById('previewModal');
const frame = document.getElementById('previewFrame');
const content = document.getElementById('previewContent');
// Скрываем модальное окно и сбрасываем iframe
modal.style.display = 'none';
frame.src = '';
frame.classList.remove('pdf');
// Сбрасываем стили
content.style.width = '';
content.style.height = '';
content.style.maxWidth = '';
content.style.maxHeight = '';
document.body.style.overflow = 'auto';
}
// Закрытие модального окна по клику вне контента
document.getElementById('previewModal').addEventListener('click', function(e) {
if (e.target === this) {
closePreview();
}
});
// Закрытие по ESC
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closePreview();
}
});
document.addEventListener('DOMContentLoaded', function() {
const savedTheme = getCookie('theme');
const button = document.querySelector('.theme-toggle');