This commit is contained in:
kunfei 2023-02-20 00:03:19 +08:00
parent 814fcaffdc
commit cf6c6df86b
2 changed files with 3 additions and 18 deletions

View File

@ -2,7 +2,7 @@
{
"name": "百度汉语",
"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,
"sortNumber": 0
},

View File

@ -4,11 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
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 org.jsoup.Jsoup
import java.util.regex.Pattern
class DictViewModel(application: Application) : BaseViewModel(application) {
@ -46,20 +42,9 @@ class DictViewModel(application: Application) : BaseViewModel(application) {
*/
private fun baiduDict(word: String) {
execute {
val body = okHttpClient.newCallStrResponse {
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")
DefaultData.dictRules[0].search(word)
}.onSuccess {
dictHtmlData.postValue(it.html())
dictHtmlData.postValue(it)
}.onError {
context.toastOnUi(it.localizedMessage)
}