Code:
#NoEnv
SetWorkingDir %A_ScriptDir%
;=============================
Pwb := ComObjCreate("InternetExplorer.Application")
Pwb.Visible := True
Return
;=============================
!z::
;==============
IfNotExist, AmazonCodes.txt
Return
FileRead, e, EnteredCodes.txt
FileRead, c, AmazonCodes.txt
StringReplace, c, c, `r`n, ^, All
StringSplit, ca, c, ^
Loop, %ca0%
{
d := ca%A_Index%
StringSplit, da, d, |
Code := da1
If A_Index = 1
Msgbox, %Code%
IfInString, e, %Code%
Continue
Pwb.Document.getElementsByName("claimCode")[0].value := Code
Pwb.Document.getElementsByName("applytoaccount")[0].click()
IELoad(Pwb)
Sleep, 1000
filedelete, html.txt
html := Pwb.Document.DocumentElement.innerHTML
fileappend, %html%, html.txt
IfNotInString, html, gift card has been applied to your account
{
Msgbox, 64, Amazon Enterer, Failed to enter the code...
Pwb.Navigate("https://www.amazon.com/gp/gc/payment")
IELoad(Pwb)
Continue
}
FileAppend, %Code%`r`n, EnteredCodes.txt
Pwb.Navigate("https://www.amazon.com/gp/css/gc/payment/view-gc-balance?ie=UTF8&ref_=gc_lp_wl3_atya_red_new2")
IELoad(Pwb)
Sleep, 1000
}
Return
;=============================
IELoad(Pwb) ;You need to send the IE handle to the function unless you define it as global.
{
If !Pwb ;If Pwb is not a valid pointer then quit
Return False
Loop ;Otherwise sleep for .1 seconds untill the page starts loading
Sleep,100
Until (Pwb.busy)
Loop ;Once it starts loading wait until completes
Sleep,100
Until (!Pwb.busy)
Loop ;optional check to wait for the page to completely load
Sleep,100
Until (Pwb.Document.Readystate = "Complete")
Return True
}
0 comments:
Post a Comment