komikku/app/src/main/java/exh/patch/UniversalCaptchaDetection.kt

24 lines
801 B
Kotlin
Raw Normal View History

2019-04-22 02:46:29 +02:00
package exh.patch
import android.app.Application
2019-04-22 02:46:29 +02:00
import exh.ui.captcha.BrowserActionActivity
import exh.util.interceptAsHtml
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
2019-04-22 02:46:29 +02:00
val CAPTCHA_DETECTION_PATCH: EHInterceptor = { request, response, sourceId ->
if (!response.isSuccessful) {
response.interceptAsHtml { doc ->
// Find captcha
if (doc.getElementsByClass("g-recaptcha").isNotEmpty() || doc.getElementsByClass("h-captcha").isNotEmpty()) {
// Found it, allow the user to solve this thing
BrowserActionActivity.launchUniversal(
2020-05-02 06:46:24 +02:00
Injekt.get<Application>(),
sourceId,
request.url.toString()
)
2019-04-22 02:46:29 +02:00
}
}
} else response
}