File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed
Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 1111
1212[ 1 ] : https://travis-ci.org/TimothyYe/ydict.svg?branch=master
1313[ 2 ] : https://travis-ci.org/TimothyYe/ydict
14- [ 3 ] : https://img.shields.io/badge/release-v0.6 -brightgreen.svg
14+ [ 3 ] : https://img.shields.io/badge/release-v0.7 -brightgreen.svg
1515[ 4 ] : https://github.com/TimothyYe/ydict/releases
1616[ 5 ] : https://img.shields.io/dub/l/vibe-d.svg
1717[ 6 ] : LICENSE
Original file line number Diff line number Diff line change @@ -19,5 +19,5 @@ func main() {
1919 }
2020
2121 words := strings .Join (os .Args [1 :], " " )
22- query (words )
22+ query (words , len ( os . Args [ 1 :]) > 1 )
2323}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import (
1212 proxier "golang.org/x/net/proxy"
1313)
1414
15- func query (word string ) {
15+ func query (word string , isMulti bool ) {
1616 var url string
1717 var doc * goquery.Document
1818 isChinese := isChinese (word )
@@ -62,6 +62,11 @@ func query(word string) {
6262 color .Green (" %s" , s .Find (".search-js" ).Text ())
6363 })
6464 } else {
65+ // Find the pronounce
66+ if ! isMulti {
67+ color .Green ("\r \n %s" , getPronounce (doc ))
68+ }
69+
6570 // Find the result
6671 result := doc .Find ("div#phrsListTab > div.trans-container > ul" ).Text ()
6772 color .Green (result )
@@ -79,6 +84,24 @@ func query(word string) {
7984 }
8085}
8186
87+ func getPronounce (doc * goquery.Document ) string {
88+ var pronounce string
89+ doc .Find ("div.baav > span.pronounce" ).Each (func (i int , s * goquery.Selection ) {
90+
91+ if i == 0 {
92+ p := fmt .Sprintf ("英: %s " , s .Find ("span.phonetic" ).Text ())
93+ pronounce += p
94+ }
95+
96+ if i == 1 {
97+ p := fmt .Sprintf ("美: %s" , s .Find ("span.phonetic" ).Text ())
98+ pronounce += p
99+ }
100+ })
101+
102+ return pronounce
103+ }
104+
82105func getSentences (doc * goquery.Document , isChinese bool ) [][]string {
83106 result := [][]string {}
84107 doc .Find ("#bilingual ul li" ).Each (func (_ int , s * goquery.Selection ) {
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const (
2020 ██║ ██████╔╝██║╚██████╗ ██║
2121 ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝
2222
23- YDict V0.6
23+ YDict V0.7
2424https://github.com/TimothyYe/ydict
2525
2626`
You can’t perform that action at this time.
0 commit comments