Happymh: add setting to override user agent (#15861)
This commit is contained in:
parent
aa9ac35a98
commit
5c4ee8e887
@ -5,7 +5,7 @@ ext {
|
|||||||
extName = 'Happymh'
|
extName = 'Happymh'
|
||||||
pkgNameSuffix = 'zh.happymh'
|
pkgNameSuffix = 'zh.happymh'
|
||||||
extClass = '.Happymh'
|
extClass = '.Happymh'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package eu.kanade.tachiyomi.extension.zh.happymh
|
package eu.kanade.tachiyomi.extension.zh.happymh
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.network.POST
|
import eu.kanade.tachiyomi.network.POST
|
||||||
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
@ -16,12 +20,15 @@ import kotlinx.serialization.json.jsonArray
|
|||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
|
import okhttp3.Headers
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class Happymh : HttpSource() {
|
class Happymh : HttpSource(), ConfigurableSource {
|
||||||
override val name: String = "嗨皮漫画"
|
override val name: String = "嗨皮漫画"
|
||||||
override val lang: String = "zh"
|
override val lang: String = "zh"
|
||||||
override val supportsLatest: Boolean = true
|
override val supportsLatest: Boolean = true
|
||||||
@ -29,6 +36,17 @@ class Happymh : HttpSource() {
|
|||||||
override val client: OkHttpClient = network.cloudflareClient
|
override val client: OkHttpClient = network.cloudflareClient
|
||||||
private val json: Json by injectLazy()
|
private val json: Json by injectLazy()
|
||||||
|
|
||||||
|
override fun headersBuilder(): Headers.Builder {
|
||||||
|
val builder = super.headersBuilder()
|
||||||
|
val preferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
|
val userAgent = preferences.getString(USER_AGENT_PREF, "")!!
|
||||||
|
return if (userAgent.isNotBlank()) {
|
||||||
|
builder.set("User-Agent", userAgent)
|
||||||
|
} else {
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Popular
|
// Popular
|
||||||
|
|
||||||
// Requires login, otherwise result is the same as latest updates
|
// Requires login, otherwise result is the same as latest updates
|
||||||
@ -119,4 +137,16 @@ class Happymh : HttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun imageUrlParse(response: Response): String = throw Exception("Not Used")
|
override fun imageUrlParse(response: Response): String = throw Exception("Not Used")
|
||||||
|
|
||||||
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
|
EditTextPreference(screen.context).apply {
|
||||||
|
key = USER_AGENT_PREF
|
||||||
|
title = "User Agent"
|
||||||
|
summary = "留空则使用应用设置中的默认 User Agent"
|
||||||
|
}.let(screen::addPreference)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val USER_AGENT_PREF = "userAgent"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user