From 6d7d8f065953d9aa32f3a35bf16643a6e2e00d74 Mon Sep 17 00:00:00 2001 From: Celeter Date: Sun, 8 Mar 2020 12:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E7=BD=AE=E7=9A=84web=E7=9C=8B?= =?UTF-8?q?=E4=B9=A6=E5=8B=89=E5=BC=BA=E8=83=BD=E7=94=A8=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/web/bookshelf.html | 50 ++++++++++++++------------ app/src/main/assets/web/bookshelf.js | 36 +++++++++++-------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/app/src/main/assets/web/bookshelf.html b/app/src/main/assets/web/bookshelf.html index 485622373..d5a37ae51 100644 --- a/app/src/main/assets/web/bookshelf.html +++ b/app/src/main/assets/web/bookshelf.html @@ -1,32 +1,36 @@  + - - 阅读书架 - + + 阅读3.0书架 + + + - - - - + + + + -
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
- + + \ No newline at end of file diff --git a/app/src/main/assets/web/bookshelf.js b/app/src/main/assets/web/bookshelf.js index c182f49fa..19909b0f5 100644 --- a/app/src/main/assets/web/bookshelf.js +++ b/app/src/main/assets/web/bookshelf.js @@ -1,7 +1,7 @@ var $ = document.querySelector.bind(document) , $$ = document.querySelectorAll.bind(document) , $c = document.createElement.bind(document) - , randomImg = "http://acg.bakayun.cn/randbg.php?t=dfzh" + , randomImg = "http://api.mtyqx.cn/api/random.php" , randomImg2 = "http://img.xjh.me/random_img.php" , books ; @@ -13,13 +13,13 @@ var formatTime = value => { }; var apiMap = { - getBookshelf: "/getBookshelf", - getChapterList: "/getChapterList", - getBookContent: "/getBookContent", - saveBook: "/saveBook" + "getBookshelf": "/getBookshelf", + "getChapterList": "/getChapterList", + "getBookContent": "/getBookContent", + "saveBook": "/saveBook" }; -var apiAddress = (apiName, url) => { +var apiAddress = (apiName, url, index) => { let address = $('#address').value || window.location.host; if (!(/^http|^\/\//).test(address)) { address = "//" + address; @@ -28,6 +28,9 @@ var apiAddress = (apiName, url) => { address += ":1122"; } localStorage.setItem('address', address); + if (apiName == "getBookContent") { + return address + apiMap[apiName] + (url ? "?url=" + encodeURIComponent(url) : "") + "&index=" + index; + } return address + apiMap[apiName] + (url ? "?url=" + encodeURIComponent(url) : ""); }; @@ -41,12 +44,12 @@ var init = () => { alert(getBookshelf.errorMsg); return; } - books = data.data.sort((book1, book2) => book1.serialNumber - book2.serialNumber); - books.forEach(book => { + books = data.data; + books.forEach((book, i) => { let bookDiv = $c("div"); let img = $c("img"); img.src = book.coverUrl || randomImg; - img.setAttribute("data-series-num", book.serialNumber); + img.setAttribute("data-series-num", i); bookDiv.appendChild(img); bookDiv.innerHTML += ` @@ -85,9 +88,10 @@ var init = () => { data.data.forEach(chapter => { let ch = $c("button"); - ch.setAttribute("data-url", chapter.durChapterUrl); - ch.setAttribute("title", chapter.durChapterName); - ch.innerHTML = chapter.durChapterName.length > 15 ? chapter.durChapterName.substring(0, 14) + "..." : chapter.durChapterName; + ch.setAttribute("data-url", chapter.bookUrl); + ch.setAttribute("data-index", chapter.index); + ch.setAttribute("title", chapter.title); + ch.innerHTML = chapter.title.length > 15 ? chapter.title.substring(0, 14) + "..." : chapter.title; $("#chapter").appendChild(ch); }); $('#chapter').scrollTop = 0; @@ -129,12 +133,16 @@ $('#showchapter').addEventListener("click", () => { $('#chapter').addEventListener("click", (e) => { if (e.target.tagName === "BUTTON") { var url = e.target.getAttribute("data-url"); + var index = e.target.getAttribute("data-index"); var name = e.target.getAttribute("title"); if (!url) { - alert("未取得章节地址"); + alert("未取得书籍地址"); + } + if (!index && (0 != index)) { + alert("未取得章节索引"); } $("#content").innerHTML = "

" + name + " 加载中...

"; - fetch(apiAddress("getBookContent", url), { mode: "cors" }) + fetch(apiAddress("getBookContent", url, index), { mode: "cors" }) .then(res => res.json()) .then(data => { if (!data.isSuccess) {
书名:${book.name}