mirror of
https://github.com/keiyoushi/extensions-source.git
synced 2024-11-21 18:02:42 +01:00
Hentaiteca: Add random UA (#3819)
* Add random UA * Fix WebView UA * Add useLoadMoreRequest * Fix date format * Remove hardcode UA
This commit is contained in:
parent
a4f0ee776c
commit
507fd8055d
@ -3,8 +3,12 @@ ext {
|
||||
extClass = '.HentaiTeca'
|
||||
themePkg = 'madara'
|
||||
baseUrl = 'https://hentaiteca.net'
|
||||
overrideVersionCode = 1
|
||||
overrideVersionCode = 2
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
||||
dependencies {
|
||||
implementation project(':lib:randomua')
|
||||
}
|
||||
|
@ -1,20 +1,61 @@
|
||||
package eu.kanade.tachiyomi.extension.pt.hentaiteca
|
||||
|
||||
import android.app.Application
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.lib.randomua.addRandomUAPreferenceToScreen
|
||||
import eu.kanade.tachiyomi.lib.randomua.getPrefCustomUA
|
||||
import eu.kanade.tachiyomi.lib.randomua.getPrefUAType
|
||||
import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent
|
||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
import okhttp3.Headers
|
||||
import okhttp3.OkHttpClient
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class HentaiTeca : Madara(
|
||||
"Hentai Teca",
|
||||
"https://hentaiteca.net",
|
||||
"pt-BR",
|
||||
SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")),
|
||||
) {
|
||||
class HentaiTeca :
|
||||
Madara(
|
||||
"Hentai Teca",
|
||||
"https://hentaiteca.net",
|
||||
"pt-BR",
|
||||
SimpleDateFormat("dd/MM/yyyy", Locale("pt", "BR")),
|
||||
),
|
||||
ConfigurableSource {
|
||||
|
||||
private val preferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
|
||||
override val client: OkHttpClient = super.client.newBuilder()
|
||||
.setRandomUserAgent(
|
||||
preferences.getPrefUAType(),
|
||||
preferences.getPrefCustomUA(),
|
||||
)
|
||||
.rateLimit(1, 2, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
override fun headersBuilder(): Headers.Builder = super.headersBuilder()
|
||||
.addCustomUA()
|
||||
|
||||
override val useLoadMoreRequest = LoadMoreStrategy.Never
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
addRandomUAPreferenceToScreen(screen)
|
||||
}
|
||||
|
||||
/*
|
||||
* Using Custom UA also in WebView
|
||||
* */
|
||||
private fun Headers.Builder.addCustomUA(): Headers.Builder {
|
||||
preferences.getPrefCustomUA()
|
||||
.takeIf { !it.isNullOrBlank() }
|
||||
?.let { set(UA_KEY, it) }
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val UA_KEY = "User-Agent"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user