-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CodeApe
committed
Jul 25, 2024
1 parent
8c03054
commit 01a950c
Showing
6 changed files
with
73 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//go:build js && wasm | ||
|
||
package wasmecdict | ||
package main | ||
|
||
import ( | ||
"github.com/mojocn/wasmecdict" | ||
"syscall/js" | ||
) | ||
|
||
|
@@ -11,7 +12,7 @@ const versionCe = "1.0.1" | |
func ceLookUpTw(_ js.Value, args []js.Value) any { | ||
if len(args) > 0 { | ||
text := args[0].String() | ||
res := CeLookUp(text, false) | ||
res := wasmecdict.CeLookUp(text, false) | ||
if res != nil { | ||
return js.ValueOf(res.Map()) | ||
} | ||
|
@@ -21,7 +22,7 @@ func ceLookUpTw(_ js.Value, args []js.Value) any { | |
func ceLookUpCn(_ js.Value, args []js.Value) any { | ||
if len(args) > 0 { | ||
text := args[0].String() | ||
res := CeLookUp(text, true) | ||
res := wasmecdict.CeLookUp(text, true) | ||
if res != nil { | ||
return js.ValueOf(res.Map()) | ||
} | ||
|
@@ -31,7 +32,7 @@ func ceLookUpCn(_ js.Value, args []js.Value) any { | |
func ceQueryLikeTw(_ js.Value, args []js.Value) any { | ||
if len(args) > 0 { | ||
text := args[0].String() | ||
words := CeQueryLike(text, false, 10) | ||
words := wasmecdict.CeQueryLike(text, false, 10) | ||
results := make([]map[string]interface{}, 0, len(words)) | ||
for _, word := range words { | ||
results = append(results, word.Map()) | ||
|
@@ -43,7 +44,7 @@ func ceQueryLikeTw(_ js.Value, args []js.Value) any { | |
func ceQueryLikeCn(_ js.Value, args []js.Value) any { | ||
if len(args) > 0 { | ||
text := args[0].String() | ||
words := CeQueryLike(text, true, 10) | ||
words := wasmecdict.CeQueryLike(text, true, 10) | ||
results := make([]map[string]interface{}, 0, len(words)) | ||
for _, word := range words { | ||
results = append(results, word.Map()) | ||
|
@@ -56,7 +57,6 @@ func ceQueryLikeCn(_ js.Value, args []js.Value) any { | |
func ceDictInfo(_ js.Value, _ []js.Value) any { | ||
return map[string]interface{}{ | ||
"version": versionCe, | ||
"words": len(ceDictSingletonCn), | ||
"author": "[email protected]", | ||
"email": "[email protected]", | ||
"DictionaryData": "https://www.mdbg.net/chinese/dictionary?page=cedict", | ||
|
@@ -65,13 +65,12 @@ func ceDictInfo(_ js.Value, _ []js.Value) any { | |
} | ||
|
||
func main() { | ||
preLoadCeDict() | ||
js.Global().Set("ceLookUpTw", js.FuncOf(ceLookUpTw)) //export window.ceLookUpTw to lookUp Chinese word | ||
js.Global().Set("ceLookUpCn", js.FuncOf(ceLookUpCn)) //export window.ceLookUpCn to lookUp Chinese word | ||
js.Global().Set("ceQueryLikeCn", js.FuncOf(ceQueryLikeCn)) //export window.ceLookUpCn to lookUp Chinese word | ||
js.Global().Set("ceQueryLikeTw", js.FuncOf(ceQueryLikeTw)) //export window.ceLookUpCn to lookUp Chinese word | ||
js.Global().Set("ceDictInfo", js.FuncOf(ceDictInfo)) //export window.ecInfo to get dictionary info | ||
|
||
done := make(chan struct{}, 0) | ||
wasmecdict.PreLoadCeDict() | ||
js.Global().Set("ceLookUpTw", js.FuncOf(ceLookUpTw)) //export window.ceLookUpTw to lookUp Traditional Chinese word | ||
js.Global().Set("ceLookUpCn", js.FuncOf(ceLookUpCn)) //export window.ceLookUpCn to lookUp Simplified Chinese word | ||
js.Global().Set("ceQueryLikeCn", js.FuncOf(ceQueryLikeCn)) //export window.ceQueryLikeCn to query Simplified Chinese word | ||
js.Global().Set("ceQueryLikeTw", js.FuncOf(ceQueryLikeTw)) //export window.ceQueryLikeTw to query Traditional Chinese word | ||
js.Global().Set("ceDictInfo", js.FuncOf(ceDictInfo)) //export window.ceDictInfo to get dictionary info | ||
done := make(chan struct{}) | ||
<-done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//go:build js && wasm | ||
|
||
package wasmecdict | ||
package main | ||
|
||
import ( | ||
"github.com/mojocn/wasmecdict" | ||
"syscall/js" | ||
) | ||
|
||
|
@@ -11,7 +12,7 @@ const versionEc = "1.0.1" | |
func lookUp(_ js.Value, args []js.Value) any { | ||
if len(args) > 0 { | ||
text := args[0].String() | ||
res := EcLookUp(text) | ||
res := wasmecdict.EcLookUp(text) | ||
if res != nil { | ||
return js.ValueOf(res.Map()) | ||
} | ||
|
@@ -22,8 +23,6 @@ func lookUp(_ js.Value, args []js.Value) any { | |
func ecDictInfo(_ js.Value, _ []js.Value) any { | ||
return map[string]interface{}{ | ||
"version": versionEc, | ||
"words": len(dictMapSingleton), | ||
"lemmas": len(lemmaMapSingleton), | ||
"author": "[email protected]", | ||
"email": "[email protected]", | ||
"DictionaryData": "https://github.com/skywind3000/ECDICT", | ||
|
@@ -32,9 +31,9 @@ func ecDictInfo(_ js.Value, _ []js.Value) any { | |
} | ||
|
||
func main() { | ||
preloadEcDict() | ||
js.Global().Set("ecLookUp", js.FuncOf(lookUp)) //export window.ecLookUp to lookUp English word | ||
js.Global().Set("ecDictInfo", js.FuncOf(ecDictInfo)) //export window.ecInfo to get dictionary info | ||
done := make(chan struct{}, 0) | ||
wasmecdict.PreLoadEcDict() | ||
js.Global().Set("ecLookUp", js.FuncOf(lookUp)) //use window.ecLookUp("word") to look up a word | ||
js.Global().Set("ecDictInfo", js.FuncOf(ecDictInfo)) //use window.ecDictInfo() to get dictionary info | ||
done := make(chan struct{}) | ||
<-done | ||
} |