mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
.
This commit is contained in:
parent
7c6925b4e0
commit
3a05f09ba2
@ -2276,7 +2276,7 @@ class mdict(cishubase):
|
|||||||
)
|
)
|
||||||
return html_content
|
return html_content
|
||||||
|
|
||||||
def tryloadurl(self, index: IndexBuilder, base, url: str):
|
def tryloadurl(self, index: IndexBuilder, base, url: str, tolongvals: dict):
|
||||||
_local = os.path.join(base, url)
|
_local = os.path.join(base, url)
|
||||||
iscss = url.lower().endswith(".css")
|
iscss = url.lower().endswith(".css")
|
||||||
_type = 0
|
_type = 0
|
||||||
@ -2313,8 +2313,10 @@ class mdict(cishubase):
|
|||||||
if func == "sound":
|
if func == "sound":
|
||||||
ext = os.path.splitext(url1)[1].lower()
|
ext = os.path.splitext(url1)[1].lower()
|
||||||
if ext in (".aac", ".spx"):
|
if ext in (".aac", ".spx"):
|
||||||
return 3, "javascript:safe_mdict_sound_call('{}','{}')".format(
|
varname = "var_" + base64.b64encode(url1.encode()).hex()
|
||||||
ext, base64.b64encode(file_content).decode()
|
tolongvals[varname] = base64.b64encode(file_content).decode()
|
||||||
|
return 3, "javascript:safe_mdict_sound_call('{}',{})".format(
|
||||||
|
ext, varname
|
||||||
)
|
)
|
||||||
_type = 2
|
_type = 2
|
||||||
return _type, file_content
|
return _type, file_content
|
||||||
@ -2410,7 +2412,7 @@ class mdict(cishubase):
|
|||||||
)
|
)
|
||||||
return html_content
|
return html_content
|
||||||
|
|
||||||
def repairtarget(self, index, base, html_content: str):
|
def repairtarget(self, index, base, html_content: str, tolongvals: dict):
|
||||||
src_pattern = r'src="([^"]+)"'
|
src_pattern = r'src="([^"]+)"'
|
||||||
href_pattern = r'href="([^"]+)"'
|
href_pattern = r'href="([^"]+)"'
|
||||||
|
|
||||||
@ -2422,8 +2424,9 @@ class mdict(cishubase):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_content = self.tryloadurl(index, base, url)
|
file_content = self.tryloadurl(index, base, url, tolongvals)
|
||||||
except:
|
except:
|
||||||
|
print_exc()
|
||||||
print("unknown", url)
|
print("unknown", url)
|
||||||
continue
|
continue
|
||||||
if not file_content:
|
if not file_content:
|
||||||
@ -2459,7 +2462,7 @@ class mdict(cishubase):
|
|||||||
allres.append(content)
|
allres.append(content)
|
||||||
return allres
|
return allres
|
||||||
|
|
||||||
def searchthread(self, allres, i, word):
|
def searchthread(self, allres, i, word, tolongvals):
|
||||||
f, index = self.builders[i]
|
f, index = self.builders[i]
|
||||||
results = []
|
results = []
|
||||||
try:
|
try:
|
||||||
@ -2473,7 +2476,9 @@ class mdict(cishubase):
|
|||||||
|
|
||||||
print_exc()
|
print_exc()
|
||||||
for i in range(len(results)):
|
for i in range(len(results)):
|
||||||
results[i] = self.repairtarget(index, os.path.dirname(f), results[i])
|
results[i] = self.repairtarget(
|
||||||
|
index, os.path.dirname(f), results[i], tolongvals
|
||||||
|
)
|
||||||
if len(results):
|
if len(results):
|
||||||
allres.append(
|
allres.append(
|
||||||
(
|
(
|
||||||
@ -2626,23 +2631,16 @@ if (content.style.display === 'block') {
|
|||||||
|
|
||||||
def search(self, word):
|
def search(self, word):
|
||||||
allres = []
|
allres = []
|
||||||
# threads = []
|
tolongvals = {}
|
||||||
# for i in range(len(self.builders)):
|
|
||||||
# threads.append(
|
|
||||||
# threading.Thread(target=self.searchthread, args=(allres, i, word))
|
|
||||||
# )
|
|
||||||
|
|
||||||
# for _ in threads:
|
|
||||||
# _.start()
|
|
||||||
# for _ in threads:
|
|
||||||
# _.join()
|
|
||||||
for i in range(len(self.builders)):
|
for i in range(len(self.builders)):
|
||||||
self.searchthread(allres, i, word)
|
self.searchthread(allres, i, word, tolongvals)
|
||||||
if len(allres) == 0:
|
if len(allres) == 0:
|
||||||
return
|
return
|
||||||
allres.sort(key=lambda _: -_[0])
|
allres.sort(key=lambda _: -_[0])
|
||||||
func = """
|
func = "<script>"
|
||||||
<script>
|
for varname, val in tolongvals.items():
|
||||||
|
func += '{}="{}"\n'.format(varname, val)
|
||||||
|
func += """
|
||||||
function safe_mdict_sound_call(ext, b64){
|
function safe_mdict_sound_call(ext, b64){
|
||||||
if(window.mdict_sound_call)
|
if(window.mdict_sound_call)
|
||||||
window.mdict_sound_call(ext, b64)
|
window.mdict_sound_call(ext, b64)
|
||||||
@ -2654,7 +2652,8 @@ function safe_mdict_entry_call(word){
|
|||||||
window.mdict_entry_call(word)
|
window.mdict_entry_call(word)
|
||||||
else if(window.LUNAJSObject)
|
else if(window.LUNAJSObject)
|
||||||
window.LUNAJSObject.mdict_entry_call(word)
|
window.LUNAJSObject.mdict_entry_call(word)
|
||||||
}</script>"""
|
}"""
|
||||||
|
func += "</script>"
|
||||||
if self.config["stylehv"] == 0:
|
if self.config["stylehv"] == 0:
|
||||||
return self.generatehtml_tabswitch(allres) + func
|
return self.generatehtml_tabswitch(allres) + func
|
||||||
elif self.config["stylehv"] == 1:
|
elif self.config["stylehv"] == 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user