copymanga: add a preference to change image cdn (#7384)
* copymanga: add a preference to change image cdn Closed #6649 * copymanga: fix typo
This commit is contained in:
parent
e8b6a225aa
commit
7cc0764041
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'CopyManga'
|
extName = 'CopyManga'
|
||||||
pkgNameSuffix = 'zh.copymanga'
|
pkgNameSuffix = 'zh.copymanga'
|
||||||
extClass = '.CopyManga'
|
extClass = '.CopyManga'
|
||||||
extVersionCode = 8
|
extVersionCode = 9
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -41,6 +41,10 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
override val supportsLatest = true
|
override val supportsLatest = true
|
||||||
private val popularLatestPageSize = 50 // default
|
private val popularLatestPageSize = 50 // default
|
||||||
private val searchPageSize = 12 // default
|
private val searchPageSize = 12 // default
|
||||||
|
|
||||||
|
val replaceWith277 = Regex("mirror277")
|
||||||
|
val replaceWith77 = Regex("mirror77")
|
||||||
|
|
||||||
private val preferences: SharedPreferences by lazy {
|
private val preferences: SharedPreferences by lazy {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
}
|
}
|
||||||
|
@ -70,9 +74,9 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
|
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
// when perform html search, sort by popular
|
// when perform html search, sort by popular
|
||||||
var apiUrlString = "$baseUrl/api/kb/web/search/comics?limit=$searchPageSize&offset=${(page - 1) * searchPageSize}&platform=2&q=$query&q_type="
|
val apiUrlString = "$baseUrl/api/kb/web/search/comics?limit=$searchPageSize&offset=${(page - 1) * searchPageSize}&platform=2&q=$query&q_type="
|
||||||
var htmlUrlString = "$baseUrl/comics?offset=${(page - 1) * popularLatestPageSize}&limit=$popularLatestPageSize"
|
val htmlUrlString = "$baseUrl/comics?offset=${(page - 1) * popularLatestPageSize}&limit=$popularLatestPageSize"
|
||||||
var requestUrlString: String
|
val requestUrlString: String
|
||||||
|
|
||||||
val params = filters.map {
|
val params = filters.map {
|
||||||
if (it is MangaFilter) {
|
if (it is MangaFilter) {
|
||||||
|
@ -107,7 +111,12 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
}
|
}
|
||||||
val manga = SManga.create().apply {
|
val manga = SManga.create().apply {
|
||||||
title = _title
|
title = _title
|
||||||
thumbnail_url = document.select("div.comicParticulars-title-left img").first().attr("data-src")
|
var picture = document.select("div.comicParticulars-title-left img").first().attr("data-src")
|
||||||
|
if (!preferences.getBoolean(change_cdn_tomainland, false)) {
|
||||||
|
picture = replaceWith277.replace(picture, "mirror2")
|
||||||
|
picture = replaceWith77.replace(picture, "mirror")
|
||||||
|
}
|
||||||
|
thumbnail_url = picture
|
||||||
description = document.select("div.comicParticulars-synopsis p.intro").first().text().trim()
|
description = document.select("div.comicParticulars-synopsis p.intro").first().text().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +196,12 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
|
|
||||||
val ret = ArrayList<Page>(pageArray.length())
|
val ret = ArrayList<Page>(pageArray.length())
|
||||||
for (i in 0 until pageArray.length()) {
|
for (i in 0 until pageArray.length()) {
|
||||||
ret.add(Page(i, "", pageArray.getJSONObject(i).getString("url")))
|
var page = pageArray.getJSONObject(i).getString("url")
|
||||||
|
if (!preferences.getBoolean(change_cdn_tomainland, false)) {
|
||||||
|
page = replaceWith277.replace(page, "mirror2")
|
||||||
|
page = replaceWith77.replace(page, "mirror")
|
||||||
|
}
|
||||||
|
ret.add(Page(i, "", page))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -324,7 +338,12 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
ret.add(
|
ret.add(
|
||||||
SManga.create().apply {
|
SManga.create().apply {
|
||||||
title = _title
|
title = _title
|
||||||
thumbnail_url = obj.getString("cover")
|
var picture = obj.getString("cover")
|
||||||
|
if (!preferences.getBoolean(change_cdn_tomainland, false)) {
|
||||||
|
picture = replaceWith277.replace(picture, "mirror2")
|
||||||
|
picture = replaceWith77.replace(picture, "mirror")
|
||||||
|
}
|
||||||
|
thumbnail_url = picture
|
||||||
author = Array<String?>(authorArray.length()) { i -> authorArray.getJSONObject(i).getString("name") }.joinToString(", ")
|
author = Array<String?>(authorArray.length()) { i -> authorArray.getJSONObject(i).getString("name") }.joinToString(", ")
|
||||||
status = SManga.UNKNOWN
|
status = SManga.UNKNOWN
|
||||||
url = "/comic/${obj.getString("path_word")}"
|
url = "/comic/${obj.getString("path_word")}"
|
||||||
|
@ -338,7 +357,12 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
private fun mangaFromPage(element: Element): SManga {
|
private fun mangaFromPage(element: Element): SManga {
|
||||||
val manga = SManga.create()
|
val manga = SManga.create()
|
||||||
element.select("div.exemptComicItem-img > a > img").first().let {
|
element.select("div.exemptComicItem-img > a > img").first().let {
|
||||||
manga.thumbnail_url = it.attr("data-src")
|
var picture = it.attr("data-src")
|
||||||
|
if (!preferences.getBoolean(change_cdn_tomainland, false)) {
|
||||||
|
picture = replaceWith277.replace(picture, "mirror2")
|
||||||
|
picture = replaceWith77.replace(picture, "mirror")
|
||||||
|
}
|
||||||
|
manga.thumbnail_url = picture
|
||||||
}
|
}
|
||||||
element.select("div.exemptComicItem-txt > a").first().let {
|
element.select("div.exemptComicItem-txt > a").first().let {
|
||||||
manga.setUrlWithoutDomain(it.attr("href"))
|
manga.setUrlWithoutDomain(it.attr("href"))
|
||||||
|
@ -410,10 +434,27 @@ class CopyManga : ConfigurableSource, HttpSource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val cdnPreference = androidx.preference.CheckBoxPreference(screen.context).apply {
|
||||||
|
key = change_cdn_tomainland
|
||||||
|
title = "转换图片CDN为国内"
|
||||||
|
summary = "加载图片使用国内CDN,可以使用代理的情况下请不要打开此选项"
|
||||||
|
|
||||||
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
try {
|
||||||
|
val setting = preferences.edit().putBoolean(change_cdn_tomainland, newValue as Boolean).commit()
|
||||||
|
setting
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
screen.addPreference(zhPreference)
|
screen.addPreference(zhPreference)
|
||||||
|
screen.addPreference(cdnPreference)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SHOW_Simplified_Chinese_TITLE_PREF = "showSCTitle"
|
private const val SHOW_Simplified_Chinese_TITLE_PREF = "showSCTitle"
|
||||||
|
private const val change_cdn_tomainland = "changeCDN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue