-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest20.ahk
48 lines (42 loc) · 1.56 KB
/
test20.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#SingleInstance Force
#include d:\util\autohotkey\WinClipAPI.ahk
#include d:\util\autohotkey\WinClip.ahk
^t::
wc := new WinClip()
wc.iCopy() ; clear current inner buffer then send Ctrl+c
_sSearch := wc.iGetText()
translate(_sSearch)
Return
translate(sSearch) {
url := "https://tw.dictionary.search.yahoo.com/search?p=" . sSearch . "&fr=sfp&iscqry="
httpClient := ComObjCreate("WinHttp.WinHttpRequest.5.1")
httpClient.Open("POST", url, false) ; false=not async
;httpClient.SetRequestHeader("User-Agent", User-Agent)
;httpClient.SetRequestHeader("Content-Type", Content-Type)
;httpClient.SetRequestHeader("Cookie", Cookie)
httpClient.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
httpClient.Send()
httpClient.WaitForResponse()
Result := httpClient.ResponseText
html := ComObjCreate("HTMLFile")
html.write(Result)
elements := html.getElementsByTagName("div")
_sPronounce := "" ; 發音
_sNotion := "" ; 詞類
_sDictionaryExplanation := "" ; 解釋
Loop % elements.length
{
ele := elements[A_Index-1] ; zero based collection
_sClassName := ele.className
if (InStr(_sClassName, "pos_button") > 0) {
_sNotion := ele.innerText
} else if (InStr(_sClassName, "compList d-ib") > 0) {
_sPronounce := ele.innerText
} else if (InStr(_sClassName, "dictionaryExplanation") > 0) {
_sDictionaryExplanation .= _sNotion "`t" ele.innerText . "`r"
_sNotion := ""
}
}
MsgBox % sSearch "`r`r" _sPronounce "`r----------`r" _sDictionaryExplanation
return ""
}