Shinigami: add baseUrl override (#4152)

This commit is contained in:
inipew 2024-07-22 14:26:41 +07:00 committed by Draff
parent 0cda850385
commit e07b44263d
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 51 additions and 3 deletions

View File

@ -2,8 +2,8 @@ ext {
extName = 'Shinigami'
extClass = '.Shinigami'
themePkg = 'madara'
baseUrl = 'https://shinigami02.com'
overrideVersionCode = 24
baseUrl = 'https://shinigami03.com'
overrideVersionCode = 25
isNsfw = false
}

View File

@ -1,21 +1,64 @@
package eu.kanade.tachiyomi.extension.id.shinigami
import android.app.Application
import android.content.SharedPreferences
import android.util.Base64
import android.widget.Toast
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES
import eu.kanade.tachiyomi.lib.synchrony.Deobfuscator
import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class Shinigami : Madara("Shinigami", "https://shinigami02.com", "id") {
class Shinigami : Madara("Shinigami", "https://shinigami03.com", "id"), ConfigurableSource {
// moved from Reaper Scans (id) to Shinigami (id)
override val id = 3411809758861089969
override val baseUrl by lazy { getPrefBaseUrl() }
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply {
key = BASE_URL_PREF
title = BASE_URL_PREF_TITLE
summary = BASE_URL_PREF_SUMMARY
this.setDefaultValue(super.baseUrl)
dialogTitle = BASE_URL_PREF_TITLE
dialogMessage = "Default: ${super.baseUrl}"
setOnPreferenceChangeListener { _, _ ->
Toast.makeText(screen.context, RESTART_APP, Toast.LENGTH_LONG).show()
true
}
}
screen.addPreference(baseUrlPref)
}
private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, super.baseUrl)!!
init {
preferences.getString(DEFAULT_BASE_URL_PREF, null).let { prefDefaultBaseUrl ->
if (prefDefaultBaseUrl != super.baseUrl) {
preferences.edit()
.putString(BASE_URL_PREF, super.baseUrl)
.putString(DEFAULT_BASE_URL_PREF, super.baseUrl)
.apply()
}
}
}
override val useLoadMoreRequest = LoadMoreStrategy.Never
override val useNewChapterEndpoint = false
@ -101,5 +144,10 @@ class Shinigami : Madara("Shinigami", "https://shinigami02.com", "id") {
private val CHAPTER_DATA_REGEX by lazy { Regex("""var chapter_data\s*=\s*'(.*?)'""") }
private val POST_ID_REGEX by lazy { Regex("""var post_id\s*=\s*'(.*?)'""") }
private val OTHER_ID_REGEX by lazy { Regex("""var (\w+)_id\s*=\s*'(.*?)'""") }
private const val RESTART_APP = "Untuk menerapkan perubahan, restart aplikasi."
private const val BASE_URL_PREF_TITLE = "Ubah Domain"
private const val BASE_URL_PREF = "overrideBaseUrl"
private const val BASE_URL_PREF_SUMMARY = "Untuk penggunaan sementara. Memperbarui aplikasi akan menghapus pengaturan"
private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
}
}