mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-28 03:57:50 +02:00
Add universal captcha detection
This commit is contained in:
@ -15,8 +15,8 @@ import java.nio.charset.Charset
|
||||
class AutoSolvingWebViewClient(activity: SolveCaptchaActivity,
|
||||
source: CaptchaCompletionVerifier,
|
||||
injectScript: String?,
|
||||
private val headers: Map<String, String>)
|
||||
: BasicWebViewClient(activity, source, injectScript) {
|
||||
headers: Map<String, String>)
|
||||
: HeadersInjectingWebViewClient(activity, source, injectScript, headers) {
|
||||
|
||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||
// Inject our custom script into the recaptcha iframes
|
||||
@ -32,24 +32,6 @@ class AutoSolvingWebViewClient(activity: SolveCaptchaActivity,
|
||||
doc.toString().byteInputStream(Charset.forName("UTF-8")).buffered()
|
||||
)
|
||||
}
|
||||
if(headers.isNotEmpty()) {
|
||||
val response = activity.httpClient.newCall(request.toOkHttpRequest()
|
||||
.newBuilder()
|
||||
.apply {
|
||||
headers.forEach { (n, v) -> addHeader(n, v) }
|
||||
}
|
||||
.build())
|
||||
.execute()
|
||||
|
||||
return WebResourceResponse(
|
||||
response.body()?.contentType()?.let { "${it.type()}/${it.subtype()}" },
|
||||
response.body()?.contentType()?.charset()?.toString(),
|
||||
response.code(),
|
||||
response.message(),
|
||||
response.headers().toMultimap().mapValues { it.value.joinToString(",") },
|
||||
response.body()?.byteStream()
|
||||
)
|
||||
}
|
||||
return super.shouldInterceptRequest(view, request)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user