Skip to content

Commit d5bda5a

Browse files
committed
Added: Support for input type "image" for _WinHttpSimpleFormFill.
1 parent a0c93f6 commit d5bda5a

File tree

1 file changed

+86
-23
lines changed

1 file changed

+86
-23
lines changed

WinHttp.au3

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,66 +2082,129 @@ Func __WinHttpNormalizeActionURL($sActionPage, ByRef $sAction, ByRef $iScheme, B
20822082
If $sMethod = "GET" Then $sEnctype = ""
20832083
EndFunc
20842084

2085-
Func __WinHttpHTML5FormAttribs($aDtas, $aFlds, $iNumParams, ByRef $aInput, ByRef $sAction, ByRef $sEnctype, ByRef $sMethod)
2086-
; Clicking "submit" is done using:
2085+
Func __WinHttpHTML5FormAttribs(ByRef $aDtas, ByRef $aFlds, ByRef $iNumParams, ByRef $aInput, ByRef $sAction, ByRef $sEnctype, ByRef $sMethod)
2086+
; Clicking "submit" or "image" is done using:
20872087
; "type:submit", zero_based_index_of_the_submit_button
2088+
; "type:image", zero_based_index_of_the_image_control Xcoord,Ycoord
20882089
; "name:whatever", True
20892090
; "id:whatever", True
20902091
; "whatever", True ;<- same as "id:whatever"
2091-
Local $aSpl, $iSubmitHTML5 = 0, $iInpSubm
2092+
Local $aSpl, $iSubmitHTML5 = 0, $iInpSubm, $sImgAppx = "."
20922093
For $k = 1 To $iNumParams
20932094
$aSpl = StringSplit($aFlds[$k], ":", 2)
2094-
If $aSpl[0] = "type" And $aSpl[1] = "submit" Then
2095-
Local $iSubmIndex = $aDtas[$k], $iSubmCur = 0
2095+
If $aSpl[0] = "type" And ($aSpl[1] = "submit" Or $aSpl[1] = "image") Then
2096+
Local $iSubmIndex = $aDtas[$k], $iSubmCur = 0, $iImgCur = 0, $sType, $sInpNme
2097+
If $aSpl[1] = "image" Then
2098+
$iSubmIndex = Int($aDtas[$k])
2099+
EndIf
20962100
For $i = 0 To UBound($aInput) - 1 ; for all input elements
2097-
If __WinHttpAttribVal($aInput[$i], "type") = "submit" Then
2098-
If $iSubmCur = $iSubmIndex Then
2099-
$iSubmitHTML5 = 1
2100-
$iInpSubm = $i
2101-
Else
2102-
$aInput[$i] = "" ; remove any other submit control
2103-
EndIf
2104-
$iSubmCur += 1
2105-
EndIf
2101+
Switch __WinHttpAttribVal($aInput[$i], "type")
2102+
Case "submit"
2103+
If $iSubmCur = $iSubmIndex Then
2104+
$iSubmitHTML5 = 1
2105+
$iInpSubm = $i
2106+
ExitLoop 2
2107+
EndIf
2108+
$iSubmCur += 1
2109+
Case "image"
2110+
If $iImgCur = $iSubmIndex Then
2111+
$iSubmitHTML5 = 1
2112+
$iInpSubm = $i
2113+
$sInpNme = __WinHttpAttribVal($aInput[$iInpSubm], "name")
2114+
If $sInpNme Then $sInpNme &= $sImgAppx
2115+
$aInput[$iInpSubm] = 'type="image" formaction="' & __WinHttpAttribVal($aInput[$iInpSubm], "formaction") & '" formenctype="' & __WinHttpAttribVal($aInput[$iInpSubm], "formenctype") & '" formmethod="' & __WinHttpAttribVal($aInput[$iInpSubm], "formmethod") & '"'
2116+
Local $sX = 0, $sY = 0
2117+
$iX = Int(StringRegExpReplace($aDtas[$k], "(\d+)\h*(\d+),(\d+)", "$2", 1))
2118+
$iY = Int(StringRegExpReplace($aDtas[$k], "(\d+)\h*(\d+),(\d+)", "$3", 1))
2119+
ReDim $aInput[UBound($aInput) + 2]
2120+
$aInput[UBound($aInput) - 2] = 'type="image" name="' & $sInpNme & 'x" value="' & $iX & '"'
2121+
$aInput[UBound($aInput) - 1] = 'type="image" name="' & $sInpNme & 'y" value="' & $iY & '"'
2122+
ExitLoop 2
2123+
EndIf
2124+
$iImgCur += 1
2125+
EndSwitch
21062126
Next
2107-
ElseIf $aSpl[0] = "name" Then
2108-
Local $sInpNme = $aSpl[1]
2127+
ElseIf $aSpl[0] = "name" Then
2128+
Local $sInpNme = $aSpl[1], $sType
21092129
For $i = 0 To UBound($aInput) - 1 ; for all input elements
2110-
If __WinHttpAttribVal($aInput[$i], "type") = "submit" Then
2130+
$sType = __WinHttpAttribVal($aInput[$i], "type")
2131+
If $sType = "submit" Then
21112132
If __WinHttpAttribVal($aInput[$i], "name") = $sInpNme And $aDtas[$k] = True Then
21122133
$iSubmitHTML5 = 1
21132134
$iInpSubm = $i
2114-
ExitLoop
2135+
ExitLoop 2
2136+
EndIf
2137+
ElseIf $sType = "image" Then
2138+
If __WinHttpAttribVal($aInput[$i], "name") = $sInpNme And $aDtas[$k] Then
2139+
$iSubmitHTML5 = 1
2140+
$iInpSubm = $i
2141+
Local $aStrSplit = StringSplit($aDtas[$k], ",", 3), $iX = 0, $iY = 0
2142+
If Not @error Then
2143+
$iX = Int($aStrSplit[0])
2144+
$iY = Int($aStrSplit[1])
2145+
EndIf
2146+
$aInput[$iInpSubm] = 'type="image" formaction="' & __WinHttpAttribVal($aInput[$iInpSubm], "formaction") & '" formenctype="' & __WinHttpAttribVal($aInput[$iInpSubm], "formenctype") & '" formmethod="' & __WinHttpAttribVal($aInput[$iInpSubm], "formmethod") & '"'
2147+
$sInpNme &= $sImgAppx
2148+
ReDim $aInput[UBound($aInput) + 2]
2149+
$aInput[UBound($aInput) - 2] = 'type="image" name="' & $sInpNme & 'x" value="' & $iX & '"'
2150+
$aInput[UBound($aInput) - 1] = 'type="image" name="' & $sInpNme & 'y" value="' & $iY & '"'
2151+
ExitLoop 2
21152152
EndIf
21162153
EndIf
21172154
Next
2118-
If $iSubmitHTML5 Then ExitLoop
21192155
Else ; id
2120-
Local $sInpId
2156+
Local $sInpId, $sType
21212157
If @error Then
21222158
$sInpId = $aSpl[0]
21232159
ElseIf $aSpl[0] = "id" Then
21242160
$sInpId = $aSpl[1]
21252161
EndIf
21262162
For $i = 0 To UBound($aInput) - 1 ; for all input elements
2127-
If __WinHttpAttribVal($aInput[$i], "type") = "submit" Then
2163+
$sType = __WinHttpAttribVal($aInput[$i], "type")
2164+
If $sType = "submit" Then
21282165
If __WinHttpAttribVal($aInput[$i], "id") = $sInpId And $aDtas[$k] = True Then
21292166
$iSubmitHTML5 = 1
21302167
$iInpSubm = $i
2131-
ExitLoop
2168+
ExitLoop 2
2169+
EndIf
2170+
ElseIf $sType = "image" Then
2171+
If __WinHttpAttribVal($aInput[$i], "id") = $sInpId And $aDtas[$k] Then
2172+
$iSubmitHTML5 = 1
2173+
$iInpSubm = $i
2174+
Local $sInpNme = __WinHttpAttribVal($aInput[$iInpSubm], "name")
2175+
If $sInpNme Then $sInpNme &= $sImgAppx
2176+
Local $aStrSplit = StringSplit($aDtas[$k], ",", 3), $iX = 0, $iY = 0
2177+
If Not @error Then
2178+
$iX = Int($aStrSplit[0])
2179+
$iY = Int($aStrSplit[1])
2180+
EndIf
2181+
$aInput[$iInpSubm] = 'type="image" formaction="' & __WinHttpAttribVal($aInput[$iInpSubm], "formaction") & '" formenctype="' & __WinHttpAttribVal($aInput[$iInpSubm], "formenctype") & '" formmethod="' & __WinHttpAttribVal($aInput[$iInpSubm], "formmethod") & '"'
2182+
ReDim $aInput[UBound($aInput) + 2]
2183+
$aInput[UBound($aInput) - 2] = 'type="image" name="' & $sInpNme & 'x" value="' & $iX & '"'
2184+
$aInput[UBound($aInput) - 1] = 'type="image" name="' & $sInpNme & 'y" value="' & $iY & '"'
2185+
ExitLoop 2
21322186
EndIf
21332187
EndIf
21342188
Next
2135-
If $iSubmitHTML5 Then ExitLoop
21362189
EndIf
21372190
Next
21382191
If $iSubmitHTML5 Then
2192+
Local $iUbound = UBound($aInput) - 1
2193+
If __WinHttpAttribVal($aInput[$iInpSubm], "type") = "image" Then $iUbound -= 2 ; two form fields are added for "image"
2194+
For $j = 0 To $iUbound ; for all other input elements
2195+
If $j = $iInpSubm Then ContinueLoop
2196+
Switch __WinHttpAttribVal($aInput[$j], "type")
2197+
Case "submit", "image"
2198+
$aInput[$j] = "" ; remove any other submit/image controls
2199+
EndSwitch
2200+
Next
21392201
Local $sAttr = __WinHttpAttribVal($aInput[$iInpSubm], "formaction")
21402202
If $sAttr Then $sAction = $sAttr
21412203
$sAttr = __WinHttpAttribVal($aInput[$iInpSubm], "formenctype")
21422204
If $sAttr Then $sEnctype = $sAttr
21432205
$sAttr = __WinHttpAttribVal($aInput[$iInpSubm], "formmethod")
21442206
If $sAttr Then $sMethod = $sAttr
2207+
If __WinHttpAttribVal($aInput[$iInpSubm], "type") = "image" Then $aInput[$iInpSubm] = ""
21452208
EndIf
21462209
EndFunc
21472210

0 commit comments

Comments
 (0)