edit
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: #faf8ef;
|
background-color: #faf8ef;
|
||||||
font-family: serif;
|
font-family: serif;
|
||||||
touch-action: none;
|
|
||||||
-webkit-touch-callout: none;
|
-webkit-touch-callout: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@@ -123,16 +122,6 @@
|
|||||||
// ========== DEBUG LOGGING ==========
|
// ========== DEBUG LOGGING ==========
|
||||||
function debugLog(msg) {
|
function debugLog(msg) {
|
||||||
console.log('[Reader] ' + 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) {
|
function showError(msg) {
|
||||||
|
|||||||
@@ -42,14 +42,14 @@
|
|||||||
</Frame.GestureRecognizers>
|
</Frame.GestureRecognizers>
|
||||||
|
|
||||||
<VerticalStackLayout Spacing="15">
|
<VerticalStackLayout Spacing="15">
|
||||||
<!--Title-->
|
<!--Title-->
|
||||||
<Label Text="Reading Settings"
|
<Label Text="Reading Settings"
|
||||||
FontSize="18"
|
FontSize="18"
|
||||||
FontAttributes="Bold"
|
FontAttributes="Bold"
|
||||||
TextColor="White"
|
TextColor="White"
|
||||||
HorizontalOptions="Center" />
|
HorizontalOptions="Center" />
|
||||||
|
|
||||||
<!--Font Size-->
|
<!--Font Size-->
|
||||||
<VerticalStackLayout Spacing="5">
|
<VerticalStackLayout Spacing="5">
|
||||||
<Label Text="Font Size"
|
<Label Text="Font Size"
|
||||||
FontSize="14"
|
FontSize="14"
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
|
|
||||||
<!--Font Family-->
|
<!--Font Family-->
|
||||||
<VerticalStackLayout Spacing="5">
|
<VerticalStackLayout Spacing="5">
|
||||||
<Label Text="Font Family"
|
<Label Text="Font Family"
|
||||||
FontSize="14"
|
FontSize="14"
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
SelectedIndexChanged="OnFontFamilyChanged" />
|
SelectedIndexChanged="OnFontFamilyChanged" />
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
|
|
||||||
<!--Chapters Button-->
|
<!--Chapters Button-->
|
||||||
<Button Text="📑 Chapters"
|
<Button Text="📑 Chapters"
|
||||||
BackgroundColor="#5D4037"
|
BackgroundColor="#5D4037"
|
||||||
TextColor="White"
|
TextColor="White"
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
HeightRequest="45"
|
HeightRequest="45"
|
||||||
Command="{Binding ToggleChapterListCommand}" />
|
Command="{Binding ToggleChapterListCommand}" />
|
||||||
|
|
||||||
<!--Chapter List-->
|
<!--Chapter List-->
|
||||||
<CollectionView ItemsSource="{Binding Chapters}"
|
<CollectionView ItemsSource="{Binding Chapters}"
|
||||||
IsVisible="{Binding IsChapterListVisible}"
|
IsVisible="{Binding IsChapterListVisible}"
|
||||||
MaximumHeightRequest="200"
|
MaximumHeightRequest="200"
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
</CollectionView>
|
</CollectionView>
|
||||||
|
|
||||||
<!--Back Button-->
|
<!--Back Button-->
|
||||||
<Button Text="← Back to Library"
|
<Button Text="← Back to Library"
|
||||||
BackgroundColor="#D32F2F"
|
BackgroundColor="#D32F2F"
|
||||||
TextColor="White"
|
TextColor="White"
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ public partial class ReaderPage : ContentPage
|
|||||||
await _viewModel.InitializeAsync();
|
await _viewModel.InitializeAsync();
|
||||||
System.Diagnostics.Debug.WriteLine("[Reader] ViewModel initialized");
|
System.Diagnostics.Debug.WriteLine("[Reader] ViewModel initialized");
|
||||||
|
|
||||||
StartProgressTimer();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -41,32 +40,11 @@ public partial class ReaderPage : ContentPage
|
|||||||
protected override async void OnDisappearing()
|
protected override async void OnDisappearing()
|
||||||
{
|
{
|
||||||
_isActive = false;
|
_isActive = false;
|
||||||
StopProgressTimer();
|
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
await SaveCurrentProgress();
|
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()
|
private async Task SaveCurrentProgress()
|
||||||
|
|||||||
Reference in New Issue
Block a user