mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-27 19:47:51 +02:00
Fix universal captcha detection
This commit is contained in:
@ -27,7 +27,7 @@ private fun verifyComplete(url: String): Boolean {
|
||||
fun OkHttpClient.Builder.attachMangaDexLogin() =
|
||||
addInterceptor { chain ->
|
||||
val response = chain.proceed(chain.request())
|
||||
if(response.request().url().host() == "mangadex.org") {
|
||||
if(response.request().url().host() == MANGADEX_DOMAIN) {
|
||||
response.interceptAsHtml { doc ->
|
||||
if (doc.title().trim().equals("Login - MangaDex", true)) {
|
||||
BrowserActionActivity.launchAction(
|
||||
@ -36,7 +36,7 @@ fun OkHttpClient.Builder.attachMangaDexLogin() =
|
||||
HIDE_SCRIPT,
|
||||
"https://mangadex.org/login",
|
||||
"Login",
|
||||
(Injekt.get<SourceManager>().get(2499283573021220255) as? HttpSource)?.headers?.toMultimap()?.mapValues {
|
||||
(Injekt.get<SourceManager>().get(MANGADEX_SOURCE_ID) as? HttpSource)?.headers?.toMultimap()?.mapValues {
|
||||
it.value.joinToString(",")
|
||||
} ?: emptyMap()
|
||||
)
|
||||
@ -44,3 +44,6 @@ fun OkHttpClient.Builder.attachMangaDexLogin() =
|
||||
}
|
||||
} else response
|
||||
}
|
||||
|
||||
const val MANGADEX_SOURCE_ID = 2499283573021220255
|
||||
const val MANGADEX_DOMAIN = "mangadex.org"
|
||||
|
28
app/src/main/java/exh/patch/UniversalCaptchaDetection.kt
Normal file
28
app/src/main/java/exh/patch/UniversalCaptchaDetection.kt
Normal file
@ -0,0 +1,28 @@
|
||||
package exh.patch
|
||||
|
||||
import android.content.Context
|
||||
import exh.ui.captcha.BrowserActionActivity
|
||||
import exh.util.interceptAsHtml
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
fun OkHttpClient.Builder.detectCaptchas(context: Context, sourceId: Long, domains: List<String>? = null): OkHttpClient.Builder {
|
||||
return addInterceptor { chain ->
|
||||
// Automatic captcha detection
|
||||
val response = chain.proceed(chain.request())
|
||||
if(!response.isSuccessful) {
|
||||
if(domains != null && response.request().url().host() !in domains)
|
||||
return@addInterceptor response
|
||||
|
||||
response.interceptAsHtml { doc ->
|
||||
if (doc.getElementsByClass("g-recaptcha").isNotEmpty()) {
|
||||
// Found it, allow the user to solve this thing
|
||||
BrowserActionActivity.launchUniversal(
|
||||
context,
|
||||
sourceId,
|
||||
chain.request().url().toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
} else response
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user