This commit is contained in:
Курнат Андрей
2026-02-14 18:50:51 +03:00
parent a37943edc4
commit d6ba23a8ef
3 changed files with 8 additions and 111 deletions

View File

@@ -17,7 +17,6 @@
overflow: hidden;
background-color: #faf8ef;
font-family: serif;
touch-action: none;
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;
@@ -123,16 +122,6 @@
// ========== DEBUG LOGGING ==========
function debugLog(msg) {
console.log('[Reader] ' + msg);
//var logDiv = document.getElementById('debug-log');
//if (logDiv) {
// var line = document.createElement('div');
// line.textContent = new Date().toLocaleTimeString() + ': ' + msg;
// logDiv.appendChild(line);
// logDiv.scrollTop = logDiv.scrollHeight;
// while (logDiv.children.length > 50) {
// logDiv.removeChild(logDiv.firstChild);
// }
//}
}
function showError(msg) {

View File

@@ -42,14 +42,14 @@
</Frame.GestureRecognizers>
<VerticalStackLayout Spacing="15">
<!--Title-->
<!--Title-->
<Label Text="Reading Settings"
FontSize="18"
FontAttributes="Bold"
TextColor="White"
HorizontalOptions="Center" />
<!--Font Size-->
<!--Font Size-->
<VerticalStackLayout Spacing="5">
<Label Text="Font Size"
FontSize="14"
@@ -82,7 +82,7 @@
</Grid>
</VerticalStackLayout>
<!--Font Family-->
<!--Font Family-->
<VerticalStackLayout Spacing="5">
<Label Text="Font Family"
FontSize="14"
@@ -96,7 +96,7 @@
SelectedIndexChanged="OnFontFamilyChanged" />
</VerticalStackLayout>
<!--Chapters Button-->
<!--Chapters Button-->
<Button Text="📑 Chapters"
BackgroundColor="#5D4037"
TextColor="White"
@@ -105,7 +105,7 @@
HeightRequest="45"
Command="{Binding ToggleChapterListCommand}" />
<!--Chapter List-->
<!--Chapter List-->
<CollectionView ItemsSource="{Binding Chapters}"
IsVisible="{Binding IsChapterListVisible}"
MaximumHeightRequest="200"
@@ -123,7 +123,7 @@
</CollectionView.ItemTemplate>
</CollectionView>
<!--Back Button-->
<!--Back Button-->
<Button Text="← Back to Library"
BackgroundColor="#D32F2F"
TextColor="White"

View File

@@ -30,7 +30,6 @@ public partial class ReaderPage : ContentPage
await _viewModel.InitializeAsync();
System.Diagnostics.Debug.WriteLine("[Reader] ViewModel initialized");
StartProgressTimer();
}
catch (Exception ex)
{
@@ -41,32 +40,11 @@ public partial class ReaderPage : ContentPage
protected override async void OnDisappearing()
{
_isActive = false;
StopProgressTimer();
base.OnDisappearing();
await SaveCurrentProgress();
}
// ========== ТАЙМЕРЫ ==========
private void StartProgressTimer()
{
_progressTimer = Dispatcher.CreateTimer();
_progressTimer.Interval = TimeSpan.FromSeconds(10);
_progressTimer.Tick += async (s, e) =>
{
if (_isActive && _isBookLoaded)
{
await SaveCurrentProgress();
}
};
_progressTimer.Start();
}
private void StopProgressTimer()
{
_progressTimer?.Stop();
_progressTimer = null;
}
// ========== ЗАГРУЗКА КНИГИ ==========
@@ -150,76 +128,6 @@ public partial class ReaderPage : ContentPage
}
}
// ========== ПОЛУЧЕНИЕ ГЛАВ ИЗ JS ==========
private async Task FetchChaptersFromJs()
{
try
{
var result = await EvalJsWithResultAsync(@"
(function() {
try {
if (typeof book !== 'undefined' && book && book.navigation && book.navigation.toc) {
var toc = book.navigation.toc;
var arr = [];
for (var i = 0; i < toc.length; i++) {
arr.push({ label: (toc[i].label || '').trim(), href: toc[i].href || '' });
}
return JSON.stringify(arr);
}
var titles = document.querySelectorAll('.fb2-title');
if (titles.length > 0) {
var arr2 = [];
for (var j = 0; j < titles.length; j++) {
arr2.push({ label: titles[j].textContent.trim(), href: titles[j].getAttribute('data-chapter') || j.toString() });
}
return JSON.stringify(arr2);
}
return '[]';
} catch(e) {
return '[]';
}
})()
");
System.Diagnostics.Debug.WriteLine($"[Reader] Chapters raw: {result}");
if (string.IsNullOrEmpty(result) || result == "null") return;
// EvaluateJavaScriptAsync может вернуть экранированную строку
result = UnescapeJsResult(result);
var chapters = JArray.Parse(result);
_chapterData.Clear();
var chapterLabels = new List<string>();
foreach (var ch in chapters)
{
var obj = ch as JObject;
if (obj != null)
{
_chapterData.Add(obj);
var label = obj["label"]?.ToString() ?? "";
if (!string.IsNullOrWhiteSpace(label))
{
chapterLabels.Add(label);
}
}
}
MainThread.BeginInvokeOnMainThread(() =>
{
_viewModel.Chapters = chapterLabels;
});
System.Diagnostics.Debug.WriteLine($"[Reader] Loaded {chapterLabels.Count} chapters");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[Reader] FetchChapters error: {ex.Message}");
}
}
// ========== СОХРАНЕНИЕ ПРОГРЕССА ==========
private async Task SaveCurrentProgress()