runany是一款使用ahk写的强大工具
个人写了一些ra的插件在社区上分享
这次谷歌翻译炸了,所以弄了个有道接口的翻译,修改自随机大佬的翻译文章,改造成了ra插件
源码分享
-
;************************ ;* 【ObjReg插件脚本 1】 ;************************ global RunAny_Plugins_Version:="1.0.0" #NoTrayIcon ;~不显示托盘图标 #Persistent ;~让脚本持久运行 #SingleInstance,Force ;~运行替换旧实例 ;******************************************************************************** ; Finally, after years of hard work, there is a new major release of Vim. Besides many additions and fixes, the main new item is the support for Vim9 script. You can go straight to the Download page and try it out. Or read the announcement. (Bram Moolenaar) #Include %A_ScriptDir%\RunAny_ObjReg.ahk class RunAnyObj { yd(getZz){ MouseGetPos,x,y text = % youdao_translation(remove_punctuation(getZz)) ;单行宽度 If (StrLen(text)>=70){ i := 1 Loop, % StrLen(text)/70+1{ text1 .= SubStr(text, i, 70) text1 .= "`n" i += 70 } } Else text1 := text tooltip,%text1%,%x%,%y%,1 Clipboard:=text1 SetTimer,rebt,2000 Return } } rebt: tooltip return ;翻译主函数 youdao_translation(text){ Url=http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null postdata=type=AUTO&i=%text%&doctype=json&xmlVersion=1.4&keyfrom=fanyi.web&ue=UTF-8&typoResult=true&flag=false youdaoreText:= byteToStr(WinHttp(Url,"POST",postdata),"utf-8") NeedleRegEx=O)tgt":"(.*?)" FoundPos:=RegExMatch(youdaoreText,NeedleRegEx,OutMatch) youdaoValue:=(ErrorLevel) ? :OutMatch.Value(1) NeedleRegEx=O)entries":["","(.*?)" FoundPos:=RegExMatch(youdaoreText,NeedleRegEx,OutMatch) youdaoValue.=(! ErrorLevel and OutMatch.Value(1)="") ? : Return youdaoValue } ;发送接收数据 WinHttp(Httpurl,Httpmode="GET",Httppostdata=""){ StringUpper Httpmode,Httpmode ;~ XMLHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") XMLHTTP := ComObjCreate("Microsoft.XMLHTTP") XMLHTTP.open(Httpmode,Httpurl,false) XMLHTTP.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0") if Httpmode=POST { XMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") XMLHTTP.send(Httppostdata) }else XMLHTTP.send() ;~ return XMLHTTP.responseText return XMLHTTP.ResponseBody } ;将原始数据流以指定的编码的形式读出 byteToStr(body, charset){ Stream := ComObjCreate("Adodb.Stream") Stream.Type := 1 Stream.Mode := 3 Stream.Open() Stream.Write(body) Stream.Position := 0 Stream.Type := 2 Stream.Charset := charset str := Stream.ReadText() Stream.Close() return str } ;去除文本中的标点 remove_punctuation(text){ punctuation := [",", ".", "!", "`n", "?", """", ";"] For k, v in punctuation{ text1 := StrReplace(text, v, " ") text := text1 } Return text }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
哇,好厉害,感谢分享,我去试一下
收藏了
有用 顶你