edit
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user