Add universal captcha detection

This commit is contained in:
NerdNumber9
2019-04-18 22:08:09 -04:00
parent f0109aa796
commit 5c2fbec80a
3 changed files with 101 additions and 36 deletions

View File

@ -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)
}
}