From dfbe50de3814fb42ddc3602698444fe188c20a6a Mon Sep 17 00:00:00 2001 From: test123456654321 <16307130148@fudan.edu.cn> Date: Sat, 26 Oct 2024 16:15:41 +0800 Subject: [PATCH] some --- src/LunaTranslator/cishu/jisho.py | 139 ++++++++++++++++++++++++++-- src/LunaTranslator/myutils/utils.py | 5 +- src/files/anki/back.html | 2 +- src/files/anki/style.css | 4 + src/plugins/CMakeLists.txt | 2 +- 5 files changed, 142 insertions(+), 10 deletions(-) diff --git a/src/LunaTranslator/cishu/jisho.py b/src/LunaTranslator/cishu/jisho.py index 322ddbe1..56b8acc4 100644 --- a/src/LunaTranslator/cishu/jisho.py +++ b/src/LunaTranslator/cishu/jisho.py @@ -1,14 +1,97 @@ import requests from urllib.parse import quote -import re +import re, threading from cishu.cishubase import cishubase -from myutils.utils import get_element_by +from myutils.utils import get_element_by, simplehtmlparser_all class jisho(cishubase): - def search(self, word): - url = "https://jisho.org/search/{}".format(quote(word)) + def generatehtml_tabswitch(self, allres): + btns = [] + contents = [] + idx = 0 + for title, res in allres: + idx += 1 + btns.append( + f"""""" + ) + contents.append( + f"""
{res}
""" + ) + commonstyle = """ + + +""" + + res = f""" + {commonstyle} +
+ +
+ {''.join(btns)} +
+
+
+
+ {''.join(contents)} +
+
+
+ +""" + return res + + def paradown(self, word, key, saver): + + link = "https://jisho.org/{}/{}".format(key, quote(word)) + url = link html = requests.get( url, proxies=self.proxy, @@ -27,8 +110,50 @@ class jisho(cishubase): ) .replace(get_element_by("id", "other_dictionaries", html), "") ) + for link in simplehtmlparser_all( + res, "a", '{stl}{res}" + def search(self, word): + + ts = [] + saver = {} + for key in ("word", "search"): + ts.append(threading.Thread(target=self.paradown, args=(word, key, saver))) + ts[-1].start() + for t in ts: + t.join() + res = [] + if saver.get("word"): + res.append(("Word", saver["word"])) + if saver.get("primary"): + res.append(("Words", saver["primary"])) + if saver.get("secondary"): + res.append(("Others", saver["secondary"])) + return "".format( + saver.get("style", "") + ) + self.generatehtml_tabswitch(res) diff --git a/src/LunaTranslator/myutils/utils.py b/src/LunaTranslator/myutils/utils.py index 8f76a8ac..5780805f 100644 --- a/src/LunaTranslator/myutils/utils.py +++ b/src/LunaTranslator/myutils/utils.py @@ -1021,4 +1021,7 @@ def get_element_by(attr, attrv, html): """Return the content of the tag with the specified id in the passed HTML document""" parser = IDParser(attr, attrv) parser.loads(html) - return parser.get_result() + res = parser.get_result() + if res is None: + return "" + return res diff --git a/src/files/anki/back.html b/src/files/anki/back.html index d303a2cc..f84ebac0 100644 --- a/src/files/anki/back.html +++ b/src/files/anki/back.html @@ -24,7 +24,7 @@ {{screenshot}} -
+
{{remarks}}
diff --git a/src/files/anki/style.css b/src/files/anki/style.css index 1605011b..03cf344f 100644 --- a/src/files/anki/style.css +++ b/src/files/anki/style.css @@ -9,6 +9,10 @@ justify-content: center; } +.centertext { + text-align: center; +} + .centerdiv img { max-width: 100%; diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index a0e9ad8c..58913458 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 50) -set(VERSION_PATCH 2) +set(VERSION_PATCH 3) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)