Skip to content

Commit 653cd3d

Browse files
committed
fix: remove hardcoded domain in list script
add: Similars Books in popup UI
1 parent 3424868 commit 653cd3d

File tree

6 files changed

+992
-883
lines changed

6 files changed

+992
-883
lines changed

backend/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fetch(listURL, fetchOptions).then(res => res.text()).then(html => {
5252
}
5353

5454
return {
55-
url: "https://b-ok.global" + $(ele).find('h3 a').attr('href'),
55+
url: $(ele).find('h3 a').attr('href'),
5656
img: imageUrl,
5757
name: $(ele).find('h3').text().trim(),
5858
author: $(ele).find('div.authors').text().trim(),

backend/metadata.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const cheerio = require("cheerio");
2-
const { fetchOptions } = require("./common");
2+
const { domain, fetchOptions } = require("./common");
33
const fetch = require("node-fetch");
44

55
if (process.argv.length < 3) {
66
console.error("No link");
77
return;
88
}
9-
fetch(process.argv[2], fetchOptions).then(a => a.text()).then(html => {
9+
fetch(domain + process.argv[2], fetchOptions).then(a => a.text()).then(html => {
1010
const $ = cheerio.load(html, { _useHtmlParser2: true });
1111

1212
const author = $(`[itemprop="author"]`)
@@ -30,17 +30,23 @@ fetch(process.argv[2], fetchOptions).then(a => a.text()).then(html => {
3030
description = detail;
3131
}
3232

33-
let downloadURL = $(".dlButton").attr("href");
34-
if (downloadURL === "#") {
35-
downloadURL = "";
33+
let dlUrl = $(".dlButton").attr("href");
34+
if (dlUrl === "#") {
35+
dlUrl = "";
3636
}
3737

38+
const similars = $("#bMosaicBox .brick").get().map(a => ({
39+
url: $(a).find("a").attr("href"),
40+
img: $(a).find("img").attr("src"),
41+
}));
42+
3843
process.stdout.write(JSON.stringify({
3944
name: $("h1").text().trim(),
4045
author,
41-
imgFile: $(".details-book-cover").attr("href"),
46+
img: $(".details-book-cover").attr("href"),
4247
description,
43-
downloadURL,
48+
dlUrl,
49+
similars,
4450
}));
4551
})
4652
.catch(err => {

qml/BookPopup.qml

Lines changed: 207 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,208 @@
1-
import QtQuick 2.5
2-
import QtQuick.Controls 2.4
3-
import QtQuick.Layouts 1.0
4-
5-
Item {
6-
property var model;
7-
8-
property Popup popup: Popup {
9-
id: bookPopup
10-
width: 1000
11-
height: 1300
12-
x: (parent.width / 2) - (width / 2)
13-
y: (parent.height / 2) - (height / 2) + 150
14-
closePolicy: Popup.CloseOnPressOutside
15-
dim: true
16-
Overlay.modeless: Rectangle {
17-
color: "#505050f0"
18-
MouseArea {
19-
anchors.fill: parent
20-
}
21-
}
22-
23-
Image {
24-
id: bookImage
25-
fillMode: Image.PreserveAspectFit
26-
smooth: true
27-
source: model ? model.imgFile : ""
28-
width: 400
29-
height: 400 * 1.5
30-
x: parent.width / 2 - 400 / 2
31-
y: -(parent.height / 2 - height / 2)
32-
ProgressBar {
33-
visible: parent.progress < 1.0
34-
value: parent.progress
35-
anchors {
36-
horizontalCenter: parent.horizontalCenter
37-
bottom: parent.bottom
38-
bottomMargin: 80
39-
}
40-
}
41-
}
42-
Text {
43-
id: bookName
44-
text: model ? model.name : ""
45-
width: parent.width - 90
46-
x: 30
47-
anchors.top: bookImage.bottom
48-
anchors.topMargin: 30
49-
font.family:"Maison Neue"
50-
font.styleName: "Bold"
51-
font.pixelSize: 40
52-
wrapMode: Text.Wrap
53-
horizontalAlignment: Text.AlignHCenter
54-
}
55-
56-
Text {
57-
id: bookAuthor
58-
text: model ? model.author : ""
59-
width: bookName.width
60-
x: bookName.x
61-
anchors.top: bookName.bottom
62-
anchors.topMargin: 20
63-
font.family:"Maison Neue"
64-
font.styleName: "Medium"
65-
font.pixelSize: 35
66-
wrapMode: Text.Wrap
67-
horizontalAlignment: Text.AlignHCenter
68-
}
69-
70-
Flickable {
71-
anchors.top: bookAuthor.bottom
72-
anchors.topMargin: 30
73-
anchors.leftMargin: 100
74-
anchors.rightMargin: 100
75-
x: 30
76-
width: bookPopup.width - 80
77-
height: parent.height - bookAuthor.y - bookAuthor.height - 110
78-
contentHeight: bookDesc.height
79-
clip: true
80-
flickableDirection: Flickable.VerticalFlick
81-
boundsBehavior: Flickable.StopAtBounds
82-
83-
Text {
84-
id: bookDesc
85-
textFormat: Text.RichText
86-
text: model ? model.desc : ""
87-
font.family:"EB Garamond"
88-
font.styleName: "Medium"
89-
font.pixelSize: 30
90-
width: parent.width
91-
wrapMode: Text.Wrap
92-
}
93-
}
94-
95-
Rectangle {
96-
width: 300
97-
height: 80
98-
x: parent.width - 260
99-
y: parent.height - 30
100-
color: "black"
101-
Text {
102-
anchors.centerIn: parent
103-
text: !model || !model.dlUrl ? "Unavailable" : model.status
104-
font.family:"Maison Neue"
105-
font.styleName: "Medium"
106-
font.pixelSize: 30
107-
color: "white"
108-
}
109-
MouseArea {
110-
anchors.fill: parent
111-
onClicked: {
112-
if(!model || !model.dlUrl || model.status !== "Download") {
113-
return
114-
}
115-
model.download();
116-
}
117-
}
118-
}
119-
}
1+
import QtQuick 2.5
2+
import QtQuick.Controls 2.4
3+
import QtQuick.Layouts 1.11
4+
5+
Item {
6+
id: popupRoot
7+
property var model;
8+
property bool isBusy;
9+
10+
property Popup popup: Popup {
11+
id: bookPopup
12+
width: 1000
13+
height: 1300
14+
x: (parent.width / 2) - (width / 2)
15+
y: (parent.height / 2) - (height / 2) + 150
16+
closePolicy: Popup.CloseOnPressOutside
17+
dim: true
18+
padding: 40
19+
20+
Overlay.modeless: Rectangle {
21+
color: "#90505050"
22+
MouseArea {
23+
anchors.fill: parent
24+
}
25+
}
26+
27+
onOpened: bar.currentIndex = 0;
28+
29+
contentChildren: [
30+
Image {
31+
id: bookImage
32+
fillMode: Image.PreserveAspectFit
33+
smooth: true
34+
source: model ? model.imgFile : ""
35+
width: 400
36+
height: 400 * 1.5
37+
anchors.horizontalCenter: parent.horizontalCenter
38+
y: -(parent.height / 2 - height / 2)
39+
ProgressBar {
40+
visible: parent.progress < 1.0
41+
value: parent.progress
42+
anchors {
43+
horizontalCenter: parent.horizontalCenter
44+
bottom: parent.bottom
45+
bottomMargin: 80
46+
}
47+
}
48+
},
49+
Text {
50+
id: bookName
51+
text: model ? model.name : ""
52+
anchors {
53+
left: parent.left; right: parent.right
54+
top: bookImage.bottom
55+
topMargin: 30
56+
}
57+
font.family:"Maison Neue"
58+
font.styleName: "Bold"
59+
font.pixelSize: 40
60+
wrapMode: Text.Wrap
61+
horizontalAlignment: Text.AlignHCenter
62+
},
63+
Text {
64+
id: bookAuthor
65+
text: model ? model.author : ""
66+
anchors {
67+
left: parent.left; right: parent.right
68+
top: bookName.bottom
69+
topMargin: 20
70+
}
71+
font.family:"Maison Neue"
72+
font.styleName: "Medium"
73+
font.pixelSize: 35
74+
wrapMode: Text.Wrap
75+
horizontalAlignment: Text.AlignHCenter
76+
},
77+
TabBar {
78+
id: bar
79+
visible: !isBusy
80+
anchors {
81+
left: parent.left; right: parent.right
82+
top: bookAuthor.bottom
83+
topMargin: 30
84+
}
85+
font.pixelSize: 25
86+
TabButton {
87+
contentItem: Label {
88+
text: "Details"
89+
color: bar.currentIndex == 0 ? "black" : "gray"
90+
font.underline: bar.currentIndex == 0
91+
horizontalAlignment: Text.AlignHCenter
92+
}
93+
background: Rectangle {}
94+
}
95+
TabButton {
96+
contentItem: Label {
97+
text: "Similar books"
98+
color: bar.currentIndex == 1 ? "black" : "gray"
99+
font.underline: bar.currentIndex == 1
100+
horizontalAlignment: Text.AlignHCenter
101+
}
102+
background: Rectangle {}
103+
}
104+
},
105+
StackLayout {
106+
id: stack
107+
anchors {
108+
left: parent.left; right: parent.right
109+
top: bar.bottom
110+
topMargin: 30
111+
bottom: parent.bottom
112+
bottomMargin: 30
113+
}
114+
currentIndex: bar.currentIndex
115+
Item {
116+
Flickable {
117+
anchors.fill: parent
118+
contentHeight: bookDesc.height
119+
clip: true
120+
flickableDirection: Flickable.VerticalFlick
121+
boundsBehavior: Flickable.StopAtBounds
122+
123+
Text {
124+
id: bookDesc
125+
textFormat: Text.RichText
126+
text: model ? model.desc : ""
127+
font.family:"EB Garamond"
128+
font.styleName: "Medium"
129+
font.pixelSize: 30
130+
width: parent.width
131+
wrapMode: Text.Wrap
132+
}
133+
}
134+
}
135+
Item {
136+
GridView {
137+
id: recGrid
138+
anchors.fill: parent
139+
boundsBehavior: Flickable.StopAtBounds
140+
cellHeight: stack.height / 2
141+
cellWidth: cellHeight / 1.5
142+
model: popupRoot.model ? popupRoot.model.similars : []
143+
flickableDirection: Flickable.HorizontalFlick
144+
flow: GridView.TopToBottom
145+
clip: true
146+
snapMode: GridView.SnapToRow
147+
flickDeceleration: 0
148+
delegate: Item {
149+
id: itemRoot
150+
width: recGrid.cellWidth
151+
height: recGrid.cellHeight
152+
Image {
153+
id: image
154+
fillMode: Image.PreserveAspectCrop
155+
source: model.modelData.imgFile
156+
anchors.fill: itemRoot
157+
anchors.margins: 10
158+
}
159+
MouseArea {
160+
anchors.fill: itemRoot
161+
onClicked: {
162+
model.modelData.getDetail(popupRoot);
163+
bar.currentIndex = 0;
164+
popupRoot.model = model.modelData;
165+
}
166+
}
167+
}
168+
}
169+
}
170+
},
171+
Image {
172+
z: 1
173+
source: "png/loading"
174+
visible: isBusy
175+
width: 60
176+
height: 60
177+
anchors.centerIn: parent
178+
}
179+
]
180+
181+
Rectangle {
182+
id: download
183+
visible: !isBusy
184+
width: 300
185+
height: 80
186+
x: parent.width - 220
187+
y: parent.height
188+
color: "black"
189+
Text {
190+
anchors.centerIn: parent
191+
text: !model || !model.dlUrl ? "Unavailable" : model.status
192+
font.family:"Maison Neue"
193+
font.styleName: "Medium"
194+
font.pixelSize: 30
195+
color: "white"
196+
}
197+
MouseArea {
198+
anchors.fill: parent
199+
onClicked: {
200+
if(!model || !model.dlUrl || model.status !== "Download") {
201+
return
202+
}
203+
model.download();
204+
}
205+
}
206+
}
207+
}
120208
}

0 commit comments

Comments
 (0)