也許是這樣的:
F2::
FileDelete, %A_Temp%\stackoverflow website.txt
FileDelete, %A_MyDocuments%\example.ahk
ClipSaved := ClipboardAll ; save clipboard
clipboard = "" ; empty clipboard
Send, ^l ; mark the adress in your browser
Sleep, 100
Send, ^c ; copy the adress
ClipWait 1 ; wait for the clipboard to contain data
If not ErrorLevel ; If NOT ErrorLevel clipwait found data on the clipboard
{
If !InStr(clipboard, "http://stackoverflow.com")
{
MsgBox, You're NOT in stackoverflow
clipboard := ClipSaved
return
}
; otherwise:
UrlDownloadToFile, %clipboard%, %A_Temp%\stackoverflow website.txt
Sleep, 200
FileRead, Contents, %A_Temp%\stackoverflow website.txt
{
Array := StrSplit(Contents, "code>")
for key, val in Array
{
If (SubStr(val, -1) = "</")
{
If (StrLen(val) < 50)
continue
If InStr(val, "WScript")
continue
; ... add more restrictions
val := SubStr(val, 1, -2)
MsgBox, 4,, Do you want to save this code? `n`n%val%
IfMsgBox Yes
{
FileAppend, %val%, %A_MyDocuments%\example.ahk ; save val to file
break
}
}
}
}
}
Sleep, 300
clipboard := ClipSaved ; restore original clipboard
FileDelete, %A_Temp%\stackoverflow website.txt
return
難道你希望你的腳本工作?當然你必須知道'^ a'選擇瀏覽器文檔中的所有文本,而不僅僅是當前選擇的「代碼框」。無論如何,由於現代瀏覽器不公開任何文檔內容,AHK無法讓你走得很遠。將本地JavaScript注入瀏覽器文檔(例如,使用[用戶腳本](https://wiki.greasespot.net/User_script))是最強大的選擇。 – MCL