CatharsisWorld Add Url Editor (#10969)
* CatharsisWorld Add Url Editor * Apply suggestion from @AwkwardPeak7 Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> * Apply suggestion from @AwkwardPeak7 chang Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> * Change sugi * cathasis over ride --------- Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com>
This commit is contained in:
parent
4e8f7db34f
commit
b38f8bd0f5
@ -3,7 +3,7 @@ ext {
|
|||||||
extClass = '.CatharsisWorld'
|
extClass = '.CatharsisWorld'
|
||||||
themePkg = 'madara'
|
themePkg = 'madara'
|
||||||
baseUrl = 'https://catharsisworld.dig-it.info'
|
baseUrl = 'https://catharsisworld.dig-it.info'
|
||||||
overrideVersionCode = 7
|
overrideVersionCode = 8
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,26 +1,50 @@
|
|||||||
package eu.kanade.tachiyomi.extension.es.catharsisworld
|
package eu.kanade.tachiyomi.extension.es.catharsisworld
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||||
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||||
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
import keiyoushi.utils.getPreferences
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
|
|
||||||
class CatharsisWorld : Madara(
|
class CatharsisWorld :
|
||||||
"Catharsis World",
|
Madara(
|
||||||
"https://catharsisworld.dig-it.info",
|
"Catharsis World",
|
||||||
"es",
|
"https://catharsisworld.dig-it.info",
|
||||||
) {
|
"es",
|
||||||
|
),
|
||||||
|
ConfigurableSource {
|
||||||
|
|
||||||
|
override val baseUrl get() = preferences.prefBaseUrl
|
||||||
|
|
||||||
override val versionId = 2
|
override val versionId = 2
|
||||||
|
|
||||||
override val mangaSubString = "serie"
|
override val mangaSubString = "serie"
|
||||||
|
|
||||||
override val useLoadMoreRequest = LoadMoreStrategy.Always
|
override val useLoadMoreRequest = LoadMoreStrategy.Always
|
||||||
|
|
||||||
override val client = super.client.newBuilder()
|
override val client by lazy {
|
||||||
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1)
|
super.client.newBuilder()
|
||||||
.build()
|
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val preferences = getPreferences {
|
||||||
|
this.getString(DEFAULT_BASE_URL_PREF, null).let { domain ->
|
||||||
|
if (domain != super.baseUrl) {
|
||||||
|
this.edit()
|
||||||
|
.putString(BASE_URL_PREF, super.baseUrl)
|
||||||
|
.putString(DEFAULT_BASE_URL_PREF, super.baseUrl)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun popularMangaSelector() = "div.latest-poster"
|
override fun popularMangaSelector() = "div.latest-poster"
|
||||||
|
|
||||||
@ -57,4 +81,43 @@ class CatharsisWorld : Madara(
|
|||||||
private fun Element.imageFromStyle(): String {
|
private fun Element.imageFromStyle(): String {
|
||||||
return this.attr("style").substringAfter("url(").substringBefore(")")
|
return this.attr("style").substringAfter("url(").substringBefore(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
|
EditTextPreference(screen.context).apply {
|
||||||
|
key = BASE_URL_PREF
|
||||||
|
title = "Editar URL de la fuente"
|
||||||
|
summary = "Para uso temporal, si la extensión se actualiza se perderá el cambio."
|
||||||
|
dialogTitle = "Editar URL de la fuente"
|
||||||
|
dialogMessage = "URL por defecto:\n${super.baseUrl}"
|
||||||
|
setDefaultValue(super.baseUrl)
|
||||||
|
setOnPreferenceChangeListener { _, newVal ->
|
||||||
|
val url = newVal as String
|
||||||
|
try {
|
||||||
|
val httpurl = url.toHttpUrl()
|
||||||
|
preferences.prefBaseUrl = "https://${httpurl.host}"
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
Toast.makeText(screen.context, "Invalid Url", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}.also { screen.addPreference(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var _cachedBaseUrl: String? = null
|
||||||
|
private var SharedPreferences.prefBaseUrl: String
|
||||||
|
get() {
|
||||||
|
if (_cachedBaseUrl == null) {
|
||||||
|
_cachedBaseUrl = getString(BASE_URL_PREF, super.baseUrl)!!
|
||||||
|
}
|
||||||
|
return _cachedBaseUrl!!
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
_cachedBaseUrl = value
|
||||||
|
edit().putString(BASE_URL_PREF, value).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val BASE_URL_PREF = "overrideBaseUrl"
|
||||||
|
private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user