LuaScans: set js cookie (#3361)

* LuaScans: set js cookie

* bump
This commit is contained in:
AwkwardPeak7 2024-06-03 15:50:27 +05:00 committed by Draff
parent 66edae8b60
commit 8e28453769
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 35 additions and 2 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.LuaScans'
themePkg = 'mangathemesia'
baseUrl = 'https://luascans.com'
overrideVersionCode = 1
overrideVersionCode = 2
}
apply from: "$rootDir/common.gradle"

View File

@ -2,7 +2,11 @@ package eu.kanade.tachiyomi.extension.en.luascans
import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import okhttp3.Cookie
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
import org.jsoup.Jsoup
class LuaScans : MangaThemesia(
"Lua Scans",
@ -10,6 +14,35 @@ class LuaScans : MangaThemesia(
"en",
) {
override val client: OkHttpClient = super.client.newBuilder()
.rateLimit(4)
.addInterceptor(::wafffCookieInterceptor)
.rateLimit(2)
.build()
private fun wafffCookieInterceptor(chain: Interceptor.Chain): Response {
val request = chain.request()
val response = chain.proceed(request)
val document = Jsoup.parse(
response.peekBody(Long.MAX_VALUE).string(),
response.request.url.toString(),
)
return if (document.selectFirst("script:containsData(wafff)") != null) {
val script = document.selectFirst("script:containsData(wafff)")!!.data()
val cookie = script.substringAfter("document.cookie=\"")
.substringBefore("\"")
client.cookieJar.saveFromResponse(
request.url,
listOfNotNull(Cookie.parse(request.url, cookie)),
)
response.close()
chain.proceed(request)
} else {
response
}
}
}