Fix japscan (dynamic page loading) (#14109)

* Fix japscan

* Update extVersionCode
This commit is contained in:
BRAMILLE Sébastien 2022-11-03 10:20:38 +00:00 committed by GitHub
parent c088dfcc6f
commit 2d56d12797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Japscan'
pkgNameSuffix = 'fr.japscan'
extClass = '.Japscan'
extVersionCode = 32
extVersionCode = 33
}
dependencies {

View File

@ -11,6 +11,7 @@ import android.os.Looper
import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
@ -351,7 +352,7 @@ class Japscan : ConfigurableSource, ParsedHttpSource() {
val zjs = client.newCall(GET(baseUrl + zjsurl, headers)).execute().body!!.string()
Log.d("japscan", "webtoon, netdumping initiated")
val pagesElement = document.getElementById("pages")
val pagecount = pagesElement.getElementsByTag("option").size
var pagecount = pagesElement.getElementsByTag("option").size
val pages = ArrayList<Page>()
val handler = Handler(Looper.getMainLooper())
val checkNew = ArrayList<String>(pagecount)
@ -376,6 +377,21 @@ class Japscan : ConfigurableSource, ParsedHttpSource() {
webview.settings.domStorageEnabled = true
webview.settings.userAgentString = webview.settings.userAgentString.replace("Mobile", "eliboM").replace("Android", "diordnA")
webview.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String?) {
if (pagecount === 0) {
Log.d("japscan", "dynamic page count detected, loading it through JS")
super.onPageFinished(view, url)
view.evaluateJavascript(
"(function() { return document.getElementById('pages').length; })();",
object : ValueCallback<String> {
override fun onReceiveValue(numberOfPages: String?) {
pagecount = numberOfPages!!.toInt()
}
}
)
}
}
override fun shouldInterceptRequest(
view: WebView,
request: WebResourceRequest