This commit is contained in:
恍兮惚兮 2025-01-02 13:13:39 +08:00
parent b17943a3ac
commit 4f52269c7d
3 changed files with 27 additions and 11 deletions

View File

@ -2294,7 +2294,7 @@ class mdict(cishubase):
return _type, file_content return _type, file_content
if url.startswith("entry://"): if url.startswith("entry://"):
return 3, "javascript:safe_mdict_entry_call('{}')".format(url[8:]) return 3, "javascript:safe_mdict_search_word('{}')".format(url[8:])
if url.startswith("sound://"): if url.startswith("sound://"):
file_content = self.parse_url_in_mdd(index, url[8:]) file_content = self.parse_url_in_mdd(index, url[8:])
if not file_content: if not file_content:
@ -2582,10 +2582,10 @@ for(let i=0;i<elements.length;i++)
var lastmusicplayer=false; var lastmusicplayer=false;
function mdict_play_sound(ext, b64){ function mdict_play_sound(ext, b64){
if(window.mdict_audio_call) if(window.luna_audio_play_b64)
window.mdict_audio_call(b64) window.luna_audio_play_b64(b64)
else if(window.LUNAJSObject) else if(window.LUNAJSObject)
window.LUNAJSObject.mdict_audio_call(b64) window.LUNAJSObject.luna_audio_play_b64(b64)
else{ else{
const music = new Audio(); const music = new Audio();
music.src="data:"+ext+";base64,"+b64 music.src="data:"+ext+";base64,"+b64
@ -2597,11 +2597,11 @@ if(window.mdict_audio_call)
music.play(); music.play();
} }
} }
function safe_mdict_entry_call(word){ function safe_mdict_search_word(word){
if(window.mdict_entry_call) if(window.luna_search_word)
window.mdict_entry_call(word) window.luna_search_word(word)
else if(window.LUNAJSObject) else if(window.LUNAJSObject)
window.LUNAJSObject.mdict_entry_call(word) window.LUNAJSObject.luna_search_word(word)
}""" }"""
for varname, val in audiob64vals.items(): for varname, val in audiob64vals.items():
func += '{}="{}"\n'.format(varname, val) func += '{}="{}"\n'.format(varname, val)

View File

@ -1,5 +1,5 @@
import requests import requests
from urllib.parse import quote from urllib.parse import quote, unquote
from cishu.cishubase import cishubase from cishu.cishubase import cishubase
from myutils.utils import simplehtmlparser_all, simplehtmlparser from myutils.utils import simplehtmlparser_all, simplehtmlparser
import re, threading import re, threading
@ -42,6 +42,22 @@ class weblio(cishubase):
join = removeklass(join, "lgDictLg") join = removeklass(join, "lgDictLg")
join = removeklass(join, "lgDictSp") join = removeklass(join, "lgDictSp")
join = join.replace('href="//', 'href="https://')
def __(match):
word = unquote(match.groups()[0])
return '''href="javascript:safe_weblio_search_word('{}')"'''.format(word)
join = re.sub('href="https://www.weblio.jp/content/(.*?)"', __, join)
join+=r'''
<script>
function safe_weblio_search_word(word){
if(window.luna_search_word)
window.luna_search_word(word)
else if(window.LUNAJSObject)
window.LUNAJSObject.luna_search_word(word)
}</script>
'''
links = [] links = []
style = simplehtmlparser(html, "style", "<style>")[7:-8] style = simplehtmlparser(html, "style", "<style>")[7:-8]
for link in simplehtmlparser_all(html, "link", '<link rel="stylesheet"'): for link in simplehtmlparser_all(html, "link", '<link rel="stylesheet"'):

View File

@ -1265,10 +1265,10 @@ class searchwordW(closeashidewindow):
functools.partial(globalconfig.__setitem__, "ZoomFactor") functools.partial(globalconfig.__setitem__, "ZoomFactor")
) )
self.textOutput.bind( self.textOutput.bind(
"mdict_entry_call", lambda word: self.search_word.emit(word, False) "luna_search_word", lambda word: self.search_word.emit(word, False)
) )
self.textOutput.bind( self.textOutput.bind(
"mdict_audio_call", "luna_audio_play_b64",
lambda b64: gobject.baseobject.audioplayer.play( lambda b64: gobject.baseobject.audioplayer.play(
base64.b64decode(b64.encode()), force=True base64.b64decode(b64.encode()), force=True
), ),