[FUNC]ahk利用JScript编码函数

;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
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值