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; 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) {

View File

@@ -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()