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 Draff
parent c8df4afffd
commit e6dba52ab9
2 changed files with 9 additions and 7 deletions

View File

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

View File

@ -46,14 +46,16 @@ class ManhwasNet : ParsedHttpSource() {
chain.proceed(request.newBuilder().headers(clearHeaders).build()) chain.proceed(request.newBuilder().headers(clearHeaders).build())
} }
if (response.headers["x-sucuri-cache"].isNullOrEmpty() && response.headers["x-sucuri-id"] != null && url.toString().startsWith(baseUrl)) { 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) { 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 { QuickJs.create().use {
val b = it.evaluate(a) as String val result = (it.evaluate(patchedScript) as String)
val sucuriCookie = it.evaluate(b.replace("location.", "").replace("reload();", "")) as String .replace("location.", "")
val cookieName = sucuriCookie.split("=")[0] .replace("reload();", "")
val cookieValue = sucuriCookie.split("=")[1].replace(";path", "") 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")!!)) client.cookieJar.saveFromResponse(url, listOf(Cookie.parse(url, "$cookieName=$cookieValue")!!))
} }
val newResponse = chain.proceed(request) val newResponse = chain.proceed(request)