vomebook commited on
Commit
258eff2
·
verified ·
1 Parent(s): 0023565

Use same-tab reader navigation

Browse files
Files changed (2) hide show
  1. static/app.js +5 -15
  2. static/reader.js +9 -2
static/app.js CHANGED
@@ -623,12 +623,6 @@ function openExternalWindow(url) {
623
  return popup;
624
  }
625
 
626
- function openPendingWindow() {
627
- const popup = window.open("about:blank", "_blank");
628
- if (popup) popup.opener = null;
629
- return popup;
630
- }
631
-
632
  function buildDownloadUrl(filename, link) {
633
  return `/api/download?file=${encodeURIComponent(filename || "file")}&link=${encodeURIComponent(link || "")}`;
634
  }
@@ -2495,30 +2489,26 @@ async function randomBook() {
2495
  }
2496
  }
2497
 
2498
- function openReaderRecord(rec, popup) {
2499
  if (!rec) return false;
2500
  const url = getReaderLink(rec);
2501
  if (!url) return false;
2502
  if (STATE.isMobile) { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); }
2503
- if (popup) popup.location.replace(url);
2504
- else openExternalWindow(url);
2505
  return true;
2506
  }
2507
 
2508
  async function randomTxt() {
2509
- const popup = openPendingWindow();
2510
  try {
2511
  showToast("正在随机打开文章...");
2512
  const url = STATE.repo ? `/api/random-reader?repo=${encodeURIComponent(STATE.repo)}` : "/api/random-reader";
2513
  const resp = await fetch(url);
2514
  if (!resp.ok) throw new Error("HTTP " + resp.status);
2515
  const rec = await resp.json();
2516
- if (!openReaderRecord(rec, popup)) {
2517
- if (popup) popup.close();
2518
  showToast("暂无可读文章");
2519
  }
2520
  } catch (e) {
2521
- if (popup) popup.close();
2522
  console.error(e);
2523
  showToast("获取失败");
2524
  }
@@ -2872,7 +2862,7 @@ function setupResultDelegation() {
2872
  }
2873
  if (action === "read") {
2874
  if (STATE.isMobile) { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); }
2875
- openExternalWindow(actionBtn.dataset.readerUrl);
2876
  return;
2877
  }
2878
  }
@@ -2931,7 +2921,7 @@ function setupResultDelegation() {
2931
  const readUrl = browserItem.dataset.readUrl;
2932
  if (readUrl) {
2933
  if (STATE.isMobile) { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); }
2934
- openExternalWindow(readUrl);
2935
  return;
2936
  }
2937
  const fileLink = browserItem.dataset.link;
 
623
  return popup;
624
  }
625
 
 
 
 
 
 
 
626
  function buildDownloadUrl(filename, link) {
627
  return `/api/download?file=${encodeURIComponent(filename || "file")}&link=${encodeURIComponent(link || "")}`;
628
  }
 
2489
  }
2490
  }
2491
 
2492
+ function openReaderRecord(rec) {
2493
  if (!rec) return false;
2494
  const url = getReaderLink(rec);
2495
  if (!url) return false;
2496
  if (STATE.isMobile) { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); }
2497
+ location.assign(url);
 
2498
  return true;
2499
  }
2500
 
2501
  async function randomTxt() {
 
2502
  try {
2503
  showToast("正在随机打开文章...");
2504
  const url = STATE.repo ? `/api/random-reader?repo=${encodeURIComponent(STATE.repo)}` : "/api/random-reader";
2505
  const resp = await fetch(url);
2506
  if (!resp.ok) throw new Error("HTTP " + resp.status);
2507
  const rec = await resp.json();
2508
+ if (!openReaderRecord(rec)) {
 
2509
  showToast("暂无可读文章");
2510
  }
2511
  } catch (e) {
 
2512
  console.error(e);
2513
  showToast("获取失败");
2514
  }
 
2862
  }
2863
  if (action === "read") {
2864
  if (STATE.isMobile) { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); }
2865
+ location.assign(actionBtn.dataset.readerUrl);
2866
  return;
2867
  }
2868
  }
 
2921
  const readUrl = browserItem.dataset.readUrl;
2922
  if (readUrl) {
2923
  if (STATE.isMobile) { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); }
2924
+ location.assign(readUrl);
2925
  return;
2926
  }
2927
  const fileLink = browserItem.dataset.link;
static/reader.js CHANGED
@@ -55,8 +55,15 @@ document.querySelector(".page-controls").hidden = !["pdf", "epub"].includes(capa
55
  document.querySelector("#title").textContent = title;
56
  document.title = title + " - VoiceOfML Reader";
57
  document.querySelector("#back").addEventListener("click", () => {
58
- if (history.length > 1) history.back();
59
- else { try { const target = new URL(returnUrl); location.assign(target.origin === location.origin ? target.href : "/"); } catch (_) { location.assign("/"); } }
 
 
 
 
 
 
 
60
  });
61
  function setZoom(percent, persist = true) {
62
  const normalized = VoiceOfMLReader.clampNumber(percent, 50, 250, 100);
 
55
  document.querySelector("#title").textContent = title;
56
  document.title = title + " - VoiceOfML Reader";
57
  document.querySelector("#back").addEventListener("click", () => {
58
+ try {
59
+ const target = new URL(returnUrl);
60
+ if (target.origin === location.origin) {
61
+ if (history.length > 1) history.back();
62
+ else location.assign(target.href);
63
+ return;
64
+ }
65
+ } catch (_) {}
66
+ location.assign("/");
67
  });
68
  function setZoom(percent, persist = true) {
69
  const normalized = VoiceOfMLReader.clampNumber(percent, 50, 250, 100);