diff --git a/app/src/main/assets/help/jsHelp.md b/app/src/main/assets/help/jsHelp.md index 32cc55968..41de61d2e 100644 --- a/app/src/main/assets/help/jsHelp.md +++ b/app/src/main/assets/help/jsHelp.md @@ -55,9 +55,6 @@ java.getElements(ruleStr: String) java.reGetBook() java.refreshTocUrl() ``` - -### [js扩展类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/JsExtensions.kt) 部分函数 - * 变量存取 ``` @@ -65,6 +62,8 @@ java.get(key) java.put(key, value) ``` +### [js扩展类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/JsExtensions.kt) 部分函数 + * 网络请求 ``` diff --git a/app/src/main/assets/help/ruleHelp.md b/app/src/main/assets/help/ruleHelp.md index 554509612..75b1849b1 100644 --- a/app/src/main/assets/help/ruleHelp.md +++ b/app/src/main/assets/help/ruleHelp.md @@ -152,4 +152,8 @@ let options = { ``` * 购买操作 -> 可直接填写链接或者JavaScript,如果执行结果是字符串链接将会自动打开浏览器 \ No newline at end of file +> 可直接填写链接或者JavaScript,如果执行结果是字符串链接将会自动打开浏览器 + +* 图片解密 +> 适用于图片需要二次解密的情况,直接填写JavaScript,返回解密后的bytes +> 部分变量说明:java(仅支持[js扩展类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/JsExtensions.kt)),result为待解密图片的bytes,src为图片链接 diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt index 4f881b2a3..f1068b14e 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt @@ -11,5 +11,6 @@ data class ContentRule( var sourceRegex: String? = null, var replaceRegex: String? = null, //替换规则 var imageStyle: String? = null, //默认大小居中,FULL最大宽度 + var imageDecode: String? = null, //图片bytes二次解密js, 返回解密后的bytes var payAction: String? = null, //购买操作,js或者包含{{js}}的url ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 8fccb7723..608d593b2 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -136,15 +136,28 @@ object BookHelp { downloadImages.add(src) val analyzeUrl = AnalyzeUrl(src, source = bookSource) try { - analyzeUrl.getByteArrayAwait().let { - FileUtils.createFileIfNotExist( + var bytes = analyzeUrl.getByteArrayAwait() + //某些图片被加密,需要进一步解密 + bookSource?.getContentRule()?.imageDecode?.let { + kotlin.runCatching { + bookSource?.evalJS(it) { + put("book", book) + put("result", bytes) + put("src", src) + } as ByteArray + }.onSuccess { + bytes = it + }.onFailure { + AppLog.putDebug("${src}解密bytes错误", it) + } + } + FileUtils.createFileIfNotExist( downloadDir, cacheFolderName, book.getFolderName(), cacheImageFolderName, "${MD5Utils.md5Encode16(src)}.${getImageSuffix(src)}" - ).writeBytes(it) - } + ).writeBytes(bytes) } catch (e: Exception) { AppLog.putDebug("${src}下载错误", e) } finally { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 7d7738687..603a244ae 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -297,6 +297,7 @@ class BookSourceEditActivity : add(EditEntity("sourceRegex", cr?.sourceRegex, R.string.rule_source_regex)) add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex)) add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style)) + add(EditEntity("imageDecode", cr?.imageDecode, R.string.rule_image_decode)) add(EditEntity("payAction", cr?.payAction, R.string.rule_pay_action)) } // 段评 @@ -451,6 +452,7 @@ class BookSourceEditActivity : "sourceRegex" -> contentRule.sourceRegex = it.value "replaceRegex" -> contentRule.replaceRegex = it.value "imageStyle" -> contentRule.imageStyle = it.value + "imageDecode" -> contentRule.imageDecode = it.value "payAction" -> contentRule.payAction = it.value } } diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index c41a09106..b4e47cd47 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1025,4 +1025,5 @@ 标志:发现已禁用 show read title addition area read bar style follow page + Decode Image(imageDecode) diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 49ae6bd4a..e1cdf5197 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1028,4 +1028,5 @@ 标志:发现已禁用 show read title addition area read bar style follow page + Decode Image(imageDecode) diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7251b06bb..6c7f0b320 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1028,4 +1028,5 @@ 标志:发现已禁用 show read title addition area read bar style follow page + Decode Image(imageDecode) diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 9ec80a4b1..0857f25d7 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1025,4 +1025,5 @@ 标志:发现已禁用 展示顶部工具栏附加区域 工具栏样式跟随页面 + 图片解密(imageDecode) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index b004c5dda..dbc30e0e4 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1027,4 +1027,5 @@ 标志:发现已禁用 展示顶部工具栏附加区域 工具栏样式跟随页面 + 图片解密(imageDecode) diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index acc0a7721..014b0e727 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1027,4 +1027,5 @@ 标志:发现已禁用 展示顶部工具栏附加区域 工具栏样式跟随页面 + 图片解密(imageDecode) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fe3f6c4b0..b8e307ae6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1028,4 +1028,5 @@ 标志:发现已禁用 show read title addition area read bar style follow page + Decode Image(imageDecode)