This commit is contained in:
kunfei
2023-02-20 00:03:19 +08:00
parent 16981091b7
commit 9f0fb3807d
2 changed files with 3 additions and 18 deletions
@@ -2,7 +2,7 @@
{ {
"name": "百度汉语", "name": "百度汉语",
"urlRule": "https://dict.baidu.com/s?wd={{key}}", "urlRule": "https://dict.baidu.com/s?wd={{key}}",
"showRule": "all", "showRule": "@js:var jsoup = org.jsoup.Jsoup.parse(result)\njsoup.select(\"script\").remove()\njsoup.select(\"#word-header\").remove()\njsoup.select(\"#term-header\").remove()\njsoup.select(\".more-button\").remove()\njsoup.select(\".disactive\").remove()\njsoup.select(\"#download-wrapper\").remove()\njsoup.select(\"#right-panel\").remove()\njsoup.select(\"#content-panel\")\njsoup.body()",
"enabled": true, "enabled": true,
"sortNumber": 0 "sortNumber": 0
}, },
@@ -4,11 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.help.http.get
import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import org.jsoup.Jsoup
import java.util.regex.Pattern import java.util.regex.Pattern
class DictViewModel(application: Application) : BaseViewModel(application) { class DictViewModel(application: Application) : BaseViewModel(application) {
@@ -46,20 +42,9 @@ class DictViewModel(application: Application) : BaseViewModel(application) {
*/ */
private fun baiduDict(word: String) { private fun baiduDict(word: String) {
execute { execute {
val body = okHttpClient.newCallStrResponse { DefaultData.dictRules[0].search(word)
get("https://dict.baidu.com/s", mapOf(Pair("wd", word)))
}.body
val jsoup = Jsoup.parse(body!!)
jsoup.select("script").remove()//移除script
jsoup.select("#word-header").remove()//移除单字的header
jsoup.select("#term-header").remove()//移除词语的header
jsoup.select(".more-button").remove()//移除展示更多
jsoup.select(".disactive").remove()
jsoup.select("#download-wrapper").remove()//移除下载广告
jsoup.select("#right-panel").remove()//移除右侧广告
jsoup.select("#content-panel")
}.onSuccess { }.onSuccess {
dictHtmlData.postValue(it.html()) dictHtmlData.postValue(it)
}.onError { }.onError {
context.toastOnUi(it.localizedMessage) context.toastOnUi(it.localizedMessage)
} }