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:
Genzales6 2025-10-13 08:05:08 -05:00 committed by Draff
parent 4e8f7db34f
commit b38f8bd0f5
Signed by: Draff
GPG Key ID: E8A89F3211677653
2 changed files with 72 additions and 9 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.CatharsisWorld'
themePkg = 'madara'
baseUrl = 'https://catharsisworld.dig-it.info'
overrideVersionCode = 7
overrideVersionCode = 8
isNsfw = true
}

View File

@ -1,26 +1,50 @@
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.network.interceptor.rateLimitHost
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import keiyoushi.utils.getPreferences
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.jsoup.nodes.Element
class CatharsisWorld : Madara(
"Catharsis World",
"https://catharsisworld.dig-it.info",
"es",
) {
class CatharsisWorld :
Madara(
"Catharsis World",
"https://catharsisworld.dig-it.info",
"es",
),
ConfigurableSource {
override val baseUrl get() = preferences.prefBaseUrl
override val versionId = 2
override val mangaSubString = "serie"
override val useLoadMoreRequest = LoadMoreStrategy.Always
override val client = super.client.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1)
.build()
override val client by lazy {
super.client.newBuilder()
.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"
@ -57,4 +81,43 @@ class CatharsisWorld : Madara(
private fun Element.imageFromStyle(): String {
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"
}
}