Skip to content

Commit 6006d0e

Browse files
author
たつぞう
committed
feat: Searchable support & Remove login restriction
1 parent f2c9b32 commit 6006d0e

25 files changed

+293
-337
lines changed

EhPanda/App/Defaults.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,13 @@ struct Defaults {
5656
struct URL {
5757
// Domains
5858
static var host: String {
59-
if isTokenMatched {
60-
return galleryType == .ehentai ? ehentai : exhentai
61-
} else {
62-
return durarara
63-
}
59+
galleryType == .ehentai ? ehentai : exhentai
6460
}
6561
static let ehentai = "https://e-hentai.org/"
6662
static let exhentai = "https://exhentai.org/"
6763
static let forum = "https://forums.e-hentai.org/"
6864
static let login = merge([forum + index, loginAct])
6965
static let magnet = "magnet:?xt=urn:btih:"
70-
static let durarara = merge([ehentai, listCompact, nonh, fSearch + "parody:durarara$"])
7166

7267
// Functional Pages
7368
static let tag = "tag/"
@@ -152,21 +147,13 @@ extension Defaults.URL {
152147
)
153148
}
154149
static func frontpageList() -> String {
155-
if isTokenMatched {
156-
return merge([host, listCompact])
157-
} else {
158-
return durarara
159-
}
150+
merge([host, listCompact])
160151
}
161152
static func moreFrontpageList(pageNum: String, lastID: String) -> String {
162153
merge([host, listCompact, page + pageNum, from + lastID])
163154
}
164155
static func popularList() -> String {
165-
if isTokenMatched {
166-
return merge([host + popular, listCompact])
167-
} else {
168-
return merge([ehentai, listCompact, nonh, fSearch + "parody:gintama$"])
169-
}
156+
merge([host + popular, listCompact])
170157
}
171158
static func watchedList() -> String {
172159
merge([host + watched, listCompact])

EhPanda/App/EhPandaApp.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ struct EhPandaApp: App {
1616
init() {
1717
configureWebImage()
1818
clearImageCachesIfNeeded()
19-
UIScrollView.appearance()
20-
.keyboardDismissMode = .onDrag
2119
UITableViewCell.appearance()
2220
.selectedBackgroundView = UIView()
2321
}
@@ -46,8 +44,6 @@ private extension EhPandaApp {
4644

4745
func onOpenURL(_ url: URL) {
4846
switch url.host {
49-
case "token":
50-
setToken(with: url.pathComponents.last)
5147
case "debugMode":
5248
setDebugMode(with: url.pathComponents.last == "on")
5349
default:

EhPanda/App/Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ extension String {
126126
func safeURL() -> URL {
127127
isValidURL
128128
? URL(string: self)!
129-
: URL(string: Defaults.URL.durarara)!
129+
: URL(string: Defaults.URL.ehentai)!
130130
}
131131

132132
var isValidURL: Bool {

EhPanda/App/Tools/Parser.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,14 @@ struct Parser {
399399
}
400400

401401
// MARK: Content
402-
static func parseImagePreContents(_ doc: HTMLDocument, pageCount: Int) throws -> [(Int, URL)] {
402+
static func parseImagePreContents(_ doc: HTMLDocument, previewMode: String, pageCount: Int) throws -> [(Int, URL)] {
403403
copyHTMLIfNeeded(doc.toHTML)
404404
var imageDetailURLs = [(Int, URL)]()
405405

406-
let className = isTokenMatched ? "gdtl" : "gdtm"
407406
guard let gdtNode = doc.at_xpath("//div [@id='gdt']")
408407
else { throw AppError.parseFailed }
409408

410-
for (index, element) in gdtNode.xpath("//div [@class='\(className)']").enumerated() {
411-
409+
for (index, element) in gdtNode.xpath("//div [@class='\(previewMode)']").enumerated() {
412410
guard let imageDetailStr = element.at_xpath("//a")?["href"],
413411
let imageDetailURL = URL(string: imageDetailStr)
414412
else { continue }
@@ -428,6 +426,22 @@ struct Parser {
428426
return MangaContent(tag: tag, url: imageURL)
429427
}
430428

429+
static func parsePreviewMode(_ doc: HTMLDocument) throws -> String {
430+
guard let gdoNode = doc.at_xpath("//div [@id='gdo']"),
431+
let gdo4Node = gdoNode.at_xpath("//div [@id='gdo4']")
432+
else { return "gdtm" }
433+
434+
for link in gdo4Node.xpath("//div") {
435+
if link.text == "Large",
436+
["tha nosel", "ths nosel"]
437+
.contains(link["class"])
438+
{
439+
return "gdtl"
440+
}
441+
}
442+
return "gdtm"
443+
}
444+
431445
// MARK: User
432446
static func parseUserInfo(doc: HTMLDocument) throws -> User {
433447
var displayName: String?

EhPanda/App/Utility.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,10 @@ func getStringWithComma(_ value: Int) -> String? {
252252
// MARK: UserDefaults
253253
let isDebugModeOn = UserDefaults.standard.bool(forKey: "debugModeOn")
254254

255-
let isTokenMatched = UserDefaults.standard.string(forKey: "token") == "r9vG3pcs2mT9MoWj2ZJR"
256-
257255
var pasteboardChangeCount: Int? {
258256
UserDefaults.standard.integer(forKey: "PasteboardChangeCount")
259257
}
260258

261-
func setToken(with token: String?) {
262-
UserDefaults.standard.set(token, forKey: "token")
263-
}
264-
265259
func setDebugMode(with debugModeOn: Bool) {
266260
UserDefaults.standard.set(debugModeOn, forKey: "debugModeOn")
267261
}

EhPanda/App/ja.lproj/Localizable.strings

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
// MARK: AlertView
3333
"Loading..." = "読み込み中...";
34-
"You need to login to use this app." = "ご利用にはログインが必要です";
3534
"Login" = "ログイン";
3635
"Your search didn't match any docs." = "お探しの情報が見つかりませんでした";
3736
"Retry" = "やり直す";

EhPanda/App/zh-Hans.lproj/Localizable.strings

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
// MARK: AlertView
3333
"Loading..." = "加载中...";
34-
"You need to login to use this app." = "请登录以使用这个App";
3534
"Login" = "登录";
3635
"Your search didn't match any docs." = "未能找到你需要的信息";
3736
"Retry" = "重试";

EhPanda/App/zh-Hant.lproj/Localizable.strings

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
// MARK: AlertView
3333
"Loading..." = "載入中...";
34-
"You need to login to use this app." = "你需要登入才能使用這個App";
3534
"Login" = "登入";
3635
"Your search didn't match any docs." = "未能找到你需要的資訊";
3736
"Retry" = "重試";

EhPanda/DataFlow/AppAction.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ enum AppAction {
1616
case initializeUser
1717
case initializeFilter
1818
case initializeSetting
19-
case cleanDetailViewCommentContent
20-
case cleanCommentViewCommentContent
19+
case clearDetailViewCommentContent
20+
case clearCommentViewCommentContent
2121
case saveAspectBox(gid: String, box: [Int: CGFloat])
2222
case saveReadingProgress(gid: String, tag: Int)
2323
case updateDiskImageCacheSize(size: String)
2424
case updateAppIconType(iconType: IconType)
2525
case updateHistoryItems(gid: String)
26+
case updateHistoryKeywords(text: String)
27+
case clearHistoryKeywords
28+
case updateSearchKeyword(text: String)
2629
case updateViewControllersCount
2730
case resetDownloadCommandResponse
2831
case replaceMangaCommentJumpID(gid: String?)

EhPanda/DataFlow/AppState.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ extension AppState {
133133

134134
@FileStorage(directory: .cachesDirectory, fileName: "historyList.json")
135135
var historyItems: [String: Manga]?
136+
@FileStorage(directory: .cachesDirectory, fileName: "historyKeywords.json")
137+
var historyKeywords: [String]?
136138

137139
static func generateBoolDic(_ defaultValue: Bool = false) -> [Int: Bool] {
138140
var tmp = [Int: Bool]()
@@ -193,6 +195,32 @@ extension AppState {
193195
)
194196
}
195197
}
198+
mutating func insertHistoryKeyword(text: String) {
199+
guard !text.isEmpty else { return }
200+
guard var historyKeywords = historyKeywords else {
201+
historyKeywords = [text]
202+
return
203+
}
204+
205+
if let index = historyKeywords.firstIndex(of: text) {
206+
if historyKeywords.last != text {
207+
historyKeywords.remove(at: index)
208+
historyKeywords.append(text)
209+
}
210+
} else {
211+
historyKeywords.append(text)
212+
213+
let overflow = historyKeywords.count - 10
214+
215+
if overflow > 0 {
216+
historyKeywords = Array(
217+
historyKeywords.dropFirst(overflow)
218+
)
219+
}
220+
}
221+
222+
self.historyKeywords = historyKeywords
223+
}
196224
}
197225

198226
// MARK: DetailInfo

0 commit comments

Comments
 (0)