komikku/app/src/main/java/exh/patch/UniversalCaptchaDetection.kt
2022-09-11 19:43:45 -04:00

25 lines
818 B
Kotlin

package exh.patch
import android.app.Application
import exh.ui.captcha.BrowserActionActivity
import exh.util.interceptAsHtml
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
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(
Injekt.get<Application>(),
sourceId,
request.url.toString(),
)
}
}
} else {
response
}
}