mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
源添加jsLib,未完成
This commit is contained in:
1853
app/schemas/io.legado.app.data.AppDatabase/65.json
Normal file
1853
app/schemas/io.legado.app.data.AppDatabase/65.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@ val appDb by lazy {
|
||||
}
|
||||
|
||||
@Database(
|
||||
version = 64,
|
||||
version = 65,
|
||||
exportSchema = true,
|
||||
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
|
||||
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
|
||||
@@ -49,7 +49,8 @@ val appDb by lazy {
|
||||
AutoMigration(from = 60, to = 61),
|
||||
AutoMigration(from = 61, to = 62),
|
||||
AutoMigration(from = 62, to = 63),
|
||||
AutoMigration(from = 63, to = 64)
|
||||
AutoMigration(from = 63, to = 64),
|
||||
AutoMigration(from = 64, to = 65, spec = DatabaseMigrations.Migration_64_65::class)
|
||||
]
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.legado.app.data
|
||||
|
||||
import androidx.room.DeleteColumn
|
||||
import androidx.room.migration.AutoMigrationSpec
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
@@ -362,4 +363,12 @@ object DatabaseMigrations {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Suppress("ClassName")
|
||||
@DeleteColumn(
|
||||
tableName = "book_sources",
|
||||
columnName = "enabledReview"
|
||||
)
|
||||
class Migration_64_65 : AutoMigrationSpec
|
||||
|
||||
}
|
||||
@@ -40,8 +40,8 @@ data class BookSource(
|
||||
// 启用发现
|
||||
@ColumnInfo(defaultValue = "1")
|
||||
var enabledExplore: Boolean = true,
|
||||
// 启用段评
|
||||
var enabledReview: Boolean? = false,
|
||||
// js库
|
||||
var jsLib: String? = null,
|
||||
// 启用okhttp CookieJAr 自动保存每次请求的cookie
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
override var enabledCookieJar: Boolean? = true,
|
||||
|
||||
@@ -27,6 +27,9 @@ data class RssSource(
|
||||
var enabled: Boolean = true,
|
||||
// 自定义变量说明
|
||||
var variableComment: String? = null,
|
||||
// js库
|
||||
var jsLib: String? = null,
|
||||
// 启用okhttp CookieJAr 自动保存每次请求的cookie
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
override var enabledCookieJar: Boolean? = true,
|
||||
/**并发率**/
|
||||
|
||||
19
app/src/main/java/io/legado/app/model/SharedJsScope.kt
Normal file
19
app/src/main/java/io/legado/app/model/SharedJsScope.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package io.legado.app.model
|
||||
|
||||
import io.legado.app.utils.MD5Utils
|
||||
import org.mozilla.javascript.Scriptable
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
object SharedJsScope {
|
||||
|
||||
private val scopeMap = hashMapOf<String, WeakReference<Scriptable>>()
|
||||
|
||||
fun getScope(jsLib: String) {
|
||||
val key = MD5Utils.md5Encode(jsLib)
|
||||
var scope = scopeMap[key]?.get()
|
||||
if (scope == null) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import androidx.activity.viewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.VMBaseActivity
|
||||
import io.legado.app.constant.BookSourceType
|
||||
@@ -156,12 +155,6 @@ class BookSourceEditActivity :
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().apply {
|
||||
setText(R.string.source_tab_content)
|
||||
})
|
||||
if (BuildConfig.DEBUG) {
|
||||
binding.cbIsEnableReview.visible()
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().apply {
|
||||
setText(R.string.review)
|
||||
})
|
||||
}
|
||||
binding.recyclerView.setEdgeEffectColor(primaryColor)
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
binding.recyclerView.adapter = adapter
|
||||
@@ -221,7 +214,6 @@ class BookSourceEditActivity :
|
||||
binding.cbIsEnable.isChecked = it.enabled
|
||||
binding.cbIsEnableExplore.isChecked = it.enabledExplore
|
||||
binding.cbIsEnableCookie.isChecked = it.enabledCookieJar ?: false
|
||||
binding.cbIsEnableReview.isChecked = it.enabledReview ?: false
|
||||
binding.spType.setSelection(
|
||||
when (it.bookSourceType) {
|
||||
BookSourceType.file -> 3
|
||||
@@ -246,6 +238,7 @@ class BookSourceEditActivity :
|
||||
add(EditEntity("header", bs.header, R.string.source_http_header))
|
||||
add(EditEntity("variableComment", bs.variableComment, R.string.variable_comment))
|
||||
add(EditEntity("concurrentRate", bs.concurrentRate, R.string.concurrent_rate))
|
||||
add(EditEntity("jsLib", bs.jsLib, "jsLib"))
|
||||
}
|
||||
// 搜索
|
||||
val sr = bs.getSearchRule()
|
||||
@@ -345,7 +338,6 @@ class BookSourceEditActivity :
|
||||
source.enabled = binding.cbIsEnable.isChecked
|
||||
source.enabledExplore = binding.cbIsEnableExplore.isChecked
|
||||
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
|
||||
source.enabledReview = binding.cbIsEnableReview.isChecked
|
||||
source.bookSourceType = when (binding.spType.selectedItemPosition) {
|
||||
3 -> BookSourceType.file
|
||||
2 -> BookSourceType.image
|
||||
@@ -372,6 +364,7 @@ class BookSourceEditActivity :
|
||||
"bookSourceComment" -> source.bookSourceComment = it.value
|
||||
"concurrentRate" -> source.concurrentRate = it.value
|
||||
"variableComment" -> source.variableComment = it.value
|
||||
"jsLib" -> source.jsLib = it.value
|
||||
}
|
||||
}
|
||||
searchEntities.forEach {
|
||||
|
||||
@@ -204,6 +204,7 @@ class RssSourceEditActivity :
|
||||
add(EditEntity("header", rs.header, R.string.source_http_header))
|
||||
add(EditEntity("variableComment", rs.variableComment, R.string.variable_comment))
|
||||
add(EditEntity("concurrentRate", rs.concurrentRate, R.string.concurrent_rate))
|
||||
add(EditEntity("jsLib", rs.jsLib, "jsLib"))
|
||||
}
|
||||
listEntities.clear()
|
||||
listEntities.apply {
|
||||
@@ -263,6 +264,7 @@ class RssSourceEditActivity :
|
||||
"variableComment" -> source.variableComment = it.value
|
||||
"concurrentRate" -> source.concurrentRate = it.value
|
||||
"sortUrl" -> source.sortUrl = it.value
|
||||
"jsLib" -> source.jsLib = it.value
|
||||
}
|
||||
}
|
||||
listEntities.forEach {
|
||||
|
||||
@@ -48,6 +48,15 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
private val indexedProps: MutableMap<Any, Any?>
|
||||
private val implementor: InterfaceImplementor
|
||||
|
||||
fun run(function: (Context) -> Any?): Any? {
|
||||
return try {
|
||||
val context = Context.enter()
|
||||
function.invoke(context)
|
||||
} finally {
|
||||
Context.exit()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(ScriptException::class)
|
||||
override fun eval(reader: Reader, scope: Scriptable): Any? {
|
||||
val cx = Context.enter()
|
||||
|
||||
@@ -43,20 +43,29 @@ import java.security.*
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
var accessContext: AccessControlContext? = null
|
||||
private var topLevel: RhinoTopLevel? = null
|
||||
private val indexedProps: MutableMap<Any, Any?>
|
||||
private val implementor: InterfaceImplementor
|
||||
var accessContext: AccessControlContext? = null
|
||||
private var topLevel: RhinoTopLevel? = null
|
||||
private val indexedProps: MutableMap<Any, Any?>
|
||||
private val implementor: InterfaceImplementor
|
||||
|
||||
@Throws(ScriptException::class)
|
||||
override fun eval(reader: Reader, scope: Scriptable): Any? {
|
||||
val cx = Context.enter()
|
||||
val ret: Any?
|
||||
try {
|
||||
var filename = this["javax.script.filename"] as? String
|
||||
filename = filename ?: "<Unknown source>"
|
||||
ret = cx.evaluateReader(scope, reader, filename, 1, null)
|
||||
} catch (re: RhinoException) {
|
||||
fun run(function: (Context) -> Any?): Any? {
|
||||
return try {
|
||||
val context = Context.enter()
|
||||
function.invoke(context)
|
||||
} finally {
|
||||
Context.exit()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(ScriptException::class)
|
||||
override fun eval(reader: Reader, scope: Scriptable): Any? {
|
||||
val cx = Context.enter()
|
||||
val ret: Any?
|
||||
try {
|
||||
var filename = this["javax.script.filename"] as? String
|
||||
filename = filename ?: "<Unknown source>"
|
||||
ret = cx.evaluateReader(scope, reader, filename, 1, null)
|
||||
} catch (re: RhinoException) {
|
||||
val line = if (re.lineNumber() == 0) -1 else re.lineNumber()
|
||||
val msg: String = if (re is JavaScriptException) {
|
||||
re.value.toString()
|
||||
|
||||
Reference in New Issue
Block a user