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