This commit is contained in:
test123456654321 2024-10-26 16:15:41 +08:00
parent d84757673c
commit dfbe50de38
5 changed files with 142 additions and 10 deletions

View File

@ -1,14 +1,97 @@
import requests import requests
from urllib.parse import quote from urllib.parse import quote
import re import re, threading
from cishu.cishubase import cishubase from cishu.cishubase import cishubase
from myutils.utils import get_element_by from myutils.utils import get_element_by, simplehtmlparser_all
class jisho(cishubase): class jisho(cishubase):
def search(self, word): def generatehtml_tabswitch(self, allres):
url = "https://jisho.org/search/{}".format(quote(word)) btns = []
contents = []
idx = 0
for title, res in allres:
idx += 1
btns.append(
f"""<button type="button" onclick="onclickbtn_xxxxxx_internal('buttonid_xxxxx_internal{idx}')" id="buttonid_xxxxx_internal{idx}" class="tab-button_xxxx_internal" data-tab="tab_xxxxx_internal{idx}">{title}</button>"""
)
contents.append(
f"""<div id="tab_xxxxx_internal{idx}" class="tab-pane_xxxxx_internal">{res}</div>"""
)
commonstyle = """
<script>
function onclickbtn_xxxxxx_internal(_id) {
tabPanes = document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-pane_xxxxx_internal');
tabButtons = document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-button_xxxx_internal');
for (i = 0; i < tabButtons.length; i++)
tabButtons[i].classList.remove('active');
for (i = 0; i < tabPanes.length; i++)
tabPanes[i].classList.remove('active');
document.getElementById(_id).classList.add('active');
tabId = document.getElementById(_id).getAttribute('data-tab');
tabPane = document.getElementById(tabId);
tabPane.classList.add('active');
}
</script>
<style>
.centerdiv_xxxxxx_internal {
display: flex;
justify-content: center;
}
.tab-widget_xxxxxx_internal .tab-button_xxxxxx_internals_xxxxxx_internal {
display: flex;
}
.tab-widget_xxxxxx_internal .tab-button_xxxx_internal {
padding: 10px 20px;
background-color: #cccccccc;
border: none;
cursor: pointer;
display: inline-block;
}
.tab-widget_xxxxxx_internal .tab-button_xxxx_internal.active {
background-color: #cccccc44;
}
.tab-widget_xxxxxx_internal .tab-content_xxxxxx_internal .tab-pane_xxxxx_internal {
display: none;
}
.tab-widget_xxxxxx_internal .tab-content_xxxxxx_internal .tab-pane_xxxxx_internal.active {
display: block;
}
</style>
"""
res = f"""
{commonstyle}
<div class="tab-widget_xxxxxx_internal">
<div class="centerdiv_xxxxxx_internal"><div>
{''.join(btns)}
</div>
</div>
<div>
<div class="tab-content_xxxxxx_internal">
{''.join(contents)}
</div>
</div>
</div>
<script>
if(document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-button_xxxx_internal').length)
document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-button_xxxx_internal')[0].click()
</script>
"""
return res
def paradown(self, word, key, saver):
link = "https://jisho.org/{}/{}".format(key, quote(word))
url = link
html = requests.get( html = requests.get(
url, url,
proxies=self.proxy, proxies=self.proxy,
@ -27,8 +110,50 @@ class jisho(cishubase):
) )
.replace(get_element_by("id", "other_dictionaries", html), "") .replace(get_element_by("id", "other_dictionaries", html), "")
) )
for link in simplehtmlparser_all(
res, "a", '<a class="concept_audio concept_light-status_link"'
):
res = res.replace(link, "")
for link in simplehtmlparser_all(
res, "a", '<a class="concept_light-status_link"'
):
res = res.replace(link, "")
for link in simplehtmlparser_all(res, "a", '<a href="#"'):
res = res.replace(link, "")
ss = re.search('href="https://assets.jisho.org/assets/application(.*)"', html) if key == "search":
stl = requests.get(ss.group()[6:-1], proxies=self.proxy).text ss = re.search(
'href="https://assets.jisho.org/assets/application(.*)"', html
)
stl = requests.get(ss.group()[6:-1], proxies=self.proxy).text
saver["style"] = stl
saver["primary"] = get_element_by("id", "main_results", res) + res.replace(
get_element_by("id", "main_results", res),
get_element_by("id", "primary", res),
)
saver["secondary"] = res.replace(
get_element_by("id", "main_results", res),
get_element_by("id", "secondary", res),
)
else:
saver[key] = res
return f"<style>{stl}</style>{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 "<style>{}</style>".format(
saver.get("style", "")
) + self.generatehtml_tabswitch(res)

View File

@ -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""" """Return the content of the tag with the specified id in the passed HTML document"""
parser = IDParser(attr, attrv) parser = IDParser(attr, attrv)
parser.loads(html) parser.loads(html)
return parser.get_result() res = parser.get_result()
if res is None:
return ""
return res

View File

@ -24,7 +24,7 @@
{{screenshot}} {{screenshot}}
</div> </div>
<div id="remarks" class="centerdiv remark-div"> <div id="remarks" class="centerdiv centertext remark-div">
{{remarks}} {{remarks}}
</div> </div>

View File

@ -9,6 +9,10 @@
justify-content: center; justify-content: center;
} }
.centertext {
text-align: center;
}
.centerdiv img { .centerdiv img {
max-width: 100%; max-width: 100%;

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 50) set(VERSION_MINOR 50)
set(VERSION_PATCH 2) set(VERSION_PATCH 3)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)