Pupil-127 Use gg.js directly
This commit is contained in:
@@ -81,6 +81,7 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1"
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"
|
||||||
|
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.3.2"
|
||||||
|
|
||||||
implementation "androidx.appcompat:appcompat:1.4.1"
|
implementation "androidx.appcompat:appcompat:1.4.1"
|
||||||
implementation "androidx.activity:activity-ktx:1.4.0"
|
implementation "androidx.activity:activity-ktx:1.4.0"
|
||||||
@@ -128,10 +129,6 @@ dependencies {
|
|||||||
|
|
||||||
implementation "org.jsoup:jsoup:1.14.3"
|
implementation "org.jsoup:jsoup:1.14.3"
|
||||||
|
|
||||||
implementation ("app.cash.zipline:zipline:1.0.0-SNAPSHOT") {
|
|
||||||
exclude group: "com.squareup.okio", module: "okio"
|
|
||||||
}
|
|
||||||
|
|
||||||
implementation "xyz.quaver:documentfilex:0.7.2"
|
implementation "xyz.quaver:documentfilex:0.7.2"
|
||||||
implementation "xyz.quaver:floatingsearchview:1.1.7"
|
implementation "xyz.quaver:floatingsearchview:1.1.7"
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import android.util.Log
|
|||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import app.cash.zipline.QuickJs
|
|
||||||
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
|
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
|
||||||
import com.github.piasy.biv.BigImageViewer
|
import com.github.piasy.biv.BigImageViewer
|
||||||
import com.github.piasy.biv.loader.fresco.FrescoImageLoader
|
import com.github.piasy.biv.loader.fresco.FrescoImageLoader
|
||||||
@@ -77,46 +76,12 @@ val client: OkHttpClient
|
|||||||
clientHolder = it
|
clientHolder = it
|
||||||
}
|
}
|
||||||
|
|
||||||
private var version = ""
|
|
||||||
var runtimeReady = false
|
|
||||||
private set
|
|
||||||
lateinit var runtime: QuickJs
|
|
||||||
|
|
||||||
class Pupil : Application() {
|
class Pupil : Application() {
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var instance: Pupil
|
lateinit var instance: Pupil
|
||||||
private set
|
private set
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
runtime = QuickJs.create()
|
|
||||||
}
|
|
||||||
while (true) {
|
|
||||||
kotlin.runCatching {
|
|
||||||
val newVersion = URL("https://tom5079.github.io/PupilSources/hitomi.html.ver").readText()
|
|
||||||
|
|
||||||
if (version != newVersion) {
|
|
||||||
runtimeReady = false
|
|
||||||
evaluationContext.cancelChildren()
|
|
||||||
kotlin.runCatching {
|
|
||||||
URL("https://tom5079.github.io/PupilSources/assets/js/gg.js").readText()
|
|
||||||
}.getOrNull()?.also { gg ->
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
runtime.evaluate(gg)
|
|
||||||
version = newVersion
|
|
||||||
runtimeReady = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delay(10000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
instance = this
|
instance = this
|
||||||
|
|
||||||
|
|||||||
@@ -17,16 +17,24 @@
|
|||||||
package xyz.quaver.pupil.hitomi
|
package xyz.quaver.pupil.hitomi
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import kotlinx.datetime.Clock.System.now
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Callback
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
import xyz.quaver.pupil.client
|
import xyz.quaver.pupil.client
|
||||||
import xyz.quaver.pupil.runtime
|
|
||||||
import xyz.quaver.pupil.runtimeReady
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
import kotlin.coroutines.resumeWithException
|
||||||
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
import kotlin.time.ExperimentalTime
|
||||||
|
|
||||||
const val protocol = "https:"
|
const val protocol = "https:"
|
||||||
|
|
||||||
@@ -131,19 +139,73 @@ const val nozomiextension = ".nozomi"
|
|||||||
val evaluationContext = Dispatchers.Main + Job()
|
val evaluationContext = Dispatchers.Main + Job()
|
||||||
|
|
||||||
object gg {
|
object gg {
|
||||||
|
private var lastRetrieval: Instant? = null
|
||||||
|
|
||||||
suspend fun m(g: Int): Int = withContext(evaluationContext) {
|
private val mutex = Mutex()
|
||||||
while (!runtimeReady) delay(1000)
|
|
||||||
runtime.evaluate("gg.m($g)").toString().toInt()
|
private var mDefault = 0
|
||||||
}
|
private val mMap = mutableMapOf<Int, Int>()
|
||||||
suspend fun b(): String = withContext(evaluationContext) {
|
|
||||||
while (!runtimeReady) delay(1000)
|
private var b = ""
|
||||||
runtime.evaluate("gg.b").toString()
|
|
||||||
|
@OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class)
|
||||||
|
private suspend fun refresh() = withContext(Dispatchers.IO) {
|
||||||
|
mutex.withLock {
|
||||||
|
if (lastRetrieval == null || (lastRetrieval!! + 1.minutes) < now()) {
|
||||||
|
val ggjs: String = suspendCancellableCoroutine { continuation ->
|
||||||
|
val call = client.newCall(Request.Builder().url("https://ltn.hitomi.la/gg.js").build())
|
||||||
|
|
||||||
|
call.enqueue(object: Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
if (continuation.isCancelled) return
|
||||||
|
continuation.resumeWithException(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
if (!call.isCanceled) {
|
||||||
|
response.body()?.use {
|
||||||
|
continuation.resume(it.string()) {
|
||||||
|
call.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
call.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mDefault = Regex("var o = (\\d)").find(ggjs)!!.groupValues[1].toInt()
|
||||||
|
val o = Regex("o = (\\d); break;").find(ggjs)!!.groupValues[1].toInt()
|
||||||
|
|
||||||
|
mMap.clear()
|
||||||
|
Regex("case (\\d+):").findAll(ggjs).forEach {
|
||||||
|
val case = it.groupValues[1].toInt()
|
||||||
|
mMap[case] = o
|
||||||
|
}
|
||||||
|
|
||||||
|
b = Regex("b: '(.+)'").find(ggjs)!!.groupValues[1]
|
||||||
|
|
||||||
|
lastRetrieval = now()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun s(h: String): String = withContext(evaluationContext) {
|
suspend fun m(g: Int): Int {
|
||||||
while (!runtimeReady) delay(1000)
|
refresh()
|
||||||
runtime.evaluate("gg.s('$h')").toString()
|
|
||||||
|
return mMap[g] ?: mDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun b(): String {
|
||||||
|
refresh()
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
fun s(h: String): String {
|
||||||
|
val m = Regex("(..)(.)$").find(h)
|
||||||
|
return m!!.groupValues.let { it[2]+it[1] }.toInt(16).toString(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user