feat(reader): autonomous Wikipedia import and reading with media, tables and settings
This commit is contained in:
1 parent
52db766b23
commit
dee9b8d10b
9 files changed
+1659
-24
No files matched your search
@@ -3603,6 +3603,408 @@ body.drawer-open {
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Wikipedia Articles Section & Settings Modal
|
||||
========================================================================== */
|
||||
|
||||
.wiki-section {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.wiki-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.wiki-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.wiki-icon-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
font-size: 24px;
|
||||
background: rgba(168, 85, 247, 0.12);
|
||||
border: 1px solid rgba(168, 85, 247, 0.28);
|
||||
border-radius: var(--radius-md);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.wiki-heading {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: var(--text-main);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.wiki-action-box {
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 20px 24px;
|
||||
margin-bottom: 24px;
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.wiki-primary-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.wiki-read-btn {
|
||||
padding: 10px 24px;
|
||||
font-weight: 700;
|
||||
font-size: 15px;
|
||||
background: linear-gradient(135deg, #6366f1, #8b5cf6);
|
||||
border: none;
|
||||
box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.wiki-read-btn:hover {
|
||||
background: linear-gradient(135deg, #4f46e5, #7c3aed);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
|
||||
}
|
||||
|
||||
.wiki-settings-btn {
|
||||
padding: 10px 18px;
|
||||
font-weight: 600;
|
||||
border-color: rgba(168, 85, 247, 0.35);
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.wiki-settings-btn:hover {
|
||||
background: rgba(168, 85, 247, 0.12);
|
||||
border-color: #a855f7;
|
||||
color: #c084fc;
|
||||
}
|
||||
|
||||
.wiki-badges-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.wiki-badges-label {
|
||||
color: var(--text-dim);
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05em;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.wiki-badge-chip {
|
||||
background: rgba(168, 85, 247, 0.12);
|
||||
color: #c084fc;
|
||||
border: 1px solid rgba(168, 85, 247, 0.28);
|
||||
border-radius: var(--radius-full);
|
||||
padding: 4px 12px;
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.wiki-fetch-status {
|
||||
margin-top: 14px;
|
||||
padding: 10px 16px;
|
||||
font-size: 13.5px;
|
||||
border-radius: var(--radius-md);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.wiki-status-loading {
|
||||
background: rgba(99, 102, 241, 0.12);
|
||||
color: #818cf8;
|
||||
border: 1px solid rgba(99, 102, 241, 0.3);
|
||||
}
|
||||
|
||||
.wiki-status-success {
|
||||
background: rgba(34, 197, 94, 0.12);
|
||||
color: #4ade80;
|
||||
border: 1px solid rgba(34, 197, 94, 0.25);
|
||||
}
|
||||
|
||||
.wiki-status-error {
|
||||
background: rgba(239, 68, 68, 0.12);
|
||||
color: #f87171;
|
||||
border: 1px solid rgba(239, 68, 68, 0.25);
|
||||
}
|
||||
|
||||
.wiki-empty-state {
|
||||
padding: 36px 20px;
|
||||
background: var(--bg-surface);
|
||||
border: 1px dashed var(--border-color);
|
||||
border-radius: var(--radius-lg);
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
/* Card styling for Wikipedia and thumbnails */
|
||||
.wiki-card {
|
||||
border-color: rgba(168, 85, 247, 0.22);
|
||||
}
|
||||
|
||||
.wiki-card:hover {
|
||||
border-color: rgba(168, 85, 247, 0.55);
|
||||
box-shadow: 0 8px 24px rgba(168, 85, 247, 0.15);
|
||||
}
|
||||
|
||||
.wiki-cover-icon {
|
||||
background: rgba(168, 85, 247, 0.12);
|
||||
border-color: rgba(168, 85, 247, 0.3);
|
||||
color: #c084fc;
|
||||
}
|
||||
|
||||
.badge-wiki {
|
||||
background: rgba(168, 85, 247, 0.18);
|
||||
color: #c084fc;
|
||||
border: 1px solid rgba(168, 85, 247, 0.35);
|
||||
}
|
||||
|
||||
.wiki-progress-fill {
|
||||
background: linear-gradient(90deg, #7c3aed, #a855f7);
|
||||
}
|
||||
|
||||
.book-cover-img-wrap {
|
||||
width: 52px;
|
||||
height: 64px;
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.book-cover-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.badge-time {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: var(--text-dim);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
padding: 2px 7px;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
/* Wikipedia Settings Modal */
|
||||
.wiki-modal-window {
|
||||
max-width: 620px;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.wiki-modal-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.wiki-setting-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.wiki-group-label {
|
||||
font-size: 13.5px;
|
||||
font-weight: 700;
|
||||
color: var(--text-main);
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.wiki-radio-cards {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.wiki-radio-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
background: var(--bg-input);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.wiki-radio-card:hover {
|
||||
border-color: rgba(168, 85, 247, 0.4);
|
||||
background: rgba(168, 85, 247, 0.04);
|
||||
}
|
||||
|
||||
.wiki-radio-card:has(input:checked) {
|
||||
border-color: #a855f7;
|
||||
background: rgba(168, 85, 247, 0.1);
|
||||
box-shadow: 0 0 0 1px #a855f7;
|
||||
}
|
||||
|
||||
.wiki-radio-card input[type="radio"] {
|
||||
margin-top: 3px;
|
||||
accent-color: #a855f7;
|
||||
}
|
||||
|
||||
.wiki-radio-card-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.wiki-card-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.wiki-card-desc {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
line-height: 1.45;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.badge-level-pill {
|
||||
font-size: 10.5px;
|
||||
font-weight: 700;
|
||||
padding: 1px 7px;
|
||||
border-radius: var(--radius-full);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.badge-level-a2 {
|
||||
background: rgba(34, 197, 94, 0.2);
|
||||
color: #4ade80;
|
||||
border: 1px solid rgba(34, 197, 94, 0.35);
|
||||
}
|
||||
|
||||
.badge-level-b2 {
|
||||
background: rgba(59, 130, 246, 0.2);
|
||||
color: #60a5fa;
|
||||
border: 1px solid rgba(59, 130, 246, 0.35);
|
||||
}
|
||||
|
||||
.wiki-time-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.wiki-time-pill {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.wiki-time-pill input[type="radio"] {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.wiki-pill-text {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 10px 8px;
|
||||
background: var(--bg-input);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--text-main);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.wiki-pill-text small {
|
||||
font-size: 11px;
|
||||
font-weight: normal;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.wiki-time-pill:hover .wiki-pill-text {
|
||||
border-color: rgba(168, 85, 247, 0.4);
|
||||
}
|
||||
|
||||
.wiki-time-pill input[type="radio"]:checked + .wiki-pill-text {
|
||||
border-color: #a855f7;
|
||||
background: rgba(168, 85, 247, 0.12);
|
||||
color: #c084fc;
|
||||
box-shadow: 0 0 0 1px #a855f7;
|
||||
}
|
||||
|
||||
.wiki-select {
|
||||
width: 100%;
|
||||
padding: 10px 14px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.wiki-direct-import-group {
|
||||
border-top: 1px dashed var(--border-color);
|
||||
padding-top: 18px;
|
||||
}
|
||||
|
||||
.wiki-custom-input-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.wiki-custom-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.wiki-custom-fetch-btn {
|
||||
white-space: nowrap;
|
||||
padding: 0 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.wiki-radio-cards {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.wiki-custom-input-wrap {
|
||||
flex-direction: column;
|
||||
}
|
||||
.wiki-custom-fetch-btn {
|
||||
width: 100%;
|
||||
padding: 10px 16px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reader Interface */
|
||||
.reader-interface {
|
||||
background-color: var(--bg-surface);
|
||||
@@ -4273,6 +4675,48 @@ body.drawer-open {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* Figures and Media (Images, Diagrams, Animated GIFs, SVGs) */
|
||||
.reader-figure {
|
||||
margin: 28px auto;
|
||||
padding: 14px;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
max-width: 95%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.reader-figure-img {
|
||||
max-width: 100%;
|
||||
max-height: 480px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: var(--radius-md);
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.reader-figcaption {
|
||||
margin-top: 12px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
font-size: 13.5px;
|
||||
line-height: 1.55;
|
||||
color: var(--text-dim);
|
||||
text-align: center;
|
||||
max-width: 90%;
|
||||
font-style: italic;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.reader-figcaption .reader-word {
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.reader-content-body p[style*="text-align: center"],
|
||||
.reader-content-body p.text-center {
|
||||
text-indent: 0 !important;
|
||||
|
||||
+137
-1
@@ -546,7 +546,52 @@
|
||||
</div>
|
||||
<div id="bookshelf-grid" class="bookshelf-grid"></div>
|
||||
|
||||
<!-- Divider between General Books & RFC Specifications -->
|
||||
<!-- Divider between General Books & Wikipedia Section -->
|
||||
<hr class="bookshelf-divider">
|
||||
|
||||
<!-- Wikipedia Articles Section -->
|
||||
<div id="wiki-section" class="wiki-section">
|
||||
<div class="wiki-header">
|
||||
<div class="wiki-title-wrap">
|
||||
<div class="wiki-title-row">
|
||||
<span class="wiki-icon-badge">🌐</span>
|
||||
<div>
|
||||
<h3 class="wiki-heading">Статьи Википедии (Wikipedia Reader)</h3>
|
||||
<p class="subtitle">Автономное чтение статей Simple и Standard Wikipedia с иллюстрациями, таблицами и клик-переводом</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wikipedia Action Bar & Current Settings Badges -->
|
||||
<div class="wiki-action-box">
|
||||
<div class="wiki-primary-actions">
|
||||
<button type="button" id="wiki-read-btn" class="btn btn-primary wiki-read-btn">
|
||||
<span>📖 Читать статью</span>
|
||||
</button>
|
||||
<button type="button" id="wiki-settings-btn" class="btn btn-outline wiki-settings-btn" title="Настроить сложность, объем и тематику статьи">
|
||||
<span>⚙️ Настройки</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="wiki-badges-row">
|
||||
<span class="wiki-badges-label">Текущие фильтры:</span>
|
||||
<span id="wiki-active-lang-badge" class="badge-chip wiki-badge-chip">Simple English (A2–B1)</span>
|
||||
<span id="wiki-active-time-badge" class="badge-chip wiki-badge-chip">⏱️ ~10-15 мин</span>
|
||||
<span id="wiki-active-topic-badge" class="badge-chip wiki-badge-chip">🎲 Любая тема</span>
|
||||
</div>
|
||||
<div id="wiki-fetch-status" class="wiki-fetch-status hidden"></div>
|
||||
</div>
|
||||
|
||||
<!-- Wikipedia Articles Grid / Empty State -->
|
||||
<div id="wiki-empty-state" class="empty-state wiki-empty-state hidden">
|
||||
<div class="empty-icon">🌐</div>
|
||||
<h4>Нет сохраненных статей из Википедии</h4>
|
||||
<p>Нажмите «Читать статью» выше, чтобы подобрать случайную познавательную статью по вашим настройкам, или настройте тему и объем через шестерёнку ⚙️.</p>
|
||||
</div>
|
||||
<div id="wiki-grid" class="bookshelf-grid wiki-grid"></div>
|
||||
</div>
|
||||
|
||||
<!-- Divider between Wikipedia & RFC Specifications -->
|
||||
<hr class="bookshelf-divider">
|
||||
|
||||
<!-- RFC Specifications Section -->
|
||||
@@ -1253,6 +1298,97 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Wikipedia Settings Modal -->
|
||||
<div id="wiki-settings-modal" class="modal-backdrop hidden">
|
||||
<div class="modal-window wiki-modal-window">
|
||||
<div class="modal-header">
|
||||
<h3>⚙️ Настройки статей Википедии</h3>
|
||||
<button id="wiki-settings-close-btn" class="icon-btn" title="Закрыть">✕</button>
|
||||
</div>
|
||||
<div class="modal-body wiki-modal-body">
|
||||
<!-- Setting 1: Language / Complexity -->
|
||||
<div class="wiki-setting-group">
|
||||
<label class="wiki-group-label">Сложность языка (Wikipedia Edition):</label>
|
||||
<div class="wiki-radio-cards">
|
||||
<label class="wiki-radio-card">
|
||||
<input type="radio" name="wiki-lang" value="simple" checked>
|
||||
<div class="wiki-radio-card-content">
|
||||
<div class="wiki-card-title-row">
|
||||
<strong>Simple English</strong>
|
||||
<span class="badge-level-pill badge-level-a2">A2–B1</span>
|
||||
</div>
|
||||
<p class="wiki-card-desc">Простая грамматика и базовая лексика (simple.wikipedia.org). Рекомендуется для уверенного чтения без перегрузки редкими терминами.</p>
|
||||
</div>
|
||||
</label>
|
||||
<label class="wiki-radio-card">
|
||||
<input type="radio" name="wiki-lang" value="en">
|
||||
<div class="wiki-radio-card-content">
|
||||
<div class="wiki-card-title-row">
|
||||
<strong>Standard English</strong>
|
||||
<span class="badge-level-pill badge-level-b2">B2–C1</span>
|
||||
</div>
|
||||
<p class="wiki-card-desc">Полный оригинальный текст (en.wikipedia.org). Академическая лексика, развернутые описания и глубокая научная терминология.</p>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Setting 2: Reading Volume / Duration -->
|
||||
<div class="wiki-setting-group">
|
||||
<label class="wiki-group-label">Объем статьи / Время чтения:</label>
|
||||
<div class="wiki-time-grid">
|
||||
<label class="wiki-time-pill">
|
||||
<input type="radio" name="wiki-time" value="5">
|
||||
<span class="wiki-pill-text">⚡ ~5 мин <small class="text-dim">(800–1200 слов)</small></span>
|
||||
</label>
|
||||
<label class="wiki-time-pill">
|
||||
<input type="radio" name="wiki-time" value="10-15" checked>
|
||||
<span class="wiki-pill-text">⏱️ ~10–15 мин <small class="text-dim">(1500–2500 слов)</small></span>
|
||||
</label>
|
||||
<label class="wiki-time-pill">
|
||||
<input type="radio" name="wiki-time" value="20+">
|
||||
<span class="wiki-pill-text">📚 20+ мин <small class="text-dim">(лонгрид от 3000 слов)</small></span>
|
||||
</label>
|
||||
<label class="wiki-time-pill">
|
||||
<input type="radio" name="wiki-time" value="any">
|
||||
<span class="wiki-pill-text">🎲 Любой объем</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Setting 3: Topic Presets -->
|
||||
<div class="wiki-setting-group">
|
||||
<label class="wiki-group-label">Тематика статьи:</label>
|
||||
<select id="wiki-topic-select" class="input-styled wiki-select">
|
||||
<option value="random">🎲 Любая / Случайная тема</option>
|
||||
<option value="science">🚀 Наука, космос и астрономия</option>
|
||||
<option value="tech">💻 Технологии, IT и интернет</option>
|
||||
<option value="history">🏛️ История и великие цивилизации</option>
|
||||
<option value="nature">🌿 Природа, животные и экология</option>
|
||||
<option value="psychology">🧠 Психология, мозг и память</option>
|
||||
<option value="featured">⭐ Статья дня (Featured Article)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Setting 4: Direct Article URL or Title -->
|
||||
<div class="wiki-setting-group wiki-direct-import-group">
|
||||
<label class="wiki-group-label">Или загрузить конкретную статью по ссылке/названию:</label>
|
||||
<form id="wiki-custom-form" class="wiki-custom-form">
|
||||
<div class="wiki-custom-input-wrap">
|
||||
<input type="text" id="wiki-custom-input" class="input-styled wiki-custom-input" placeholder="Название (напр. Black hole, Solar System) или URL статьи" autocomplete="off" spellcheck="false">
|
||||
<button type="submit" id="wiki-custom-fetch-btn" class="btn btn-primary wiki-custom-fetch-btn">
|
||||
<span>📥 Загрузить</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" id="wiki-settings-save-btn" class="btn btn-primary">Применить настройки</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Move Collection Modal -->
|
||||
<div id="move-col-modal" class="modal-backdrop hidden">
|
||||
<div class="modal-window modal-sm">
|
||||
|
||||
@@ -230,6 +230,26 @@ export const api = {
|
||||
detail = errData.detail || detail;
|
||||
} catch (_) {}
|
||||
throw new Error(detail);
|
||||
},
|
||||
async fetchWikipedia({ query = '', lang = 'simple', time_budget = '10-15', topic = 'random', force = false } = {}) {
|
||||
const resp = await fetch('/api/books/fetch-wikipedia', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
lang: lang,
|
||||
time_budget: time_budget,
|
||||
topic: topic,
|
||||
force: force
|
||||
})
|
||||
});
|
||||
if (resp.ok) return await resp.json();
|
||||
let detail = 'Не удалось загрузить статью из Wikipedia';
|
||||
try {
|
||||
const errData = await resp.json();
|
||||
detail = errData.detail || detail;
|
||||
} catch (_) {}
|
||||
throw new Error(detail);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+359
-14
@@ -42,7 +42,10 @@ export function getCurrentChapterIndex() {
|
||||
function createBookCard(b) {
|
||||
const card = document.createElement('div');
|
||||
const isRfc = (b.source_type === 'rfc');
|
||||
card.className = isRfc ? 'book-card rfc-card' : 'book-card';
|
||||
const isWiki = (b.source_type === 'wikipedia');
|
||||
if (isWiki) card.className = 'book-card wiki-card';
|
||||
else if (isRfc) card.className = 'book-card rfc-card';
|
||||
else card.className = 'book-card';
|
||||
|
||||
const totalCh = Math.max(1, b.chapters_count || 1);
|
||||
const chIndex = Math.max(0, Math.min(totalCh - 1, b.current_chapter || 0));
|
||||
@@ -56,22 +59,42 @@ function createBookCard(b) {
|
||||
? `<span>1 глава • ${totalPct}%</span><span>${totalPct}%</span>`
|
||||
: `<span>Глава ${chIndex + 1} из ${totalCh} (${chPct}%)</span><span>${totalPct}%</span>`;
|
||||
|
||||
let coverIcon = '📄';
|
||||
if (b.source_type === 'epub') coverIcon = '📕';
|
||||
else if (b.source_type === 'pdf') coverIcon = '📑';
|
||||
else if (b.source_type === 'rfc') coverIcon = '🌐';
|
||||
let coverHtml = '';
|
||||
if (b.cover_url) {
|
||||
coverHtml = `<div class="book-cover-img-wrap"><img src="${escapeHtml(b.cover_url)}" class="book-cover-img" alt="Cover" loading="lazy" onerror="this.parentElement.innerHTML='<div class=\\\'book-cover-icon ${isWiki ? 'wiki-cover-icon' : (isRfc ? 'rfc-cover-icon' : '')}\\\'>${isWiki ? '🌐' : (isRfc ? '📜' : '📄')}</div>';"/></div>`;
|
||||
} else {
|
||||
let coverIcon = '📄';
|
||||
if (b.source_type === 'epub') coverIcon = '📕';
|
||||
else if (b.source_type === 'pdf') coverIcon = '📑';
|
||||
else if (isRfc) coverIcon = '📜';
|
||||
else if (isWiki) coverIcon = '🌐';
|
||||
const coverIconClass = isWiki ? 'wiki-cover-icon' : (isRfc ? 'rfc-cover-icon' : '');
|
||||
coverHtml = `<div class="book-cover-icon ${coverIconClass}">${coverIcon}</div>`;
|
||||
}
|
||||
|
||||
const badgeClass = isRfc ? 'badge-format badge-rfc' : 'badge-format';
|
||||
let badgeClass = 'badge-format';
|
||||
if (isWiki) badgeClass = 'badge-format badge-wiki';
|
||||
else if (isRfc) badgeClass = 'badge-format badge-rfc';
|
||||
|
||||
const readMinutes = Math.max(1, Math.round((b.total_words || 800) / 180));
|
||||
const timeBadge = (b.total_words && b.total_words > 0)
|
||||
? `<span class="badge-time" title="Примерное время чтения: ~${readMinutes} минут">⏱️ ~${readMinutes} мин</span>`
|
||||
: '';
|
||||
const progressFillClass = isWiki ? 'wiki-progress-fill' : (isRfc ? 'rfc-progress-fill' : '');
|
||||
|
||||
const authorDisplay = b.author || (isWiki ? 'Wikipedia' : (isRfc ? 'IETF' : 'Неизвестный автор'));
|
||||
const sourceLabel = isWiki ? 'WIKIPEDIA' : (isRfc ? 'RFC' : (b.source_type || 'text').toUpperCase());
|
||||
|
||||
card.innerHTML = `
|
||||
<div>
|
||||
<div class="book-card-top">
|
||||
<div class="book-cover-icon ${isRfc ? 'rfc-cover-icon' : ''}">${coverIcon}</div>
|
||||
${coverHtml}
|
||||
<div class="book-card-info">
|
||||
<h4 class="book-card-title" title="${escapeHtml(b.title)}">${escapeHtml(b.title)}</h4>
|
||||
<p class="book-card-author">${escapeHtml(b.author || (isRfc ? 'IETF' : 'Неизвестный автор'))}</p>
|
||||
<p class="book-card-author">${escapeHtml(authorDisplay)}</p>
|
||||
<div class="book-card-badges">
|
||||
<span class="${badgeClass}">${escapeHtml((b.source_type || 'text').toUpperCase())}</span>
|
||||
<span class="${badgeClass}">${escapeHtml(sourceLabel)}</span>
|
||||
${timeBadge}
|
||||
<span class="badge-words">${b.total_words ? b.total_words.toLocaleString() + ' слов' : ''}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -81,14 +104,14 @@ function createBookCard(b) {
|
||||
${progressLabels}
|
||||
</div>
|
||||
<div class="book-progress-bar-bg">
|
||||
<div class="book-progress-bar-fill ${isRfc ? 'rfc-progress-fill' : ''}" style="width: ${totalPct}%"></div>
|
||||
<div class="book-progress-bar-fill ${progressFillClass}" style="width: ${totalPct}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="book-card-actions">
|
||||
<button class="btn btn-primary btn-sm read-book-btn" data-id="${b.id}">📖 Читать</button>
|
||||
<button class="btn btn-outline btn-xs train-book-btn" data-title="${escapeHtml(b.title)}" title="Тренировать слова из этой книги">🎓 Слова книги</button>
|
||||
<button class="icon-btn delete-book-btn" data-id="${b.id}" title="Удалить книгу">🗑️</button>
|
||||
<button class="icon-btn delete-book-btn" data-id="${b.id}" title="Удалить из библиотеки">🗑️</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -100,7 +123,7 @@ function createBookCard(b) {
|
||||
window.location.hash = `#srs/${encodeURIComponent(bookTag)}`;
|
||||
});
|
||||
card.querySelector('.delete-book-btn').addEventListener('click', async () => {
|
||||
const typeName = isRfc ? 'спецификацию' : 'книгу';
|
||||
const typeName = isWiki ? 'статью Википедии' : (isRfc ? 'спецификацию' : 'книгу');
|
||||
if (confirm(`Удалить ${typeName} "${b.title}" из библиотеки?`)) {
|
||||
await api.books.delete(b.id);
|
||||
loadBookshelf();
|
||||
@@ -117,6 +140,8 @@ export async function loadBookshelf() {
|
||||
const bookshelfEmpty = document.getElementById('bookshelf-empty');
|
||||
const rfcGrid = document.getElementById('rfc-grid');
|
||||
const rfcEmptyState = document.getElementById('rfc-empty-state');
|
||||
const wikiGrid = document.getElementById('wiki-grid');
|
||||
const wikiEmptyState = document.getElementById('wiki-empty-state');
|
||||
|
||||
if (!bookshelfContainer) return;
|
||||
if (!window.location.hash.includes('/book/')) {
|
||||
@@ -125,8 +150,10 @@ export async function loadBookshelf() {
|
||||
}
|
||||
if (bookshelfGrid) bookshelfGrid.innerHTML = '';
|
||||
if (rfcGrid) rfcGrid.innerHTML = '';
|
||||
if (wikiGrid) wikiGrid.innerHTML = '';
|
||||
if (bookshelfEmpty) bookshelfEmpty.classList.add('hidden');
|
||||
if (rfcEmptyState) rfcEmptyState.classList.add('hidden');
|
||||
if (wikiEmptyState) wikiEmptyState.classList.add('hidden');
|
||||
|
||||
try {
|
||||
const books = await api.books.getAll();
|
||||
@@ -141,12 +168,16 @@ export function renderBookshelf(books) {
|
||||
const bookshelfEmpty = document.getElementById('bookshelf-empty');
|
||||
const rfcGrid = document.getElementById('rfc-grid');
|
||||
const rfcEmptyState = document.getElementById('rfc-empty-state');
|
||||
const wikiGrid = document.getElementById('wiki-grid');
|
||||
const wikiEmptyState = document.getElementById('wiki-empty-state');
|
||||
|
||||
if (bookshelfGrid) bookshelfGrid.innerHTML = '';
|
||||
if (rfcGrid) rfcGrid.innerHTML = '';
|
||||
if (wikiGrid) wikiGrid.innerHTML = '';
|
||||
|
||||
const generalBooks = (books || []).filter(b => b.source_type !== 'rfc');
|
||||
const generalBooks = (books || []).filter(b => b.source_type !== 'rfc' && b.source_type !== 'wikipedia');
|
||||
const rfcBooks = (books || []).filter(b => b.source_type === 'rfc');
|
||||
const wikiBooks = (books || []).filter(b => b.source_type === 'wikipedia');
|
||||
|
||||
if (bookshelfEmpty) {
|
||||
bookshelfEmpty.classList.toggle('hidden', generalBooks.length > 0);
|
||||
@@ -157,6 +188,15 @@ export function renderBookshelf(books) {
|
||||
});
|
||||
}
|
||||
|
||||
if (wikiEmptyState) {
|
||||
wikiEmptyState.classList.toggle('hidden', wikiBooks.length > 0);
|
||||
}
|
||||
if (wikiGrid) {
|
||||
wikiBooks.forEach(b => {
|
||||
wikiGrid.appendChild(createBookCard(b));
|
||||
});
|
||||
}
|
||||
|
||||
if (rfcEmptyState) {
|
||||
rfcEmptyState.classList.toggle('hidden', rfcBooks.length > 0);
|
||||
}
|
||||
@@ -375,6 +415,24 @@ export function buildChapterDOM(chapterIdx, knownWordsMap, isContinuous = false)
|
||||
|
||||
blockEl.appendChild(header);
|
||||
blockEl.appendChild(pre);
|
||||
} else if (block.type === 'figure') {
|
||||
blockEl = document.createElement('figure');
|
||||
blockEl.className = 'reader-figure';
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.className = 'reader-figure-img';
|
||||
img.src = block.src;
|
||||
img.alt = block.alt || '';
|
||||
img.loading = 'lazy';
|
||||
img.onerror = () => { blockEl.style.display = 'none'; };
|
||||
blockEl.appendChild(img);
|
||||
|
||||
if (block.caption) {
|
||||
const figcaption = document.createElement('figcaption');
|
||||
figcaption.className = 'reader-figcaption';
|
||||
renderInteractiveSpans(figcaption, block.caption, block.caption, knownWordsMap);
|
||||
blockEl.appendChild(figcaption);
|
||||
}
|
||||
} else if (block.type === 'table') {
|
||||
blockEl = document.createElement('div');
|
||||
blockEl.className = 'reader-table-wrap';
|
||||
@@ -804,6 +862,86 @@ export function parseContentBlocks(content) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2a. HTML Figure Block: <figure ...> ... </figure>
|
||||
if (/^<figure\b/i.test(trimmed)) {
|
||||
const figLines = [];
|
||||
while (i < lines.length) {
|
||||
figLines.push(lines[i]);
|
||||
if (/<\/figure>/i.test(lines[i])) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
const figHtml = figLines.join('\n');
|
||||
const imgMatch = figHtml.match(/<img\b([^>]*)>/i);
|
||||
let src = '';
|
||||
let alt = '';
|
||||
if (imgMatch) {
|
||||
const srcM = imgMatch[1].match(/src=["']([^"']+)["']/i);
|
||||
const altM = imgMatch[1].match(/alt=["']([^"']*)["']/i);
|
||||
if (srcM) src = srcM[1];
|
||||
if (altM) alt = altM[1];
|
||||
}
|
||||
let caption = '';
|
||||
const capMatch = figHtml.match(/<figcaption\b[^>]*>([\s\S]*?)<\/figcaption>/i);
|
||||
if (capMatch) {
|
||||
caption = capMatch[1].replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
if (src) {
|
||||
blocks.push({
|
||||
type: 'figure',
|
||||
src: src,
|
||||
alt: alt,
|
||||
caption: caption
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 2b. HTML Data Table: <div class="reader-table-wrap"><table ...> or <table ...>
|
||||
if (/^(?:<div[^>]*class=["'][^"']*reader-table-wrap[^"']*["'][^>]*>\s*)?<table\b/i.test(trimmed)) {
|
||||
const tableLines = [];
|
||||
while (i < lines.length) {
|
||||
tableLines.push(lines[i]);
|
||||
if (/<\/table>(?:\s*<\/div>)?/i.test(lines[i])) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
const fullTableHtml = tableLines.join('\n');
|
||||
const tpl = document.createElement('template');
|
||||
tpl.innerHTML = fullTableHtml;
|
||||
const tableEl = tpl.content.querySelector('table');
|
||||
if (tableEl) {
|
||||
const headers = [];
|
||||
const ths = tableEl.querySelectorAll('thead th, tr:first-child th');
|
||||
ths.forEach(th => headers.push(th.textContent.trim()));
|
||||
|
||||
const rows = [];
|
||||
const trs = tableEl.querySelectorAll('tbody tr, tr');
|
||||
trs.forEach((tr) => {
|
||||
const tds = tr.querySelectorAll('td');
|
||||
if (tds.length > 0) {
|
||||
const rowCells = [];
|
||||
tds.forEach(td => rowCells.push(td.textContent.trim()));
|
||||
rows.push(rowCells);
|
||||
}
|
||||
});
|
||||
|
||||
if (headers.length > 0 || rows.length > 0) {
|
||||
blocks.push({
|
||||
type: 'table',
|
||||
headers: headers,
|
||||
alignments: headers.map(() => 'left'),
|
||||
rows: rows
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Markdown Table: lines starting with | and ending with |
|
||||
if (trimmed.startsWith('|') && trimmed.endsWith('|')) {
|
||||
const tableLines = [];
|
||||
@@ -950,6 +1088,9 @@ export function parseContentBlocks(content) {
|
||||
/^[-*+]\s+/.test(curTrim) ||
|
||||
/^\d+\.\s+/.test(curTrim) ||
|
||||
/^(\-{3,}|\*{3,}|\_{3,})$/.test(curTrim) ||
|
||||
/^<figure\b/i.test(curTrim) ||
|
||||
/^<table\b/i.test(curTrim) ||
|
||||
curTrim.includes('reader-table-wrap') ||
|
||||
/^<(?:p|div)[^>]*align=["']?center/i.test(curTrim)) {
|
||||
break;
|
||||
}
|
||||
@@ -1899,7 +2040,7 @@ export function initReader() {
|
||||
if (wordSpan) {
|
||||
e.stopPropagation();
|
||||
const word = wordSpan.dataset.word;
|
||||
const context = wordSpan.dataset.context || wordSpan.closest('p, div, li, td, th, blockquote')?.textContent || word;
|
||||
const context = wordSpan.dataset.context || wordSpan.closest('p, div, li, td, th, blockquote, figcaption')?.textContent || word;
|
||||
handleWordClick(word, context, wordSpan);
|
||||
}
|
||||
});
|
||||
@@ -2448,4 +2589,208 @@ export function initReader() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Wikipedia Autonomous Import & Settings
|
||||
// -----------------------------------------------------------------------
|
||||
const WIKI_SETTINGS_KEY = 'notes_wiki_settings';
|
||||
const wikiReadBtn = document.getElementById('wiki-read-btn');
|
||||
const wikiSettingsBtn = document.getElementById('wiki-settings-btn');
|
||||
const wikiSettingsModal = document.getElementById('wiki-settings-modal');
|
||||
const wikiSettingsCloseBtn = document.getElementById('wiki-settings-close-btn');
|
||||
const wikiSettingsSaveBtn = document.getElementById('wiki-settings-save-btn');
|
||||
const wikiFetchStatus = document.getElementById('wiki-fetch-status');
|
||||
const wikiCustomForm = document.getElementById('wiki-custom-form');
|
||||
const wikiCustomInput = document.getElementById('wiki-custom-input');
|
||||
const wikiCustomFetchBtn = document.getElementById('wiki-custom-fetch-btn');
|
||||
|
||||
const wikiActiveLangBadge = document.getElementById('wiki-active-lang-badge');
|
||||
const wikiActiveTimeBadge = document.getElementById('wiki-active-time-badge');
|
||||
const wikiActiveTopicBadge = document.getElementById('wiki-active-topic-badge');
|
||||
|
||||
const TOPIC_LABELS = {
|
||||
'random': '🎲 Любая тема',
|
||||
'science': '🚀 Наука и космос',
|
||||
'tech': '💻 Технологии и IT',
|
||||
'history': '🏛️ История',
|
||||
'nature': '🌿 Природа',
|
||||
'psychology': '🧠 Психология',
|
||||
'featured': '⭐ Статья дня'
|
||||
};
|
||||
|
||||
const TIME_LABELS = {
|
||||
'5': '⏱️ ~5 мин',
|
||||
'10-15': '⏱️ ~10-15 мин',
|
||||
'20+': '⏱️ 20+ мин',
|
||||
'any': '⏱️ Любой объем'
|
||||
};
|
||||
|
||||
function getStoredWikiSettings() {
|
||||
try {
|
||||
const raw = localStorage.getItem(WIKI_SETTINGS_KEY);
|
||||
if (raw) {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (parsed && typeof parsed === 'object') {
|
||||
return {
|
||||
lang: parsed.lang || 'simple',
|
||||
time_budget: parsed.time_budget || '10-15',
|
||||
topic: parsed.topic || 'random'
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
return { lang: 'simple', time_budget: '10-15', topic: 'random' };
|
||||
}
|
||||
|
||||
function saveStoredWikiSettings(settings) {
|
||||
try {
|
||||
localStorage.setItem(WIKI_SETTINGS_KEY, JSON.stringify(settings));
|
||||
} catch (_) {}
|
||||
updateWikiUIBadges(settings);
|
||||
}
|
||||
|
||||
function updateWikiUIBadges(settings) {
|
||||
if (wikiActiveLangBadge) {
|
||||
wikiActiveLangBadge.textContent = settings.lang === 'en' ? 'Standard English (B2–C1)' : 'Simple English (A2–B1)';
|
||||
}
|
||||
if (wikiActiveTimeBadge) {
|
||||
wikiActiveTimeBadge.textContent = TIME_LABELS[settings.time_budget] || '⏱️ ~10-15 мин';
|
||||
}
|
||||
if (wikiActiveTopicBadge) {
|
||||
wikiActiveTopicBadge.textContent = TOPIC_LABELS[settings.topic] || '🎲 Любая тема';
|
||||
}
|
||||
}
|
||||
|
||||
function syncWikiModalInputs(settings) {
|
||||
const langRadios = document.querySelectorAll('input[name="wiki-lang"]');
|
||||
langRadios.forEach(r => {
|
||||
r.checked = (r.value === settings.lang);
|
||||
});
|
||||
const timeRadios = document.querySelectorAll('input[name="wiki-time"]');
|
||||
timeRadios.forEach(r => {
|
||||
r.checked = (r.value === settings.time_budget);
|
||||
});
|
||||
const topicSelect = document.getElementById('wiki-topic-select');
|
||||
if (topicSelect) {
|
||||
topicSelect.value = settings.topic || 'random';
|
||||
}
|
||||
}
|
||||
|
||||
function readWikiModalInputs() {
|
||||
const langRadio = document.querySelector('input[name="wiki-lang"]:checked');
|
||||
const timeRadio = document.querySelector('input[name="wiki-time"]:checked');
|
||||
const topicSelect = document.getElementById('wiki-topic-select');
|
||||
|
||||
return {
|
||||
lang: langRadio ? langRadio.value : 'simple',
|
||||
time_budget: timeRadio ? timeRadio.value : '10-15',
|
||||
topic: topicSelect ? topicSelect.value : 'random'
|
||||
};
|
||||
}
|
||||
|
||||
const currentWikiSettings = getStoredWikiSettings();
|
||||
updateWikiUIBadges(currentWikiSettings);
|
||||
|
||||
if (wikiSettingsBtn && wikiSettingsModal) {
|
||||
wikiSettingsBtn.addEventListener('click', () => {
|
||||
syncWikiModalInputs(getStoredWikiSettings());
|
||||
wikiSettingsModal.classList.remove('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
if (wikiSettingsCloseBtn && wikiSettingsModal) {
|
||||
wikiSettingsCloseBtn.addEventListener('click', () => {
|
||||
wikiSettingsModal.classList.add('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
if (wikiSettingsModal) {
|
||||
wikiSettingsModal.addEventListener('click', (e) => {
|
||||
if (e.target === wikiSettingsModal) {
|
||||
wikiSettingsModal.classList.add('hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (wikiSettingsSaveBtn && wikiSettingsModal) {
|
||||
wikiSettingsSaveBtn.addEventListener('click', () => {
|
||||
const newSettings = readWikiModalInputs();
|
||||
saveStoredWikiSettings(newSettings);
|
||||
wikiSettingsModal.classList.add('hidden');
|
||||
showToast('Настройки статей Википедии сохранены!');
|
||||
});
|
||||
}
|
||||
|
||||
async function handleWikiFetch(params) {
|
||||
const isCustom = Boolean(params.query);
|
||||
const activeBtn = isCustom ? wikiCustomFetchBtn : wikiReadBtn;
|
||||
|
||||
if (activeBtn) activeBtn.disabled = true;
|
||||
if (wikiReadBtn) wikiReadBtn.disabled = true;
|
||||
if (wikiCustomInput) wikiCustomInput.disabled = true;
|
||||
|
||||
if (wikiFetchStatus) {
|
||||
wikiFetchStatus.className = 'wiki-fetch-status wiki-status-loading';
|
||||
wikiFetchStatus.innerHTML = `<span>⏳ ${isCustom ? 'Загрузка статьи по запросу...' : 'Подбираем и загружаем статью из Википедии...'}</span>`;
|
||||
wikiFetchStatus.classList.remove('hidden');
|
||||
}
|
||||
|
||||
try {
|
||||
const book = await api.books.fetchWikipedia(params);
|
||||
if (wikiFetchStatus) {
|
||||
wikiFetchStatus.className = 'wiki-fetch-status wiki-status-success';
|
||||
const estMin = Math.max(1, Math.round((book.total_words || 800) / 180));
|
||||
wikiFetchStatus.innerHTML = `<span>✅ Статья «${escapeHtml(book.title)}» сохранена (~${estMin} мин, ${book.total_words ? book.total_words.toLocaleString() : ''} слов)!</span>`;
|
||||
}
|
||||
showToast(book.already_existed ? `Открываем ${book.title}` : `Статья Википедии сохранена офлайн!`);
|
||||
if (wikiCustomInput) wikiCustomInput.value = '';
|
||||
await loadBookshelf();
|
||||
setTimeout(() => {
|
||||
if (wikiFetchStatus) wikiFetchStatus.classList.add('hidden');
|
||||
if (wikiSettingsModal) wikiSettingsModal.classList.add('hidden');
|
||||
window.location.hash = `#reader/book/${book.id}`;
|
||||
}, 500);
|
||||
} catch (err) {
|
||||
console.error('Wikipedia fetch error:', err);
|
||||
if (wikiFetchStatus) {
|
||||
wikiFetchStatus.className = 'wiki-fetch-status wiki-status-error';
|
||||
wikiFetchStatus.innerHTML = `<span>❌ Ошибка: ${escapeHtml(err.message || 'Не удалось загрузить статью')}</span>`;
|
||||
wikiFetchStatus.classList.remove('hidden');
|
||||
}
|
||||
showToast(err.message || 'Ошибка загрузки статьи Wikipedia', 4000);
|
||||
} finally {
|
||||
if (activeBtn) activeBtn.disabled = false;
|
||||
if (wikiReadBtn) wikiReadBtn.disabled = false;
|
||||
if (wikiCustomInput) wikiCustomInput.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (wikiReadBtn) {
|
||||
wikiReadBtn.addEventListener('click', () => {
|
||||
const currentSettings = getStoredWikiSettings();
|
||||
handleWikiFetch({
|
||||
query: '',
|
||||
lang: currentSettings.lang,
|
||||
time_budget: currentSettings.time_budget,
|
||||
topic: currentSettings.topic,
|
||||
force: false
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (wikiCustomForm) {
|
||||
wikiCustomForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const val = wikiCustomInput ? wikiCustomInput.value.trim() : '';
|
||||
if (!val) return;
|
||||
const currentSettings = getStoredWikiSettings();
|
||||
handleWikiFetch({
|
||||
query: val,
|
||||
lang: currentSettings.lang,
|
||||
time_budget: currentSettings.time_budget,
|
||||
topic: currentSettings.topic,
|
||||
force: false
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Service Worker for Notes English PWA (Stage 2)
|
||||
// Strategy: Cache-first for static assets, Network-first for API calls.
|
||||
|
||||
const CACHE_NAME = 'notes-v6.2';
|
||||
const CACHE_NAME = 'notes-v6.3';
|
||||
const OFFLINE_URL = '/';
|
||||
|
||||
const PRECACHE_URLS = [
|
||||
|
||||
Reference in new issue
Block a user