document.addEventListener('DOMContentLoaded', () => { // Не запускать на странице создания книги if (window.location.href.includes('/books/create')) { return; } // Ждём инициализации writerEditor function initAutosave() { const writerEditor = window.writerEditor; if (!writerEditor || !writerEditor.quill) { // Пробуем снова через 500ms setTimeout(initAutosave, 500); return; } const textarea = writerEditor.textarea; if (!textarea) return; let lastSavedContent = textarea.value; let saveTimeout; function showMessage(message, isError = false) { let msgEl = document.getElementById('autosave-message'); if (!msgEl) { msgEl = document.createElement('div'); msgEl.id = 'autosave-message'; msgEl.style.cssText = ` position: fixed; top: 70px; right: 10px; padding: 8px 12px; background: ${isError ? '#dc3545' : '#28a745'}; color: white; border-radius: 3px; z-index: 10000; font-size: 0.8rem; box-shadow: 0 2px 5px rgba(0,0,0,0.2); `; document.body.appendChild(msgEl); } msgEl.textContent = message; msgEl.style.background = isError ? '#dc3545' : '#28a745'; msgEl.style.display = 'block'; setTimeout(() => msgEl.style.display = 'none', 2000); } const autoSave = () => { const currentContent = textarea.value; // Не сохранять пустой контент if (!currentContent || currentContent.trim() === '' || currentContent === '