2019-04-06 13:35:36 +02:00
|
|
|
package exh.ui.captcha
|
|
|
|
|
|
|
|
|
|
import android.webkit.WebResourceRequest
|
|
|
|
|
import android.webkit.WebResourceResponse
|
|
|
|
|
import android.webkit.WebView
|
2020-04-05 01:11:31 +02:00
|
|
|
import eu.kanade.tachiyomi.util.asJsoup
|
2019-04-06 13:35:36 +02:00
|
|
|
import org.jsoup.nodes.DataNode
|
|
|
|
|
import org.jsoup.nodes.Element
|
|
|
|
|
|
2020-04-04 22:30:05 +02:00
|
|
|
class AutoSolvingWebViewClient(
|
|
|
|
|
activity: BrowserActionActivity,
|
|
|
|
|
verifyComplete: (String) -> Boolean,
|
|
|
|
|
injectScript: String?,
|
|
|
|
|
headers: Map<String, String>
|
|
|
|
|
) :
|
|
|
|
|
HeadersInjectingWebViewClient(activity, verifyComplete, injectScript, headers) {
|
2019-04-06 13:35:36 +02:00
|
|
|
|
|
|
|
|
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
|
|
|
|
// Inject our custom script into the recaptcha iframes
|
|
|
|
|
val lastPathSegment = request.url.pathSegments.lastOrNull()
|
2020-04-04 22:30:05 +02:00
|
|
|
if (lastPathSegment == "anchor" || lastPathSegment == "bframe") {
|
2019-04-06 13:35:36 +02:00
|
|
|
val oReq = request.toOkHttpRequest()
|
|
|
|
|
val response = activity.httpClient.newCall(oReq).execute()
|
|
|
|
|
val doc = response.asJsoup()
|
2020-10-28 00:52:32 +01:00
|
|
|
doc.body().appendChild(Element("script").appendChild(DataNode(BrowserActionActivity.CROSS_WINDOW_SCRIPT_INNER)))
|
2019-04-06 13:35:36 +02:00
|
|
|
return WebResourceResponse(
|
2020-05-02 06:46:24 +02:00
|
|
|
"text/html",
|
|
|
|
|
"UTF-8",
|
2020-11-11 23:30:38 +01:00
|
|
|
doc.toString().byteInputStream().buffered()
|
2019-04-06 13:35:36 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return super.shouldInterceptRequest(view, request)
|
|
|
|
|
}
|
2020-04-04 22:30:05 +02:00
|
|
|
}
|