vomebook commited on
Commit
e7a1a72
·
verified ·
1 Parent(s): 1b92fdf

Clarify random book actions

Browse files
Files changed (2) hide show
  1. static/app.js +7 -6
  2. static/index.html +3 -3
static/app.js CHANGED
@@ -2529,17 +2529,18 @@ function typewriter(el, text, speed = 60) {
2529
 
2530
  async function randomBook() {
2531
  try {
 
2532
  const rec = await API.getRandom(STATE.repo);
2533
  const link = rec ? (rec.Link || rec.link || "") : "";
2534
  if (link) {
2535
  const filename = (rec.File || "file") + (rec.Extension ? '.' + rec.Extension : '');
2536
  downloadFile(filename, link, { skipCheck: true });
2537
  } else {
2538
- showToast("暂无可用记录");
2539
  }
2540
  } catch (e) {
2541
  console.error(e);
2542
- showToast("获取失败");
2543
  }
2544
  }
2545
 
@@ -2557,18 +2558,18 @@ async function randomTxt() {
2557
  const requestId = ++randomReaderRequestId;
2558
  const returnUrl = location.href;
2559
  try {
2560
- showToast("正在随机打开文章...");
2561
  const url = STATE.repo ? `/api/random-reader?repo=${encodeURIComponent(STATE.repo)}` : "/api/random-reader";
2562
  const resp = await fetch(url);
2563
  if (!resp.ok) throw new Error("HTTP " + resp.status);
2564
  const rec = await resp.json();
2565
  if (requestId !== randomReaderRequestId || location.href !== returnUrl) return;
2566
  if (!openReaderRecord(rec, returnUrl)) {
2567
- showToast("暂无可读文章");
2568
  }
2569
  } catch (e) {
2570
  console.error(e);
2571
- showToast("获取失败");
2572
  }
2573
  }
2574
  let toastTimer;
@@ -3150,7 +3151,7 @@ async function init() {
3150
  DOM.overlay.addEventListener("click", () => { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); syncStateToURL(true); });
3151
  DOM.randomBookBtn.addEventListener('click', randomBook);
3152
  if (DOM.randomTxtBtn) DOM.randomTxtBtn.addEventListener('click', randomTxt);
3153
- DOM.emptyRandomBtn.addEventListener('click', randomBook);
3154
  let sizeTimer;
3155
  const sizeInputToBytes = (input, unitSelect) => {
3156
  var val = parseFloat(input.value);
 
2529
 
2530
  async function randomBook() {
2531
  try {
2532
+ showToast("正在随机下载书籍...");
2533
  const rec = await API.getRandom(STATE.repo);
2534
  const link = rec ? (rec.Link || rec.link || "") : "";
2535
  if (link) {
2536
  const filename = (rec.File || "file") + (rec.Extension ? '.' + rec.Extension : '');
2537
  downloadFile(filename, link, { skipCheck: true });
2538
  } else {
2539
+ showToast("暂无可下载书籍");
2540
  }
2541
  } catch (e) {
2542
  console.error(e);
2543
+ showToast("随机下载失败");
2544
  }
2545
  }
2546
 
 
2558
  const requestId = ++randomReaderRequestId;
2559
  const returnUrl = location.href;
2560
  try {
2561
+ showToast("正在随机打开书籍...");
2562
  const url = STATE.repo ? `/api/random-reader?repo=${encodeURIComponent(STATE.repo)}` : "/api/random-reader";
2563
  const resp = await fetch(url);
2564
  if (!resp.ok) throw new Error("HTTP " + resp.status);
2565
  const rec = await resp.json();
2566
  if (requestId !== randomReaderRequestId || location.href !== returnUrl) return;
2567
  if (!openReaderRecord(rec, returnUrl)) {
2568
+ showToast("暂无可读书籍");
2569
  }
2570
  } catch (e) {
2571
  console.error(e);
2572
+ showToast("随机打开失败");
2573
  }
2574
  }
2575
  let toastTimer;
 
3151
  DOM.overlay.addEventListener("click", () => { STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false; updateSidebarVisibility(); syncStateToURL(true); });
3152
  DOM.randomBookBtn.addEventListener('click', randomBook);
3153
  if (DOM.randomTxtBtn) DOM.randomTxtBtn.addEventListener('click', randomTxt);
3154
+ DOM.emptyRandomBtn.addEventListener('click', randomTxt);
3155
  let sizeTimer;
3156
  const sizeInputToBytes = (input, unitSelect) => {
3157
  var val = parseFloat(input.value);
static/index.html CHANGED
@@ -240,16 +240,16 @@
240
 
241
  <footer id="footer" class="footer">
242
  <div id="hitokoto" class="hitokoto"></div>
243
- <button id="random-txt-btn" class="random-txt-btn" title="随机来一篇">
244
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
245
  <path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
246
  <polyline points="14 2 14 8 20 8"/>
247
  <line x1="8" y1="13" x2="16" y2="13"/>
248
  <line x1="8" y1="17" x2="14" y2="17"/>
249
  </svg>
250
- 随机来一篇
251
  </button>
252
- <button id="random-book-btn" class="random-book-btn" title="随机来本书">
253
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
254
  <path d="M2 3h6a4 4 0 014 4v14a3 3 0 00-3-3H2z"/>
255
  <path d="M22 3h-6a4 4 0 00-4 4v14a3 3 0 013-3h7z"/>
 
240
 
241
  <footer id="footer" class="footer">
242
  <div id="hitokoto" class="hitokoto"></div>
243
+ <button id="random-book-btn" class="random-txt-btn" title="随机下本书">
244
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
245
  <path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
246
  <polyline points="14 2 14 8 20 8"/>
247
  <line x1="8" y1="13" x2="16" y2="13"/>
248
  <line x1="8" y1="17" x2="14" y2="17"/>
249
  </svg>
250
+ 随机下本书
251
  </button>
252
+ <button id="random-txt-btn" class="random-book-btn" title="随机来本书">
253
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
254
  <path d="M2 3h6a4 4 0 014 4v14a3 3 0 00-3-3H2z"/>
255
  <path d="M22 3h-6a4 4 0 00-4 4v14a3 3 0 013-3h7z"/>