Manhwas.net: Tweak Sucuri Interceptor (#238)

Fix possible issues in SucuriInterceptor
This commit is contained in:
bapeey 2024-01-14 00:26:28 -05:00 committed by GitHub
parent ec2d6ef3da
commit dbca7167c3
2 changed files with 9 additions and 7 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Manhwas.net'
pkgNameSuffix = 'es.manhwasnet'
extClass = '.ManhwasNet'
extVersionCode = 10
extVersionCode = 11
isNsfw = true
}

View File

@ -46,14 +46,16 @@ class ManhwasNet : ParsedHttpSource() {
chain.proceed(request.newBuilder().headers(clearHeaders).build())
}
if (response.headers["x-sucuri-cache"].isNullOrEmpty() && response.headers["x-sucuri-id"] != null && url.toString().startsWith(baseUrl)) {
val script = response.asJsoup().selectFirst("script")?.data()
val script = response.use { it.asJsoup() }.selectFirst("script")?.data()
if (script != null) {
val a = script.split("(r)")[0].dropLast(1) + "r=r.replace('document.cookie','cookie');"
val patchedScript = script.split("(r)")[0].dropLast(1) + "r=r.replace('document.cookie','cookie');"
QuickJs.create().use {
val b = it.evaluate(a) as String
val sucuriCookie = it.evaluate(b.replace("location.", "").replace("reload();", "")) as String
val cookieName = sucuriCookie.split("=")[0]
val cookieValue = sucuriCookie.split("=")[1].replace(";path", "")
val result = (it.evaluate(patchedScript) as String)
.replace("location.", "")
.replace("reload();", "")
val sucuriCookie = (it.evaluate(result) as String).split("=", limit = 2)
val cookieName = sucuriCookie.first()
val cookieValue = sucuriCookie.last().replace(";path", "")
client.cookieJar.saveFromResponse(url, listOf(Cookie.parse(url, "$cookieName=$cookieValue")!!))
}
val newResponse = chain.proceed(request)