diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 991da0859..d3548c9f1 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -19,6 +19,8 @@ object AppConst { const val channelIdReadAloud = "channel_read_aloud" const val channelIdWeb = "channel_web" + const val UA_NAME = "User-Agent" + val userAgent: String by lazy { "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36" } diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 3236d5796..c09a467dc 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -69,7 +69,7 @@ data class BookSource( @Throws(Exception::class) fun getHeaderMap(): Map { val headerMap = HashMap() - headerMap["User-Agent"] = App.INSTANCE.getPrefString("user_agent") ?: userAgent + headerMap[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: userAgent header?.let { val header1 = when { it.startsWith("@js:", true) -> diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index fd364363c..4cd8a3dc5 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -9,6 +9,7 @@ import android.os.Message import android.text.TextUtils import android.webkit.* import io.legado.app.App +import io.legado.app.constant.AppConst import org.apache.commons.text.StringEscapeUtils import java.lang.ref.WeakReference @@ -101,7 +102,7 @@ class AjaxWebView { var javaScript: String? = null val userAgent: String? - get() = this.headerMap?.get("User-Agent") + get() = this.headerMap?.get(AppConst.UA_NAME) val isSniff: Boolean get() = !TextUtils.isEmpty(sourceRegex) diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index 7418ea6c6..343a54087 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -1,5 +1,6 @@ package io.legado.app.help.storage +import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.rule.* import io.legado.app.help.storage.Restore.jsonPath @@ -131,7 +132,7 @@ object OldRule { private fun uaToHeader(ua: String?): String? { if (ua.isNullOrEmpty()) return null - val map = mapOf(Pair("User-Agent", ua)) + val map = mapOf(Pair(AppConst.UA_NAME, ua)) return GSON.toJson(map) }