From 2c9a5f1bb318f465559984533ffb160e519d17eb Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Wed, 3 Aug 2022 13:04:38 +0800 Subject: [PATCH] Fix JsExtensions' timeFormat function --- .../model/third3/analyzeRule/JsExtensions.kt | 7 +-- .../main/java/xyz/fycz/dynamic/AppLoadImpl.kt | 1 + .../java/xyz/fycz/dynamic/fix/App250Fix.kt | 54 +++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 dynamic/src/main/java/xyz/fycz/dynamic/fix/App250Fix.kt diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt index 82cda80..4080c7c 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt @@ -25,7 +25,6 @@ import androidx.annotation.Keep import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking -import nl.siegmann.epublib.epub.PackageDocumentBase.dateFormat import org.jsoup.Connection import org.jsoup.Jsoup import xyz.fycz.myreader.application.App @@ -141,7 +140,9 @@ interface JsExtensions { BackstageWebView( url = url, html = html, - javaScript = js + javaScript = js, + headerMap = getSource()?.getHeaderMap(true), + tag = getSource()?.getKey() ).getStrResponse().body } } @@ -264,7 +265,7 @@ interface JsExtensions { * 时间格式化 */ fun timeFormat(time: Long): String { - return dateFormat.format(Date(time)) + return SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date(time)) } /** diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt index 0fed8d4..33cdecd 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt @@ -57,6 +57,7 @@ class AppLoadImpl : IAppLoader { App246Fix3::class.java, App246Fix4::class.java, App246Fix5::class.java, + App250Fix::class.java, ) override fun onLoad(appParam: AppParam) { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App250Fix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App250Fix.kt new file mode 100644 index 0000000..4798612 --- /dev/null +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App250Fix.kt @@ -0,0 +1,54 @@ +/* + * This file is part of FYReader. + * FYReader is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * FYReader is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FYReader. If not, see . + * + * Copyright (C) 2020 - 2022 fengyuecanzhu + */ + +package xyz.fycz.dynamic.fix + +import me.fycz.maple.MapleBridge +import me.fycz.maple.MapleUtils +import me.fycz.maple.MethodReplacement +import xyz.fycz.myreader.model.third3.analyzeRule.JsExtensions +import java.text.SimpleDateFormat +import java.util.* + +/** + * @author fengyue + * @date 2022/8/3 12:57 + */ +@AppFix([243, 244, 245, 246, 250], ["修复书源时间格式化bug"], "2022-08-03") +class App250Fix : AppFixHandle { + override fun onFix(key: String): BooleanArray { + return handleFix( + key, + "timeFormat" to { fixTimeFormat() }, + ) + } + + fun fixTimeFormat() { + MapleUtils.findAndHookMethod( + JsExtensions::class.java, + "timeFormat", + Long::class.java, + object : MethodReplacement() { + override fun replaceHookedMethod(param: MapleBridge.MethodHookParam): Any { + val time = param.args[0] as Long + return SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date(time)) + } + } + ) + } +} \ No newline at end of file