;sunwind 整理
;2013-5-26 13:17:31
;~ 编码函数,它输出符号的utf-8形式
MsgBox % encode2UTF8("测试")
encode2UTF8(Uri)
{
oSC := ComObjCreate("ScriptControl")
oSC.Language := "JScript"
Script := "var Encoded = encodeURI(""" . Uri . """)"
oSC.ExecuteStatement(Script)
Return, oSC.Eval("Encoded")
}
;~ http://www.autohotkey.com/board/topic/54431-scite4autohotkey-v300101-updated-nov-30-2012/page-44?hl=winhttp.winhttprequest#entry536165
SetTitleMatchMode, 2
WinGet, HWND, ID, SciTE4AutoHotkey
Gui, Add, Edit, w100 vDesc, Pasted by SciTE
Gui, Add, Edit, w100 vAuthor, GeekDude
Gui, Add, Button, w100, Paste
Gui, +Owner%HWnd% +ToolWindow
Gui, Show,, Paste
return
Buttonpaste:
Gui, Submit
Gui, Destroy
Gui, 1:Submit, NoHide
oSciTE := ComObjActive("SciTE4AHK.Application")
AhkBin(oSciTE.Document, Author, Desc, 1)
ExitApp
AhkBin(Txt, Author="GeekDude", Desc="Pasted by SciTE", Public=0)
{
URL := "http://www.autohotkey.net/paste/"
POST:= "MAX_FILE_SIZE=262144"
. "&jscheck="
. "&text=" . UriEncode(Txt)
. "&author=" . Author
. "&description=" . UriEncode(Desc)
. "&irc=" . (Public ? 100 : 0)
. "&submit=Paste"
Pbin := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Pbin.Open("POST", URL)
Pbin.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Pbin.Send(POST)
RegExMatch(Pbin.ResponseText, "<title>Paste #(.*?)</title>", pb_url)
File := FileOpen("Pastes.txt", "rw")
Txt .= File.Read()
File.pos := 0
File.Write(A_Now . "|" . URL . pb_url1 . "|" . Desc . "`r`n" . Txt)
File.Close()
if public
return URL . pb_url1
return
}
UriEncode(Uri)
{
oSC := ComObjCreate("ScriptControl")
oSC.Language := "JScript"
Script := "var Encoded = encodeURIComponent(""" . FixJS(Uri) . """)"
oSC.ExecuteStatement(Script)
return oSC.Eval("Encoded")
}
UriDecode(Uri)
{
oSC := ComObjCreate("ScriptControl")
oSC.Language := "JScript"
Script := "var Decoded = decodeURIComponent(""" . Uri . """)"
oSC.ExecuteStatement(Script)
return oSC.Eval("Decoded")
}
FixJS(JS)
{
StringReplace, JS, JS, \, \\, All ; Backslash
StringReplace, JS, JS, `b, \b, All ; Backspace
StringReplace, JS, JS, `f, \f, All ; Form feed
StringReplace, JS, JS, `n, \n, All ; New line
StringReplace, JS, JS, `r, \r, All ; Carriage return
StringReplace, JS, JS, `t, \t, All ; Tab
StringReplace, JS, JS, `v, \v, All ; Vertical tab
StringReplace, JS, JS, ', \', All ; Single quote
StringReplace, JS, JS, `", \`", All ; Double quote
return JS
}
本文由 Rinvay 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jun 17, 2018 at 01:52 pm