[UDF] Firefox (FF.au3)


SUBMITTED BY: Guest

DATE: May 28, 2013, 6:28 a.m.

FORMAT: Text only

SIZE: 177.2 kB

HITS: 3791

  1. ; :wrap=none:collapseFolds=1:maxLineLen=80:mode=autoitscript:tabSize=8:folding=indent:
  2. ; created with jEdit4AutoIt
  3. #include-once
  4. #Region Copyright
  5. #cs
  6. * FF.au3
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #ce
  22. #EndRegion Copyright
  23. #Region Many thanks to:
  24. #cs
  25. - Jonathan Bennett and the AutoIt Team for AutoIt v3 the freeware
  26. BASIC-like scripting language
  27. (and thanks John George Kemeny and Thomas Eugene Kurtz for BASIC)
  28. - Dale Hohm, for his great IE.au3, which I've used as base for the
  29. functions-names and the error handling.
  30. - Johannes Schirmer, for some functions and suggestions for the FF.au3
  31. - all others for their suggestions, bug reports ...
  32. - the FireFox-Team for his fantastic browser
  33. - and Massimiliano Mirra, without his work would this UDF impossible,
  34. for MozLab / MozRepl
  35. #ce
  36. #EndRegion Many thanks to:
  37. #Region #CURRENT# ==============================================================
  38. ;_FFAction
  39. ;_FFClick
  40. ;_FFCmd
  41. ;_FFConnect
  42. ;_FFDialogWait
  43. ;_FFDisConnect
  44. ;_FFDispatchEvent
  45. ;_FFFormCheckBox
  46. ;_FFFormGetElementsLength
  47. ;_FFFormOptionSelect
  48. ;_FFFormRadioButton
  49. ;_FFFormReset
  50. ;_FFFormSubmit
  51. ;_FFFrameEnter
  52. ;_FFFrameLeave
  53. ;_FFGetLength
  54. ;_FFGetObjectInfo
  55. ;_FFGetPosition
  56. ;_FFGetValue
  57. ;_FFImageClick
  58. ;_FFImageGetBySize
  59. ;_FFImageMapClick
  60. ;_FFIsConnected
  61. ;_FFLinkClick
  62. ;_FFLinksGetAll
  63. ;_FFLoadWait
  64. ;_FFLoadWaitTimeOut
  65. ;_FFObj
  66. ;_FFObjDelete
  67. ;_FFObjGet
  68. ;_FFObjNew
  69. ;_FFOpenURL
  70. ;_FFPrefGet
  71. ;_FFPrefReset
  72. ;_FFPrefSet
  73. ;_FFQuit
  74. ;_FFReadHTML
  75. ;_FFReadText
  76. ;_FFSearch
  77. ;_FFSetValue
  78. ;_FFStart
  79. ;_FFTabAdd
  80. ;_FFTabClose
  81. ;_FFTabDuplicate
  82. ;_FFTabExists
  83. ;_FFTabGetSelected
  84. ;_FFTabSetSelected
  85. ;_FFTableWriteToArray
  86. ;_FFWindowClose
  87. ;_FFWindowGetHandle
  88. ;_FFWindowOpen
  89. ;_FFWindowSelect
  90. ;_FFWriteHTML
  91. ;_FFXPath
  92. #EndRegion #CURRENT# ===========================================================
  93. #Region Description
  94. ; ==============================================================================
  95. ; UDF ...........: FF.au3
  96. Global Const $_FF_AU3VERSION = "0.6.0.0b-5"
  97. ; Description ...: An UDF for FireFox automation.
  98. ; Requirement ...: MozRepl AddOn:
  99. ; http://hyperstruct.net/projects/mozlab
  100. ; http://wiki.github.com/bard/mozrepl/home
  101. ; Author(s) .....: Thorsten Willert, Johannes Schirmer
  102. ; Date ..........: Fri Nov 13 18:32:04 CET 2009 @772 /Internet Time/
  103. ; FireFox Version: Firefox/3.5.3 (required 3.x.x)
  104. ; AutoIt Version : v3.3.0.0
  105. ; ==============================================================================
  106. #cs
  107. V0.6.0.0b-5
  108. - Added: _FFWindowOpen: new parameter: $bLoadWait
  109. - Added: _FFAu3Option / $_FF_SEARCH_MODE = 0 ; 0 = Substring / 1 = Compare
  110. _FFImageClick
  111. - Removed: _FFSetValueById, _FFSetValueByName ==> _FFSetValue
  112. - Removed: _FFGetValueById, _FFGetValueByName ==> _FFGetValue
  113. - Removed: _FFFormGetLength ==> _FFGetLength
  114. - Removed: _FFTabGetLength ==> _FFGetLength
  115. - Removed: _FFTableGetCell ==> _FFXpath
  116. - Removed: _FFDisPatchKeyEvent ==> _FFDisPatchEvent
  117. - Removed: _FFTabCloseAll ==> _FFTabClose
  118. - Removed: _FFFormGetElementsLength: now only returns the DOM-standard length
  119. - Removed: _FFRecord* functions and all additions for them in all functions
  120. - Changed: _FFAction("copy"): works now only on the current frame
  121. - Fixed: _FFFormGetElementsLength: Error Message
  122. - Fixed: _FFDispatchEvent: Shortcut for elements
  123. For compatibily for older scripts, please use this UDF:
  124. http://thorsten-willert.de/Themen/FFau3/FF.au3/FFEx.au3
  125. ToDo:
  126. Textsuche (name, id, text ...) per Substring, String, RegEx
  127. Events fuer die _FFForm* Funktionen
  128. #ce
  129. #EndRegion Description
  130. #Region Global Constants
  131. Global Const $_FF_PROC_NAME = "firefox.exe" ; Firefox process name
  132. Global Const $_FF_COM_DELAY_MAX = 300 ; alternative connection delay in ms
  133. Global Enum $_FF_ERROR_Success = 0, _ ; No error
  134. $_FF_ERROR_GeneralError, _ ; General error
  135. $_FF_ERROR_SocketError, _ ; No socket
  136. $_FF_ERROR_InvalidDataType, _ ; Invalid data type (IP, URL, Port ...)
  137. $_FF_ERROR_InvalidValue, _ ; Invalid value in function-call
  138. $_FF_ERROR_SendRecv, _ ; Send / Recv Error
  139. $_FF_ERROR_Timeout, _ ; Connection / Send / Recv timeout
  140. $_FF_ERROR___UNUSED, _ ;
  141. $_FF_ERROR_NoMatch, _ ; No match for _FFAction-find/search _FFGetElement...
  142. $_FF_ERROR_RetValue, _ ; Error echo from Repl e.g. _FFAction("fullscreen","true") <> "true"
  143. $_FF_ERROR_ReplException, _ ; Exception from MozRepl / FireFox
  144. $_FF_ERROR_InvalidExpression ; Invalid expression in XPath query or RegEx
  145. #EndRegion Global Constants
  146. #Region Global Variables
  147. Global $_FF_GLOBAL_SOCKET = -1 ; Socket
  148. Global $_FF_CON_DELAY ; Connection Delay
  149. Global $_FF_LOADWAIT_TIMEOUT = 120000
  150. Global $_FF_COM_TRACE = True ; Trace communication to console (debugging)
  151. Global $_FF_ERROR_MSGBOX = True ; Shows in compiled scripts error messages in msgboxes
  152. Global $_FF_FRAME = 'top'
  153. Global $_FF_SEARCH_MODE = 0 ; 0 = Substring / 1 = Compare
  154. #EndRegion Global Variables
  155. ; #FUNCTION# ===================================================================
  156. ; Name ..........: _FFAction
  157. ; Description ...: Some standard actions to work with FireFox
  158. ; Beschreibung ..: Standardaktionen in FireFox
  159. ; AutoIt Version : V3.3.0.0
  160. ; Syntax ........: _FFAction($sAction[, $vOption = ""[, $vOption2 = ""[, $bLoadWait = True]]])
  161. ; Parameter(s): .: $sAction - one of the following actions:
  162. ; | about
  163. ; | alert
  164. ; | back
  165. ; | blank
  166. ; | copy
  167. ; | fullscreen / fs
  168. ; | hideall
  169. ; | home
  170. ; | maximize / max
  171. ; | minimize / min
  172. ; | presentationmode / pm
  173. ; | print
  174. ; | reload
  175. ; | resetconsole
  176. ; | restore
  177. ; | scrollXY
  178. ; | stop
  179. ; | zoom
  180. ; $vOption - Optional: (Default = "") :
  181. ; $vOption2 - Optional: (Default = "") :
  182. ; $bLoadWait - Optional: (Default = true) :
  183. ; Return Value ..: Success - Return-value from MozRepl (sometimes an empty string!!!)
  184. ; Failure - ""
  185. ; @ERROR -
  186. ; Author(s) .....: Thorsten Willert
  187. ; Date ..........: Fri Nov 06 22:12:29 CET 2009
  188. ; Link ..........: http://developer.mozilla.org/en/docs/XUL:tabbrowser, http://developer.mozilla.org/en/docs/XUL:Method:reloadWithFlags, https://developer.mozilla.org/En/DOM/Window.scrollBy, http://kb.mozillazine.org/About_Protocol_Links
  189. ; Related .......:
  190. ; Example .......: Yes
  191. ; ==============================================================================
  192. Func _FFAction($sAction, $vOption = "", $vOption2 = "", $bLoadWait = True)
  193. Local Const $sFuncName = "_FFAction"
  194. Local $sCommand
  195. Local $sActionL = StringLower($sAction)
  196. Select
  197. Case $sActionL = "back"
  198. $sCommand = "gBrowser.goBack()"
  199. Case $sActionL = "home"
  200. $sCommand = "gBrowser.goHome()"
  201. Case $sActionL = "forward"
  202. $sCommand = "gBrowser.goForward()"
  203. Case $sActionL = "copy"
  204. Return _FFCmd(".getSelection()", $_FF_CON_DELAY + 100)
  205. Case $sActionL = "reload" And $vOption <> ""
  206. $sCommand = "gBrowser.reloadWithFlags('" & $vOption & "')"
  207. Case $sActionL = "reload"
  208. $sCommand = "gBrowser.reload()"
  209. Case $sActionL = "fullscreen" Or $sActionL = "fs" And $vOption
  210. $sCommand = "fullScreen=true"
  211. $bLoadWait = False
  212. Case $sActionL = "fullscreen" Or $sActionL = "fs" And Not $vOption
  213. $sCommand = "fullScreen=false"
  214. $bLoadWait = False
  215. Case $sActionL = "minimize" Or $sActionL = "min"
  216. $bLoadWait = False
  217. $sCommand = "minimize()"
  218. Case $sActionL = "maximize" Or $sActionL = "max"
  219. $bLoadWait = False
  220. $sCommand = "maximize()"
  221. Case $sActionL = "restore"
  222. $bLoadWait = False
  223. $sCommand = "restore()"
  224. Case $sActionL = "stop"
  225. $bLoadWait = False
  226. $sCommand = "gBrowser.stop()"
  227. Case $sActionL = "print"
  228. $bLoadWait = False
  229. $sCommand = "content.print()"
  230. Case $sActionL = "find" Or $sActionL = "search"
  231. _FFLoadWait()
  232. $sCommand = "content.find()"
  233. Case $sActionL = "hideall" And $vOption
  234. Return _FFCmd("toggleAffectedChrome(true);")
  235. Case $sActionL = "hideall" And Not $vOption
  236. Return _FFCmd("toggleAffectedChrome(false);")
  237. Case $sActionL = "presentationmode" Or $sActionL = "pm" And $vOption
  238. Return _FFCmd("toggleAffectedChrome(true)" & @CRLF & "fullScreen=true")
  239. Case $sActionL = "presentationmode" Or $sActionL = "pm" And Not $vOption
  240. Return _FFCmd("toggleAffectedChrome(false)" & @CRLF & "fullScreen=false")
  241. Case $sActionL = "alert" And $vOption <> ""
  242. $sCommand = 'alert("' & $vOption & '")'
  243. $bLoadWait = False
  244. Case $sActionL = "chrome" And $vOption <> ""
  245. $sCommand = '.location.href="' & __FFChromeSelect($vOption) & '"'
  246. Case $sActionL = "blank"
  247. $vOption = "blank"
  248. ContinueCase
  249. Case $sActionL = "about"
  250. $sCommand = '.location.href="about:' & $vOption & '"'
  251. Case $sActionL = "scrollxy" And IsInt($vOption) And IsInt($vOption2)
  252. $sCommand = "window.content.scrollBy(" & $vOption & "," & $vOption2 & ");"
  253. $bLoadWait = False
  254. Case $sActionL = "zoom" And $vOption = ""
  255. $vOption = 1
  256. ContinueCase
  257. Case $sActionL = "zoom" And IsNumber($vOption)
  258. $sCommand = "gBrowser.selectedBrowser.markupDocumentViewer.fullZoom=" & $vOption
  259. $bLoadWait = False
  260. Case $sActionL = "resetconsole"
  261. $sCommand = ";" & @CRLF & "repl.home()"
  262. $bLoadWait = False
  263. Case Else
  264. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$sAction: " & $sAction & " or " & "$vOption :" & $vOption & " or " & "$vOption2 :" & $vOption2))
  265. Return ""
  266. EndSelect
  267. Local $sRet = _FFCmd($sCommand)
  268. If Not @error Then
  269. If $bLoadWait Then _FFLoadWait()
  270. Return $sRet
  271. Else
  272. SetError(@error)
  273. Return ""
  274. EndIf
  275. EndFunc ;==>_FFAction
  276. ; #FUNCTION# ===================================================================
  277. ; Name ..........: _FFClick
  278. ; Description ...: Simulates a click on an element.
  279. ; Beschreibung ..: Simuliert einen Klick auf ein Element.
  280. ; AutoIt Version : V3.3.0.0
  281. ; Syntax ........: _FFClick($sElement[, $sMode = "elements"[, $iIndex = 0]])
  282. ; Parameter(s): .: $sElement - Element to click on
  283. ; $sMode - Optional: (Default = "elements") :
  284. ; | elements
  285. ; | id
  286. ; | name
  287. ; | class
  288. ; | tag
  289. ; $iIndex - Optional: (Default = 0) : Index if $sMode = class, name, tag
  290. ; Return Value ..: Success - 1
  291. ; Failure - 0
  292. ; @ERROR -
  293. ; Author(s) .....: Thorsten Willert
  294. ; Date ..........: Fri Sep 25 12:01:48 CEST 2009 @459 /Internet Time/
  295. ; Link ..........:
  296. ; Related .......: _FFImageClick, _FFLinkClick
  297. ; Example .......: Yes
  298. ; ==============================================================================
  299. Func _FFClick($sElement, $sMode = "elements", $iIndex = 0)
  300. Local Const $sFuncName = "_FFClick"
  301. If Not IsInt($iIndex) Then
  302. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iIndex: " & $iIndex))
  303. Return 0
  304. EndIf
  305. Switch StringLower($sMode)
  306. Case "elements"
  307. If StringLeft($sElement, 7) = "OBJECT|" Then $sElement = StringMid($sElement, 8)
  308. Case "id"
  309. $sElement = ".getElementById('" & $sElement & "')"
  310. Case "name"
  311. $sElement = ".getElementsByName('" & $sElement & "')[" & $iIndex & "]"
  312. Case "class"
  313. $sElement = ".getElementsByClassName('" & $sElement & "')[" & $iIndex & "]"
  314. Case "tag"
  315. $sElement = ".getElementsByTagName('" & $sElement & "')[" & $iIndex & "]"
  316. Case Else
  317. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(elements|id|name|class|tag) $sMode: " & $sMode))
  318. Return 0
  319. EndSwitch
  320. If StringLeft($sElement, 1) = "." Then $sElement = "window.content.document" & $sElement
  321. Local $RetVal = _FFCmd("FFau3.simulateEvent(" & $sElement & ",'MouseEvents','click');")
  322. If Not @error And $RetVal <> "_FFCmd_Err" And $RetVal = 1 Then
  323. Sleep(25)
  324. Return $RetVal
  325. Else
  326. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sElement: " & $sElement))
  327. Return 0
  328. EndIf
  329. EndFunc ;==>_FFClick
  330. ; #FUNCTION# ===================================================================
  331. ; Name ..........: _FFDialogWait
  332. ; Description ...: Waits for a browser-dialog-message (e.g. alert) and closes it.
  333. ; Beschreibung ..: Wartet auf ein Dialog-Fenster (z.B.: alert) und schließt es.
  334. ; AutoIt Version : V3.3.0.0
  335. ; Syntax ........: _FFDialogWait($sText[, $sTitle = ""[, $sClose = "close"[, $iTimeOut = 10000]]])
  336. ; Parameter(s): .: $sText - Text in the dialog (substring)
  337. ; $sTitle - Optional: (Default = "") : Window-title of the dialog (substring)
  338. ; $bClose - Optional: (Default = "close") :
  339. ; | close = Just closes the dialog window
  340. ; | open = Do nothing
  341. ; | ok = Uses the "ok"-button
  342. ; | cancel = Uses the"cancel"-button
  343. ; $iTimeOut - Optional: (Default = 10000) : Timeout for waiting (min. 1000ms)
  344. ; Return Value ..: Success - 1
  345. ; Failure - 0
  346. ; @ERROR -
  347. ; Author(s) .....: Thorsten Willert
  348. ; Date ..........: Tue Apr 14 12:18:08 CEST 2009
  349. ; Link ..........:
  350. ; Related .......: _FFLoadWait
  351. ; Example .......: Yes
  352. ; ==============================================================================
  353. Func _FFDialogWait($sText, $sTitle = "", $sClose = "close", $iTimeOut = 10000)
  354. Local Const $sFuncName = "_FFDialogWait"
  355. If $sTitle = "" And $sText = "" Then
  356. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "Empty String: $sText and $sTitle"))
  357. Return 0
  358. EndIf
  359. If $sClose = Default Then $sClose = "close"
  360. If $iTimeOut < 1000 Then $iTimeOut = 1000
  361. Local $bFound = False, $b1 = False, $b2 = False
  362. Local $iTimer = TimerInit()
  363. While TimerDiff($iTimer) < $iTimeOut
  364. If _FFCmd('FFau3.obj=Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("").window;' & _
  365. 'FFau3.obj.document.documentURI') = "chrome://global/content/commonDialog.xul" Then
  366. If $sTitle <> "" Then
  367. If StringInStr(_FFCmd("FFau3.obj.title"), $sTitle) Then $b1 = True
  368. EndIf
  369. If $sText <> "" Then
  370. If StringInStr(_FFCmd("FFau3.obj.document.documentElement.textContent"), $sText) Then $b2 = True
  371. EndIf
  372. Select
  373. Case $sTitle = "" And $sText <> "" And Not $b1 And $b2
  374. $bFound = True
  375. Case $sTitle <> "" And $sText <> "" And $b1 And $b2
  376. $bFound = True
  377. Case $sTitle <> "" And $sText = "" And $b1 And Not $b2
  378. $bFound = True
  379. Case Else
  380. $bFound = False
  381. EndSelect
  382. If $bFound Then
  383. Switch StringLower($sClose)
  384. Case "close" ; just close the window
  385. _FFCmd("FFau3.obj.close()")
  386. Case "ok"
  387. _FFCmd("FFau3.obj.document.documentElement.acceptDialog()")
  388. Case "cancel"
  389. _FFCmd("FFau3.obj.document.documentElement.cancelDialog()")
  390. Case "open" ; do nothing
  391. Case Else
  392. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$sClose: " & $sClose))
  393. Return 0
  394. EndSwitch
  395. Return 1
  396. EndIf
  397. EndIf
  398. Sleep(500)
  399. WEnd
  400. SetError(__FFError($sFuncName, $_FF_ERROR_Timeout, Round(TimerDiff($iTimer)) & "ms > " & $iTimeOut & "ms"))
  401. Return 0
  402. EndFunc ;==>_FFDialogWait
  403. ; #FUNCTION# ===================================================================
  404. ; Name ..........: _FFImageClick
  405. ; Description ...: Clicks an image-link.
  406. ; Beschreibung ..: Klickt einen Image-Link.
  407. ; AutoIt Version : V3.3.0.0
  408. ; Syntax ........: _FFImageClick($vSearch[, $sMode = "src"[, $bLoadWait = True]])
  409. ; Parameter(s): .: $vSearch - String to search or number (0-n) in index mode (the search is performed in the attributes of the image and the link)
  410. ; $sMode - Optional: (Default = "src") :
  411. ; | alt
  412. ; | href
  413. ; | id
  414. ; | index
  415. ; | name
  416. ; | src
  417. ; | title
  418. ; $bLoadWait - Optional: (Default = True) :
  419. ; Return Value ..: Success - 1
  420. ; Failure - 0
  421. ; @ERROR -
  422. ; Author(s) .....: Thorsten Willert
  423. ; Date ..........: Mon Nov 09 19:02:40 CET 2009
  424. ; Link ..........:
  425. ; Related .......: _FFClick, _FFLinkClick, _FFImageMapClick
  426. ; Example .......: Yes
  427. ; ==============================================================================
  428. Func _FFImageClick($vSearch, $sMode = "src", $bLoadWait = True)
  429. Local Const $sFuncName = "_FFImageClick"
  430. Local $sX
  431. $sMode = StringLower($sMode)
  432. Switch $sMode
  433. Case "index"
  434. If Not IsInt($vSearch) Then
  435. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vSearch: " & $vSearch))
  436. Return 0
  437. EndIf
  438. $sX = ".images[" & $vSearch & "]"
  439. Case "id", "src", "href", "alt", "name", "title"
  440. Switch $_FF_SEARCH_MODE
  441. Case 0
  442. $sX = "contains(@" & $sMode & ",'" & $vSearch & "')"
  443. Case 1
  444. $sX = "@" & $sMode & "='" & $vSearch & "')"
  445. EndSwitch
  446. Case Else
  447. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(src|href|alt|name|title|id|index) $sMode: " & $sMode))
  448. Return 0
  449. EndSwitch
  450. If $sMode <> "index" Then
  451. If _FFClick( _FFXPath("//a//img[" & $sX & "] | //a[" & $sX & "]//img", "", 9) ) Then
  452. If $bLoadWait Then Return _FFLoadWait()
  453. Return 1
  454. EndIf
  455. Else
  456. If _FFClick( $sX ) Then
  457. If $bLoadWait Then Return _FFLoadWait()
  458. Return 1
  459. EndIf
  460. EndIf
  461. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$vSearch: " & $vSearch))
  462. Return 0
  463. EndFunc ;==>_FFImageClick
  464. ; #FUNCTION# ===================================================================
  465. ; Name ..........: _FFImageMapClick
  466. ; Description ...: Clicks on area of an image-map
  467. ; Beschreibung ..: Klickt auf ein Area einer Image-map
  468. ; AutoIt Version : V3.3.0.0
  469. ; Syntax ........: _FFImageMapClick($vArea[, $sModeArea = "index"[, $vMap = 0[, $sModeMap = "index"[, $bLoadWait = True]]]])
  470. ; Parameter(s): .: $vArea - (substring)
  471. ; $sModeArea - Optional: (Default = "index") :
  472. ; | alt
  473. ; | class
  474. ; | coords
  475. ; | href
  476. ; | id
  477. ; | index
  478. ; | name
  479. ; | title
  480. ; $vMap - Optional: (Default = 0) : (substring)
  481. ; $sModeMap - Optional: (Default = "index") :
  482. ; | class
  483. ; | id
  484. ; | index
  485. ; | name
  486. ; | title
  487. ; $bLoadWait - Optional: (Default = True) :
  488. ; Return Value ..: Success - 1
  489. ; Failure - 0
  490. ; @ERROR -
  491. ; Author(s) .....: Thorsten Willert
  492. ; Date ..........: Mon Sep 28 10:39:55 CEST 2009
  493. ; Related .......: _FFClick, _FFLinkClick, _FFImageClick
  494. ; Example .......: Yes
  495. ; ==============================================================================
  496. Func _FFImageMapClick($vArea, $sModeArea = "index", $vMap = 0, $sModeMap = "index", $bLoadWait = True)
  497. Local Const $sFuncName = "_FFImageMapClick"
  498. Local $sXPath
  499. $sModeArea = StringLower($sModeArea)
  500. $sModeMap = StringLower($sModeMap)
  501. Switch $sModeMap
  502. Case "index"
  503. If Not IsInt($vMap) Then
  504. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vMap: " & $vMap))
  505. Return 0
  506. EndIf
  507. $sXPath = "//map[" & $vMap + 1 & "]"
  508. Case "id", "name", "title", "class"
  509. $sXPath = "//map[contains(@" & $sModeMap & ",'" & $vMap & "')]"
  510. Case Else
  511. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(name|title|id|index|class) $sModeMap: " & $sModeMap))
  512. Return 0
  513. EndSwitch
  514. Switch $sModeArea
  515. Case "index"
  516. If Not IsInt($vMap) Then
  517. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vArea: " & $vArea))
  518. Return 0
  519. EndIf
  520. $sXPath &= "//area[" & $vArea & "]"
  521. Case "id", "name", "title", "alt", "href", "class", "coords"
  522. $sXPath &= "//area[contains(@" & $sModeArea & ",'" & $vArea & "')]"
  523. Case Else
  524. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|id|name|title|alt|href|coords|class) $sModeArea: " & $sModeArea))
  525. Return 0
  526. EndSwitch
  527. If _FFClick( _FFXPath($sXPath, "", 9)) Then
  528. If $bLoadWait Then Return _FFLoadWait()
  529. Return 1
  530. EndIf
  531. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch))
  532. Return 0
  533. EndFunc ;==>_FFImageMapClick
  534. ; #FUNCTION# ===================================================================
  535. ; Name ..........: _FFImagesGetBySize
  536. ; Description ...: Returns an array with the index of matching images.
  537. ; Beschreibung ..: Liefert ein Array mit den Indizes der passenden Bilder.
  538. ; Syntax ........: _FFImagesGetBySize($iHeight, $iWidth[, $sMode = "eq"[, $iPercent = 0]])
  539. ; Parameter(s): .: $iHeight - Heigth of the image(s)
  540. ; $iWidth - Width of the image(s)
  541. ; $sMode - Optional (Default = "eq") :
  542. ; | eq
  543. ; | lt
  544. ; | gt
  545. ; $iPercent - Optional (Default = 0) : +/- tolerance in percent for $sMode = "eq" (min=0, max=100)
  546. ; Return Value ..: Success - array[0] > 0
  547. ; Failure - array[0] = 0
  548. ; @ERROR -
  549. ; Author(s) .....: Thorsten Willert
  550. ; Date ..........: Mon Sep 28 10:40:47 CEST 2009
  551. ; Link ..........:
  552. ; Related .......:
  553. ; Example .......: Yes
  554. ; ==============================================================================
  555. Func _FFImagesGetBySize($iHeight, $iWidth, $sMode = "eq", $iPercent = 0)
  556. Local Const $sFuncName = "_FFImagesGetBySize"
  557. Local $aRet[1] = [0]
  558. If $iPercent < 0 Or $iPercent > 100 Then $iPercent = 0
  559. $sMode = StringLower($sMode)
  560. If Not IsInt($iHeight) Then
  561. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iHeight: " & $iHeight))
  562. Return $aRet
  563. EndIf
  564. If Not IsInt($iWidth) Then
  565. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iWidth: " & $iWidth))
  566. Return $aRet
  567. EndIf
  568. Switch $sMode
  569. Case "eq", "lt", "gt"
  570. Case Else
  571. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(eq|lt|gt) $sMode: " & $sMode))
  572. Return $aRet
  573. EndSwitch
  574. Local $sCommand = StringFormat("FFau3.SearchImageBySize(%s,%s,'%s',%s);", $iHeight, $iWidth, $sMode, $iPercent)
  575. Local $iIndex = StringStripWS(_FFCmd($sCommand, 10000), 3)
  576. $aRet = StringSplit($iIndex, " ")
  577. If Not @error And $aRet[0] > 0 Then
  578. For $i = 1 To $aRet[0]
  579. $aRet[$i] = Int($aRet[$i])
  580. Next
  581. Else
  582. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch))
  583. Return $aRet
  584. EndIf
  585. Return $aRet
  586. EndFunc ;==>_FFImagesGetBySize
  587. ; #FUNCTION# ===================================================================
  588. ; Name ..........: _FFLinkClick
  589. ; Description ...: Simulates a click on a link.
  590. ; Beschreibung ..: Simuliert einen Klick auf einen Link
  591. ; AutoIt Version : V3.3.0.0
  592. ; Syntax ........: _FFLinkClick($vSearch[, $sMode = "href"[, $bLoadWait = True]])
  593. ; Parameter(s): .: $vSearch - (Sub)String to search or number (0-n) in index mode
  594. ; $sMode - Optional: (Default = "href") :
  595. ; | href
  596. ; | alt
  597. ; | name
  598. ; | title
  599. ; | id
  600. ; | index
  601. ; $bLoadWait - Optional: (Default = True) :
  602. ; Return Value ..: Success - 1
  603. ; Failure - 0
  604. ; @ERROR -
  605. ; Author(s) .....: Thorsten Willert
  606. ; Date ..........: Thu Sep 24 17:27:40 CEST 2009 @685 /Internet Time/
  607. ; Link ..........:
  608. ; Related .......: _FFClick, _FFImageClick
  609. ; Example .......: Yes
  610. ; ==============================================================================
  611. Func _FFLinkClick($vSearch, $sMode = "href", $bLoadWait = True)
  612. Local Const $sFuncName = "_FFLinkClick"
  613. Local $sX
  614. $sMode = StringLower($sMode)
  615. Switch $sMode
  616. Case "index"
  617. If Not IsInt($vSearch) Then
  618. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vSearch: " & $vSearch))
  619. Return 0
  620. EndIf
  621. $sX = ".links[" & $vSearch & "]"
  622. Case "text"
  623. $sX = "//a[contains(.,'" & $vSearch & "')]"
  624. Case "href", "name", "title", "id"
  625. $sX = "//a[contains(@" & $sMode & ",'" & $vSearch & "')]"
  626. Case Else
  627. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|href|text|name|title|id) $sMode: " & $sMode))
  628. Return 0
  629. EndSwitch
  630. If $sMode <> "index" Then
  631. If _FFClick( _FFXPath($sX, "", 9) ) Then
  632. If $bLoadWait Then Return _FFLoadWait()
  633. Return 1
  634. EndIf
  635. Else
  636. If _FFClick( $sX ) Then
  637. If $bLoadWait Then Return _FFLoadWait()
  638. Return 1
  639. EndIf
  640. EndIf
  641. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$vSearch: " & $vSearch))
  642. Return 0
  643. EndFunc ;==>_FFLinkClick
  644. ; #FUNCTION# ===================================================================
  645. ; Name ..........: _FFFrameLeave
  646. ; Description ...: Leaves the currently entered frame
  647. ; Beschreibung ..: Verläßt den aktuellen Frame
  648. ; AutoIt Version : V3.3.0.0
  649. ; Syntax ........: _FFFrameLeave()
  650. ; Parameter(s): .:
  651. ; Return Value ..: Success - 1
  652. ; Failure - 0
  653. ; Author(s) .....: Thorsten Willert
  654. ; Date ..........: Fri Sep 18 11:08:20 CEST 2009 @422 /Internet Time/
  655. ; Link ..........:
  656. ; Related .......: _FFFrameEnter
  657. ; Example .......: Yes
  658. ; ==============================================================================
  659. Func _FFFrameLeave()
  660. ;Local Const $sFuncName = "_FFFrameLeave"
  661. Local $bTrc = $_FF_COM_TRACE
  662. $_FF_COM_TRACE = False
  663. Local $sFrame = StringMid($_FF_FRAME, 1, StringInStr($_FF_FRAME, ".", 2, -1) - 1)
  664. _FFCmd("FFau3.WCD=window.content.wrappedJSObject." & $sFrame & ".document;")
  665. If Not @error Then
  666. $_FF_COM_TRACE = $bTrc
  667. $_FF_FRAME = $sFrame
  668. Return 1
  669. EndIf
  670. $_FF_COM_TRACE = $bTrc
  671. Return 0
  672. EndFunc ;==>_FFFrameLeave
  673. ; #FUNCTION# ===================================================================
  674. ; Name ..........: _FFFrameEnter
  675. ; Description ...: Selects a frame, which all subsequent commands apply on.
  676. ; Beschreibung ..: Wählt einen Frame aus, auf den alle nachfolgenden Befehle wirken.
  677. ; AutoIt Version : V3.3.0.0
  678. ; Syntax ........: _FFFrameEnter($vFrame[, $sMode = "index"])
  679. ; Parameter(s): .: $vFrame - Frame name or id or number in index mode
  680. ; $sMode - Optional: (Default = "index") :
  681. ; | name
  682. ; | id
  683. ; | index
  684. ; Return Value ..: Success - 1
  685. ; Failure - 0
  686. ; @ERROR -
  687. ; Author(s) .....: Thorsten Willert
  688. ; Date ..........: Sat Oct 24 21:05:36 CEST 2009
  689. ; Link ..........:
  690. ; Related .......: _FFFrameLeave
  691. ; Example .......: Yes
  692. ; ==============================================================================
  693. Func _FFFrameEnter($vFrame, $sMode = "index")
  694. Local Const $sFuncName = "_FFFrameEnter"
  695. Local $sFrame = $_FF_FRAME
  696. Local $bTrc = $_FF_COM_TRACE
  697. Switch StringLower($sMode)
  698. Case "index"
  699. If IsInt($vFrame) Then
  700. $sFrame &= ".frames[" & $vFrame & "]"
  701. Else
  702. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vFrame: " & $vFrame))
  703. Return 0
  704. EndIf
  705. Case "name", "id"
  706. If IsString($vFrame) Then
  707. $sFrame &= "." & $vFrame
  708. Else
  709. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(string) $vFrame: " & $vFrame))
  710. Return 0
  711. EndIf
  712. Case Else
  713. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id) $sMode: " & $sMode))
  714. Return 0
  715. EndSwitch
  716. $_FF_COM_TRACE = False
  717. _FFCmd("FFau3.WCD=window.content.wrappedJSObject." & $sFrame & ".document;")
  718. If Not @error Then
  719. $_FF_FRAME = $sFrame
  720. $_FF_COM_TRACE = $bTrc
  721. Return 1
  722. EndIf
  723. $_FF_COM_TRACE = $bTrc
  724. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "Frame not found $vFrame: " & $vFrame))
  725. Return 0
  726. EndFunc ;==>_FFFrameEnter
  727. ; #FUNCTION# ===================================================================
  728. ; Name ..........: _FFGetLength
  729. ; Description ...: Returns the length of the elements in $sMode
  730. ; Beschreibung ..: Gibt die Anzahl der angegebenen Elemente zurück.
  731. ; AutoIt Version : V3.3.0.0
  732. ; Syntax ........: _FFGetLength([$sMode = "links"])
  733. ; Parameter(s): .: $sMode - Optional: (Default = "links") :
  734. ; | links
  735. ; | images
  736. ; | forms
  737. ; | frames
  738. ; | anchors
  739. ; | tables
  740. ; | styleSheets
  741. ; | tabs
  742. ; | history
  743. ; | applets
  744. ; | embeds
  745. ; | plugins
  746. ; | tag
  747. ; Return Value ..: Success - Length of the elements
  748. ; Failure - 0
  749. ; @ERROR -
  750. ; Author(s) .....: Thorsten Willert
  751. ; Date ..........: Mon Mar 23 23:24:13 CET 2009 @975 /Internet Time/
  752. ; Link ..........:
  753. ; Related .......:
  754. ; Example .......: Yes
  755. ; ==============================================================================
  756. Func _FFGetLength($sMode = "links")
  757. Local Const $sFuncName = "_FFGetLength"
  758. $sMode = StringLower($sMode)
  759. Switch $sMode
  760. Case "links", "images", "forms", "anchors", "applets", "embeds"
  761. Return _FFCmd("." & $sMode & ".length")
  762. Case "tabs"
  763. Return _FFCmd("gBrowser.tabContainer.childNodes.length")
  764. Case "frames"
  765. Return _FFCmd("content.frames.length")
  766. Case "tables"
  767. Return _FFCmd(".getElementsByTagName('table').length")
  768. Case "history"
  769. Return _FFCmd("content.history.length")
  770. Case "stylesheets"
  771. Return _FFCmd(".styleSheets.length")
  772. Case "plugins"
  773. Return _FFCmd("navigator.plugins.length")
  774. Case Else
  775. Local $RetVal = _FFCmd(".getElementsByTagName('" & $sMode & "').length;")
  776. If Not @error And $RetVal <> "_FFCmd_Err" Then
  777. Return $RetVal
  778. Else
  779. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sMode: " & $sMode))
  780. Return 0
  781. EndIf
  782. EndSwitch
  783. Return 0
  784. EndFunc ;==>_FFGetLength
  785. ; #FUNCTION# ===================================================================
  786. ; Name ..........: _FFLinksGetAll
  787. ; Description ...: Returns an array with informations about all existing links.
  788. ; Beschreibung ..: Gibt ein Array mit Informationen über alle vorhandenen Links zurück.
  789. ; AutoIt Version : V3.3.0.0
  790. ; Syntax ........: _FFLinksGetAll()
  791. ; Parameter(s): .:
  792. ; Return Value ..: Success - 2 dim array with the link informations:
  793. ; | array[n][0] = href
  794. ; | array[n][1] = hash
  795. ; | array[n][2] = search
  796. ; | array[n][3] = name
  797. ; | array[n][4] = id
  798. ; | array[n][5] = text
  799. ; | array[n][6] = innerHTML
  800. ; | array[n][7] = target
  801. ; | array[n][8] = protocol
  802. ; | array[n][9] = port
  803. ; Failure - array[0][0] = 0
  804. ; @ERROR -
  805. ; Author(s) .....: Thorsten Willert
  806. ; Date ..........: Tue Sep 22 12:00:34 CEST 2009 @458 /Internet Time/
  807. ; Link ..........:
  808. ; Related .......:
  809. ; Example .......: Yes
  810. ; ==============================================================================
  811. Func _FFLinksGetAll()
  812. Local Const $sFuncName = "_FFLinksGetAll"
  813. Local $aInfo, $sInfo, $aRet[1][9], $aTmp
  814. Local $sDelimiter
  815. Local $bTrc = $_FF_COM_TRACE
  816. $_FF_COM_TRACE= False
  817. If _FFGetLength() > 0 Then
  818. $sDelimiter = "FF" & Random(1000, 9999, 1)
  819. $sInfo = _FFCmd('FFau3.GetLinks("' & $sDelimiter & '");')
  820. $aInfo = StringSplit($sInfo, @CRLF)
  821. If @error Then
  822. $_FF_COM_TRACE = $bTrc
  823. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch))
  824. Return $aRet[0][0] = 0
  825. EndIf
  826. ReDim $aRet[$aInfo[0] - 1][9]
  827. For $i = 1 To $aInfo[0] - 1
  828. $aTmp = StringSplit($aInfo[$i], $sDelimiter, 1)
  829. If @error Then
  830. SetError(__FFError($sFuncName, $_FF_ERROR_RetValue, "StringSplit: " & $aInfo[$i]))
  831. ExitLoop
  832. EndIf
  833. If UBound($aTmp) <> 11 Then
  834. $sDelimiter = "FF" & Random(1000, 9999, 1)
  835. $sInfo = _FFCmd("FFau3.GetLinkInfo(" & $i & " ,'top','" & $sDelimiter & "')")
  836. $aTmp = StringSplit($sInfo, $sDelimiter, 1)
  837. EndIf
  838. For $j = 1 To $aTmp[0] - 1
  839. $aRet[$i - 1][$j - 1] = $aTmp[$j]
  840. Next
  841. Next
  842. $_FF_COM_TRACE = $bTrc
  843. Return $aRet
  844. Else
  845. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch))
  846. $aRet[0][0] = 0
  847. EndIf
  848. $_FF_COM_TRACE = $bTrc
  849. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError))
  850. Return $aRet[0][0] = 0
  851. EndFunc ;==>_FFLinksGetAll
  852. ; #FUNCTION# ===================================================================
  853. ; Name ..........: _FFConnect
  854. ; Description ...: Connects to FireFox / MozRepl
  855. ; Beschreibung ..: Stellt eine Verbindung mit Firefox / MozRepl her.
  856. ; AutoIt Version : V3.3.0.0
  857. ; Syntax ........: _FFConnect([$IP = "127.0.0.1"[, $iPort = 4242[, $iTimeOut = 60000]]])
  858. ; Parameter(s): .: $IP - Optional: (Default = "127.0.0.1") :
  859. ; $iPort - Optional: (Default = 4242) :
  860. ; $iTimeOut - Optional: (Default = 60000) :
  861. ; Return Value ..: Success - 1 / $_FF_GLOBAL_SOCKET > -1
  862. ; @EXTENDED - 1 = Non Browser-window
  863. ; | 2 = Browser-window
  864. ; Failure - 0 / $_FF_GLOBAL_SOCKET = -1
  865. ; @ERROR -
  866. ; @EXTENDED - 0
  867. ; Author(s) .....: Thorsten Willert
  868. ; Date ..........: Tue Aug 18 09:36:57 CEST 2009
  869. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms740668(VS.85).aspx
  870. ; Related .......: _FFDisConnect, _FFIsConnected, _FFStart
  871. ; Example .......: Yes
  872. ; ==============================================================================
  873. Func _FFConnect($IP = "127.0.0.1", $iPort = 4242, $iTimeOut = 60000)
  874. Local Const $sFuncName = "_FFConnect"
  875. Local $Extended = 2
  876. If $_FF_CON_DELAY > 100 Then Opt("TCPTimeout", $_FF_CON_DELAY)
  877. If $IP = Default Then $IP = "127.0.0.1"
  878. If $iPort = Default Then $iPort = 4242
  879. If $iTimeOut = Default Then $iTimeOut = 60000
  880. If Not __FFIsIP($IP) Then
  881. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, $IP))
  882. Return 0
  883. EndIf
  884. If Not __FFIsPort($iPort) Then
  885. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, $iPort))
  886. Return 0
  887. EndIf
  888. Local $iTCPErr
  889. Local $bTrace = $_FF_COM_TRACE
  890. ;$_FF_COM_TRACE = false
  891. ConsoleWrite("_FFConnect: OS:" & @TAB & @OSVersion & " " & @OSTYPE & " " & @OSBuild & " " & @OSServicePack & @CRLF)
  892. ConsoleWrite("_FFConnect: AutoIt:" & @TAB & @AutoItVersion & @CRLF)
  893. ConsoleWrite("_FFConnect: FF.au3:" & @TAB & $_FF_AU3VERSION & @CRLF)
  894. ConsoleWrite("_FFConnect: IP:" & @TAB & $IP & @CRLF)
  895. ConsoleWrite("_FFConnect: Port:" & @TAB & $iPort & @CRLF)
  896. TCPStartup()
  897. If Not @error Then
  898. ; delay for connection over network
  899. $_FF_CON_DELAY = Ping($IP)
  900. If @error Then
  901. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "Ping Error: " & @error))
  902. $_FF_CON_DELAY = $_FF_COM_DELAY_MAX
  903. EndIf
  904. $_FF_CON_DELAY += Round($_FF_CON_DELAY * 0.5)
  905. ConsoleWrite("_FFConnect: Delay: " & @TAB & $_FF_CON_DELAY & "ms" & @CRLF)
  906. ; trying to connect
  907. Local $iTimeOutTimer = TimerInit()
  908. While 1
  909. $_FF_GLOBAL_SOCKET = TCPConnect($IP, $iPort)
  910. $iTCPErr = @error
  911. Sleep(500)
  912. If __FFIsSocket($_FF_GLOBAL_SOCKET) Then ExitLoop
  913. If (TimerDiff($iTimeOutTimer) > $iTimeOut) Then ; Profil laden
  914. SetError(__FFError($sFuncName, $_FF_ERROR_Timeout, "TCPConnect Error: " & $iTCPErr))
  915. $_FF_GLOBAL_SOCKET = -1
  916. ExitLoop
  917. EndIf
  918. WEnd
  919. If $_FF_GLOBAL_SOCKET <> -1 Then
  920. ConsoleWrite("_FFConnect: Socket: " & @TAB & $_FF_GLOBAL_SOCKET & @CRLF)
  921. If __FFWaitForRepl(10000) Then
  922. _FFCmd(".browserDOMWindow")
  923. If @error Then
  924. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "Warning: Connected to a non browser-window"))
  925. $Extended = 1
  926. EndIf
  927. ConsoleWrite("_FFConnect: Browser:" & @TAB & _FFCmd("navigator.userAgent") & @CRLF)
  928. __FFSendJavaScripts()
  929. $_FF_COM_TRACE = $bTrace
  930. Return SetError(0, $Extended, 1)
  931. EndIf
  932. Else
  933. TCPShutdown()
  934. $_FF_COM_TRACE = $bTrace
  935. Return SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "Timeout: Can not connect to FireFox/MozRepl on: " & $IP & ":" & $iPort), 0, 0)
  936. EndIf
  937. Else
  938. $_FF_COM_TRACE = $bTrace
  939. Return SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "TCPStartup Error: " & @error), 0, 0)
  940. EndIf
  941. $_FF_COM_TRACE = $bTrace
  942. Return SetError($_FF_ERROR_GeneralError, $Extended, 0)
  943. EndFunc ;==>_FFConnect
  944. ; #FUNCTION# ===================================================================
  945. ; Name ..........: _FFDisConnect
  946. ; Description ...: Disconnects from FireFox
  947. ; Beschreibung ..: Trennt die Verbindung mit FireFox / MozRepl
  948. ; AutoIt Version : V3.3.0.0
  949. ; Syntax ........: _FFDisConnect()
  950. ; Parameter(s): .:
  951. ; Return Value ..: Success - 1 / $_FF_GLOBAL_SOCKET = -1
  952. ; Failure - 0
  953. ; @ERROR -
  954. ; Author(s) .....: Thorsten Willert
  955. ; Date ..........: Wed Apr 15 09:54:09 CEST 2009
  956. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms740668(VS.85).aspx
  957. ; Related .......: _FFConnect, _FFIsConnected, _FFStart
  958. ; Example .......: Yes
  959. ; ==============================================================================
  960. Func _FFDisConnect()
  961. Local Const $sFuncName = "_FFDisConnect"
  962. Opt("TCPTimeout", 200)
  963. If __FFIsSocket($_FF_GLOBAL_SOCKET) Then
  964. __FFSend("repl.quit()")
  965. TCPCloseSocket($_FF_GLOBAL_SOCKET)
  966. If @error Then
  967. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "TCP Error: " & @error))
  968. Return 0
  969. EndIf
  970. TCPShutdown()
  971. If Not @error Then
  972. If $_FF_COM_TRACE Then ConsoleWrite("_FFDisConnect: disconnected" & @CRLF)
  973. $_FF_FRAME = "top"
  974. $_FF_GLOBAL_SOCKET = -1
  975. Return 1
  976. Else
  977. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "TCP Error: " & @error))
  978. Return 0
  979. EndIf
  980. Else
  981. SetError(__FFError($sFuncName, $_FF_ERROR_SocketError, $_FF_GLOBAL_SOCKET))
  982. Return 0
  983. EndIf
  984. EndFunc ;==>_FFDisConnect
  985. ; #FUNCTION# ===================================================================
  986. ; Name ..........: _FFIsConnected
  987. ; Description ...: Connection status to FireFox / MozRepl
  988. ; Beschreibung ..: Liefert den Status der Verbindung mit FireFox / MozRepl
  989. ; AutoIt Version : V3.3.0.0
  990. ; Syntax ........: _FFIsConnected()
  991. ; Parameter(s): .:
  992. ; Return Value ..: Success - 1
  993. ; Failure - 0
  994. ; @ERROR -
  995. ; Author(s) .....: Thorsten Willert
  996. ; Date ..........: Mon Sep 28 11:03:44 CEST 2009
  997. ; Link ..........:
  998. ; Related .......: _FFConnect, _FFDisConnect, _FFStart
  999. ; Example .......: Yes
  1000. ; ==============================================================================
  1001. Func _FFIsConnected()
  1002. Local Const $sFuncName = "_FFIsConnected"
  1003. If __FFIsSocket($_FF_GLOBAL_SOCKET) And _FFCmd("FFau3 != null?1:0") = 1 Then Return 1
  1004. SetError(__FFError($sFuncName, $_FF_ERROR_SocketError, $_FF_GLOBAL_SOCKET))
  1005. Return 0
  1006. EndFunc ;==>_FFIsConnected
  1007. ; #FUNCTION# ===================================================================
  1008. ; Name ..........: _FFFormCheckBox
  1009. ; Description ...: Checks or unchecks a CheckBox in a form.
  1010. ; Beschreibung ..: Wählt eine Checkbox an oder ab.
  1011. ; AutoIt Version : V3.3.0.0
  1012. ; Syntax ........: _FFFormCheckBox($vBox[, $bChecked = True[, $iBoxNameIndex = 0[, $sBoxMode = "index"[, $vForm = 0[, $sFormMode = "index"[, $bCheckBox = True]]]]]])
  1013. ; Parameter(s): .: $vBox - Index name, id or value of the CheckBox
  1014. ; $bChecked - Optional: (Default = True) :
  1015. ; | True
  1016. ; | False
  1017. ; $iBoxNameIndex - Optional: (Default = 0) : Index if $sBoxMode = "name"
  1018. ; $sBoxMode - Optional: (Default = "index") :
  1019. ; | index
  1020. ; | name
  1021. ; | id
  1022. ; | value
  1023. ; $vForm - Optional: (Default = 0) : Index, name or id of the Form
  1024. ; $sFormMode - Optional: (Default = "index") :
  1025. ; | index
  1026. ; | name
  1027. ; | id
  1028. ; | action
  1029. ; | title
  1030. ; $bCheckBox - Optional: (Default = True) : Internal use if the function should work for RadioButtons
  1031. ; Return Value ..: Success - 1
  1032. ; Failure - 0
  1033. ; @ERROR -
  1034. ; Author(s) .....: Thorsten Willert
  1035. ; Date ..........: Fri Nov 06 18:10:36 CET 2009
  1036. ; Link ..........:
  1037. ; Related .......: _FFFormOptionSelect, _FFFormRadioButton, _FFFormReset, _FFFormSubmit
  1038. ; Example .......: Yes
  1039. ; ==============================================================================
  1040. Func _FFFormCheckBox($vBox, $bChecked = True, $iBoxNameIndex = 0, $sBoxMode = "index", $vForm = 0, $sFormMode = "index", $bCheckBox = True)
  1041. Local Const $sFuncName = "_FFFormCheckBox"
  1042. ; Default parameters
  1043. ;If $bChecked = Default Then $bChecked = true
  1044. If $iBoxNameIndex = Default Then $iBoxNameIndex = 0
  1045. If $sBoxMode = Default Then $sBoxMode = "index"
  1046. If $vForm = Default Then $vForm = 0
  1047. If $sFormMode = Default Then $sFormMode = "index"
  1048. Local $sType
  1049. If $bCheckBox Then
  1050. $sType = "checkbox"
  1051. Else
  1052. $sType = "radio"
  1053. EndIf
  1054. $sBoxMode = StringLower($sBoxMode)
  1055. $sFormMode = StringLower($sFormMode)
  1056. If Not IsBool($bChecked) Then
  1057. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(bool) $bChecked: " & $bChecked))
  1058. Return 0
  1059. EndIf
  1060. Local $sCommand = "checked=" & __FFB2S($bChecked)
  1061. Local $sForm, $sCheckBox
  1062. Switch $sFormMode
  1063. Case "index"
  1064. If Not IsInt($vForm) Then
  1065. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vForm: " & $vForm))
  1066. Return 0
  1067. EndIf
  1068. $sForm = $vForm + 1
  1069. Case "id", "name", "action", "title"
  1070. $sForm = StringFormat("@%s='%s'", $sFormMode, $vForm)
  1071. Case Else
  1072. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id) $sFormMode: " & $sFormMode))
  1073. Return 0
  1074. EndSwitch
  1075. Switch $sBoxMode
  1076. Case "index"
  1077. If Not IsInt($vBox) Then
  1078. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vBox: " & $vBox))
  1079. Return 0
  1080. EndIf
  1081. $sCheckBox = "position()=" & $vBox + 1
  1082. Case "name"
  1083. If Not IsInt($iBoxNameIndex) Then
  1084. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iBoxNameIndex: " & $iBoxNameIndex))
  1085. Return 0
  1086. EndIf
  1087. $sCheckBox = StringFormat("@name='%s' and position()=%i", $vBox, $iBoxNameIndex + 1)
  1088. Case "id", "value"
  1089. $sCheckBox = StringFormat("@%s='%s'", $sBoxMode, $vBox)
  1090. Case Else
  1091. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id|value) $sBoxMode: " & $sBoxMode))
  1092. Return 0
  1093. EndSwitch
  1094. _FFXPath(StringFormat("//form[%s]//input[@type='%s' and %s]", $sForm, $sType, $sCheckBox), $sCommand, 9)
  1095. If Not @error Then
  1096. Return 1
  1097. Else
  1098. SetError(@error)
  1099. Return 0
  1100. EndIf
  1101. EndFunc ;==>_FFFormCheckBox
  1102. ; #FUNCTION# ===================================================================
  1103. ; Name ..........: _FFFormGetElementsLength
  1104. ; Description ...: Length of the form elements
  1105. ; Beschreibung ..: Gibt die Anzahl der Elemente eines Formulars zurück.
  1106. ; AutoIt Version : V3.3.0.0
  1107. ; Syntax ........: _FFFormGetElementsLength([$vForm = 0[, $sMode = "index"]])
  1108. ; Parameter(s): .: $vForm - Optional: (Default = 0) : Index (0-n), name or id
  1109. ; $sMode - Optional: (Default = "index") :
  1110. ; | index
  1111. ; | name
  1112. ; | id
  1113. ; | action
  1114. ; | title
  1115. ; Return Value ..: Success - >0
  1116. ; Failure - 0
  1117. ; @ERROR -
  1118. ; Author(s) .....: Thorsten Willert
  1119. ; Date ..........: Fri Nov 06 22:04:28 CET 2009
  1120. ; Link ..........:
  1121. ; Related .......: _FFGetLength
  1122. ; Example .......: Yes
  1123. ; ==============================================================================
  1124. Func _FFFormGetElementsLength($vForm = 0, $sMode = "index")
  1125. Local Const $sFuncName = "_FFFormGetElementsLength"
  1126. If $vForm = Default Then $vForm = 0
  1127. If $sMode = Default Then $sMode = "index"
  1128. $sMode = StringLower($sMode)
  1129. Local $sForm
  1130. Switch $sMode
  1131. Case "index"
  1132. If IsInt($vForm) Then
  1133. $sForm = $vForm + 1
  1134. Else
  1135. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vForm: " & $vForm))
  1136. Return 0
  1137. EndIf
  1138. Case "name", "id", "action", "title"
  1139. $sForm = "@" & $sMode & "='" & $vForm & "'"
  1140. Case Else
  1141. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id|action|title) $sMode: " & $sMode))
  1142. Return 0
  1143. EndSwitch
  1144. Local $bTrace = $_FF_COM_TRACE
  1145. $_FF_COM_TRACE = False
  1146. _FFXPath(StringFormat("//form[%s]", $sForm), "", 9)
  1147. Local $sRet = _FFCmd("FFau3.xpath.elements.length")
  1148. If Not @error Then
  1149. $_FF_COM_TRACE = $bTrace
  1150. Return $sRet
  1151. Else
  1152. $_FF_COM_TRACE = $bTrace
  1153. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$vForm: " & $vForm))
  1154. Return 0
  1155. EndIf
  1156. EndFunc ;==>_FFFormGetElementsLength
  1157. ; #FUNCTION# ===================================================================
  1158. ; Name ..........: _FFFormOptionSelect
  1159. ; Description ...: Selects an element of an OptionSelect.
  1160. ; Beschreibung ..: Wählt ein Element eines OptionSelect aus.
  1161. ; AutoIt Version : V3.3.0.0
  1162. ; Syntax ........: _FFFormOptionSelect([$vElement = 0[, $sElementMode = "index"[, $vOption = 0[, $sOptionMode = "index"[, $vForm = 0[, $sFormMode = "index"]]]]]])
  1163. ; Parameter(s): .: $vElement - Optional: (Default = 0) : index (0-n), name, id
  1164. ; $sElementMode - Optional: (Default = "index") :
  1165. ; | index
  1166. ; | name
  1167. ; | id
  1168. ; $vOption - Optional: (Default = 0) : index (0-n), name, id, text, value
  1169. ; $sOptionMode - Optional: (Default = "index") :
  1170. ; | index
  1171. ; | name
  1172. ; | id
  1173. ; | text
  1174. ; | value
  1175. ; $vForm - Optional: (Default = 0) : index (0-n), name, id
  1176. ; $sFormMode - Optional: (Default = "index") :
  1177. ; | index
  1178. ; | name
  1179. ; | id
  1180. ; | action
  1181. ; | title
  1182. ; Return Value ..: Success - 1
  1183. ; Failure - 0 and sets
  1184. ; @ERROR -
  1185. ; Author(s) .....: Thorsten Willert
  1186. ; Date ..........: Fri Nov 06 18:12:43 CET 2009
  1187. ; Link ..........:
  1188. ; Related .......: _FFFormCheckBox, _FFFormRadioButton, _FFFormReset, _FFFormSubmit
  1189. ; Example .......: Yes
  1190. ; ==============================================================================
  1191. Func _FFFormOptionSelect($vElement = 0, $sElementMode = "index", $vOption = 0, $sOptionMode = "index", $vForm = 0, $sFormMode = "index")
  1192. Local Const $sFuncName = "_FFFormOptionSelect"
  1193. ; Default parameters
  1194. If $vElement = Default Then $vElement = 0
  1195. If $sElementMode = Default Then $sElementMode = "index"
  1196. If $vOption = Default Then $vOption = 0
  1197. If $sOptionMode = Default Then $sOptionMode = "index"
  1198. If $vForm = Default Then $vForm = 0
  1199. If $sFormMode = Default Then $sFormMode = "index"
  1200. Local $sForm, $sElement, $sOption
  1201. $sElementMode = StringLower($sElementMode)
  1202. $sOptionMode = StringLower($sOptionMode)
  1203. $sFormMode = StringLower($sFormMode)
  1204. Switch $sFormMode
  1205. Case "index"
  1206. If Not IsInt($vForm) Then
  1207. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vForm: " & $vForm))
  1208. Return 0
  1209. EndIf
  1210. $sForm = $vForm + 1
  1211. Case "id", "name", "action", "title"
  1212. $sForm = StringFormat("@%s='%s'", $sFormMode, $vForm)
  1213. Case Else
  1214. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id) $sFormMode: " & $sFormMode))
  1215. Return 0
  1216. EndSwitch
  1217. Switch $sElementMode
  1218. Case "index"
  1219. If Not IsInt($vElement) Then
  1220. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vElement: " & $vElement))
  1221. Return 0
  1222. EndIf
  1223. $sElement = "position()=" & $vElement + 1
  1224. Case "name"
  1225. ContinueCase
  1226. Case "id"
  1227. $sElement = StringFormat("@%s='%s'", $sElementMode, $vElement)
  1228. Case Else
  1229. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id) $sElementMode: " & $sElementMode))
  1230. Return 0
  1231. EndSwitch
  1232. Switch $sOptionMode
  1233. Case "index"
  1234. If Not IsInt($vOption) Then
  1235. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vOption: " & $vOption))
  1236. Return 0
  1237. EndIf
  1238. $sOption = "position()=" & $vOption + 1
  1239. Case "text"
  1240. $sOption = StringFormat("contains(.,'%s')", $vOption)
  1241. Case "name", "id", "value"
  1242. $sOption = StringFormat("@%s='%s'", $sOptionMode, $vOption)
  1243. Case Else
  1244. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|text|name|id|value) $sOptionMode: " & $sOptionMode))
  1245. Return 0
  1246. EndSwitch
  1247. Local $sCommand = StringFormat("//form[%s]//select[%s]//option[%s]", $sForm, $sElement, $sOption)
  1248. _FFXPath($sCommand, "selected=true", 9)
  1249. If Not @error Then
  1250. Return 1
  1251. Else
  1252. SetError(@error)
  1253. Return 0
  1254. EndIf
  1255. EndFunc ;==>_FFFormOptionSelect
  1256. ; #FUNCTION# ===================================================================
  1257. ; Name ..........: _FFFormRadioButton
  1258. ; Description ...: Selects a RadioButton in a form
  1259. ; Beschreibung ..: Wählt einen RadioButton aus.
  1260. ; AutoIt Version : V3.3.0.0
  1261. ; Syntax ........: _FFFormRadioButton($vRadioButton[, $iRadioButtonIndex = 0[, $sRadioButtonMode = "index"[, $vForm = 0[, $sFormMode = "index"]]]])
  1262. ; Parameter(s): .: $vRadioButton - name, id or value
  1263. ; $iRadioButtonIndex - Optional: (Default = 0) : RadioButton index (0-n)
  1264. ; $sRadioButtonMode - Optional: (Default = "index") : RadioButton
  1265. ; | index
  1266. ; | name
  1267. ; | id
  1268. ; | value
  1269. ; $vForm - Optional: (Default = 0) : Form index or name
  1270. ; $sFormMode - Optional: (Default = "index") :
  1271. ; | index
  1272. ; | name
  1273. ; Return Value ..: Success - RadioButton state 1 or 0
  1274. ; Failure - -1
  1275. ; Author(s) .....: Thorsten Willert
  1276. ; Date ..........: Wed Mar 25 09:22:11 CET 2009 @390 /Internet Time/
  1277. ; Link ..........:
  1278. ; Related .......: _FFFormCheckBox, _FFFormOptionSelect, _FFFormReset, _FFFormSubmit
  1279. ; Example .......: Yes
  1280. ; ==============================================================================
  1281. Func _FFFormRadioButton($vRadioButton, $iRadioButtonIndex = 0, $sRadioButtonMode = "index", $vForm = 0, $sFormMode = "index")
  1282. ;Local Const $sFuncName = "_FFFormRadioButton"
  1283. Local $RetVal = _FFFormCheckBox($vRadioButton, True, $iRadioButtonIndex, $sRadioButtonMode, $vForm, $sFormMode, False)
  1284. SetError(@error)
  1285. Return $RetVal
  1286. EndFunc ;==>_FFFormRadioButton
  1287. ; #FUNCTION# ===================================================================
  1288. ; Name ..........: _FFFormReset
  1289. ; Description ...: Resets a form
  1290. ; Beschreibung ..: Setzt ein Formular zurück.
  1291. ; AutoIt Version : V3.3.0.0
  1292. ; Syntax ........: _FFFormReset([$vForm = 0[, $sMode = "index"]])
  1293. ; Parameter(s): .: $vForm - Optional: (Default = 0) : Index (0-n), name, id
  1294. ; $sMode - Optional: (Default = "index") :
  1295. ; | Index
  1296. ; | name
  1297. ; | id
  1298. ; Return Value ..: Success - 1
  1299. ; Failure - 0
  1300. ; @ERROR -
  1301. ; Author(s) .....: Thorsten Willert
  1302. ; Date ..........: Fri Sep 18 06:01:42 CEST 2009 @209 /Internet Time/
  1303. ; Link ..........:
  1304. ; Related .......: _FFFormCheckBox, _FFFormOptionSelect, _FFFormSubmit, _FFFormRadioButton
  1305. ; Example .......: Yes
  1306. ; ==============================================================================
  1307. Func _FFFormReset($vForm = 0, $sMode = "index")
  1308. Local Const $sFuncName = "_FFFormReset"
  1309. Local $sCommand
  1310. Switch StringLower($sMode)
  1311. Case "index"
  1312. If Not IsInt($vForm) Then
  1313. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vForm: " & $vForm))
  1314. Return 0
  1315. EndIf
  1316. $sCommand = '.forms[' & $vForm & ']'
  1317. Case "id"
  1318. $sCommand = '.getElementById("' & $vForm & '")'
  1319. Case "name"
  1320. $sCommand = '.getElementsByName("' & $vForm & '")[0]'
  1321. Case Else
  1322. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|id|name) $sMode: " & $sMode))
  1323. Return 0
  1324. EndSwitch
  1325. Local $sRetVal = _FFCmd($sCommand & ".reset();")
  1326. If Not @error And $sRetVal <> "_FFCmd_Err" Then Return 1
  1327. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$vForm: " & $vForm))
  1328. Return 0
  1329. EndFunc ;==>_FFFormReset
  1330. ; #FUNCTION# ===================================================================
  1331. ; Name ..........: _FFFormSubmit
  1332. ; Description ...: Submits a form
  1333. ; Beschreibung ..: Sendet ein Formular ab.
  1334. ; AutoIt Version : V3.3.0.0
  1335. ; Syntax ........: _FFFormSubmit([$vForm = 0[, $sMode = "index"[, $sSubmitMode = "submit"[, $bLoadWait = True]]]])
  1336. ; Parameter(s): .: $vForm - Optional: (Default = 0) : Index-number, name or id
  1337. ; $sSubmitMode - Optional: (Default = "auto") :
  1338. ; | auto
  1339. ; | click
  1340. ; | submit
  1341. ; | keydown
  1342. ; | keypress
  1343. ; $bLoadWait - Optional: (Default = true) :
  1344. ; | True
  1345. ; | False
  1346. ; Return Value ..: Success - 1
  1347. ; Failure - 0
  1348. ; @ERROR -
  1349. ; Author(s) .....: Thorsten Willert
  1350. ; Date ..........: Tue Apr 07 17:56:46 CEST 2009 @706 /Internet Time/
  1351. ; Link ..........:
  1352. ; Related .......: _FFFormCheckBox, _FFFormOptionSelect, _FFFormReset, _FFFormRadioButton
  1353. ; Example .......: Yes
  1354. ; ==============================================================================
  1355. Func _FFFormSubmit($vForm = 0, $sMode = "index", $sSubmitMode = "submit", $bLoadWait = True)
  1356. Local Const $sFuncName = "_FFFormSubmit"
  1357. Local $sRetVal
  1358. Local $iSubmit = -1, $iPassword = -1
  1359. Local $bTrace
  1360. $sMode = StringLower($sMode)
  1361. If $sMode = "index" Then
  1362. If IsInt($vForm) Then
  1363. $vForm = 'forms[' & $vForm & ']'
  1364. Else
  1365. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vForm: " & $vForm))
  1366. Return 0
  1367. EndIf
  1368. ElseIf $sMode = "id" Then
  1369. $vForm = "getElementById('" & $vForm & "')"
  1370. ElseIf $sMode = "name" Then
  1371. $vForm = "getElementsByName('" & $vForm & "')[0]"
  1372. Else
  1373. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|id|name) $sMode: " & $sMode))
  1374. Return 0
  1375. EndIf
  1376. Local $iLength = _FFCmd(StringFormat('.%s.elements.length;', $vForm))
  1377. If $iLength = "_FFCmd_Err" Then
  1378. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "No Elements found in form: " & $vForm))
  1379. Return 0
  1380. EndIf
  1381. $bTrace = $_FF_COM_TRACE
  1382. $_FF_COM_TRACE = False
  1383. If $iLength > 0 And ($sSubmitMode = "keypress" Or $sSubmitMode = "keydown" Or $sSubmitMode = "click" Or $sSubmitMode = "auto") Then
  1384. For $i = 0 To $iLength - 1
  1385. $sRetVal = _FFCmd(StringFormat('.%s.elements[%i].type;', $vForm, $i))
  1386. If @error Then Return 0
  1387. If $sRetVal = "submit" Then $iSubmit = $i
  1388. If $sRetVal = "password" Then $iPassword = $i
  1389. If $iSubmit > -1 And $iPassword > -1 Then ExitLoop
  1390. Next
  1391. EndIf
  1392. $_FF_COM_TRACE = $bTrace
  1393. Switch StringLower($sSubmitMode)
  1394. Case "auto"
  1395. ContinueCase
  1396. Case "keypress"
  1397. ; fire "enter" with keypress on the password element
  1398. _FFDispatchEvent(StringFormat('.%s.elements[%i]', $vForm, $iPassword), "keypress", 13)
  1399. If Not @error Then
  1400. If $bLoadWait Then
  1401. If Not _FFLoadWait() Then Return 0
  1402. EndIf
  1403. Return 1
  1404. Else
  1405. If $sSubmitMode = "auto" Then ContinueCase
  1406. EndIf
  1407. Case "click"
  1408. ; clicks on the submit element
  1409. $sRetVal = _FFCmd(StringFormat('.%s.elements[%i].click();', $vForm, $iSubmit), 3000)
  1410. If Not @error And $sRetVal <> "_FFCmd_Err" Then
  1411. If $bLoadWait Then
  1412. If Not _FFLoadWait() And $sSubmitMode = "auto" Then ContinueCase
  1413. EndIf
  1414. Return 1
  1415. Else
  1416. If $sSubmitMode = "auto" Then ContinueCase
  1417. EndIf
  1418. Case "submit"
  1419. ; use form.submit()
  1420. $sRetVal = _FFCmd(StringFormat('.%s.submit();', $vForm))
  1421. If Not @error And $sRetVal <> "_FFCmd_Err" Then
  1422. If $bLoadWait Then
  1423. If Not _FFLoadWait() And $sSubmitMode = "auto" Then ContinueCase
  1424. EndIf
  1425. Return 1
  1426. Else
  1427. If $sSubmitMode = "auto" Then ContinueCase
  1428. EndIf
  1429. Case "keydown"
  1430. ; fire "enter" with keydown on the password element
  1431. _FFDispatchEvent(StringFormat(".%s.elements[%i]", $vForm, $iPassword), "keydown", 13)
  1432. If Not @error Then
  1433. If $bLoadWait Then
  1434. If Not _FFLoadWait() And $sSubmitMode = "auto" Then ContinueCase
  1435. EndIf
  1436. Return 1
  1437. EndIf
  1438. Case Else
  1439. Return 0
  1440. EndSwitch
  1441. Return 0
  1442. EndFunc ;==>_FFFormSubmit
  1443. ; #FUNCTION# ===================================================================
  1444. ; Name ..........: _FFGetValue
  1445. ; Description ...: Gets an value of an element
  1446. ; Beschreibung ..: Liefert das Value eines Elements
  1447. ; AutoIt Version : V3.3.0.0
  1448. ; Syntax ........: _FFGetValue($sElement[, $sMode = "elements"[, $iIndex = 0[, $iFilter = 0]]])
  1449. ; Parameter(s): .: $sElement -
  1450. ; $sMode - Optional: (Default = "elements") :
  1451. ; | elements: element or object from _FFXpath or _FFObj*
  1452. ; | id
  1453. ; | name
  1454. ; | class
  1455. ; | tag
  1456. ; $iIndex - Optional: (Default = 0) : index if $sMode = class, name, tag
  1457. ; $iFilter - Optional: (Default = 0) : you can add them:
  1458. ; | 0 = No filter
  1459. ; | 1 = Remove all non ASCII
  1460. ; | 2 = Remove all double withespaces
  1461. ; | 4 = Remove all double linefeeds
  1462. ; | 8 = Remove all HTML-tags
  1463. ; | 16 = simple html-tag / entities convertor
  1464. ; Return Value ..: Success - 1
  1465. ; Failure - 0
  1466. ; @ERROR -
  1467. ; Author(s) .....: Thorsten Willert
  1468. ; Date ..........: Wed Sep 23 22:55:36 CEST 2009
  1469. ; Link ..........:
  1470. ; Related .......: _FFSetValue, _FFXPath
  1471. ; Example .......: Yes
  1472. ; ==============================================================================
  1473. Func _FFGetValue($sElement, $sMode = "elements", $iIndex = 0, $iFilter = 0)
  1474. Local Const $sFuncName = "_FFGetValue"
  1475. If Not IsInt($iIndex) Then
  1476. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iIndex: " & $iIndex))
  1477. Return 0
  1478. EndIf
  1479. If Not IsInt($iFilter) Then
  1480. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iFilter: " & $iFilter))
  1481. Return 0
  1482. EndIf
  1483. Switch StringLower($sMode)
  1484. Case "elements"
  1485. If StringLeft($sElement, 7) = "OBJECT|" Then $sElement = StringMid($sElement, 8)
  1486. Case "id"
  1487. $sElement = ".getElementById('" & $sElement & "')"
  1488. Case "name"
  1489. $sElement = ".getElementsByName('" & $sElement & "')[" & $iIndex & "]"
  1490. Case "class"
  1491. $sElement = ".getElementsByClassName('" & $sElement & "')[" & $iIndex & "]"
  1492. Case "tag"
  1493. $sElement = ".getElementsByTagName('" & $sElement & "')[" & $iIndex & "]"
  1494. Case Else
  1495. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(elements|id|name|class|tag) $sMode: " & $sMode))
  1496. Return 0
  1497. EndSwitch
  1498. If StringLeft($sElement, 1) = "." Then $sElement = "window.content.document" & $sElement
  1499. Local $sRetVal = _FFCmd($sElement & ".value")
  1500. If Not @error And $sRetVal <> "_FFCmd_Err" Then
  1501. If $iFilter > 0 Then __FFFilterString($sRetVal, $iFilter)
  1502. Return $sRetVal
  1503. Else
  1504. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sElement: " & $sElement))
  1505. Return 0
  1506. EndIf
  1507. EndFunc
  1508. ; #FUNCTION# ===================================================================
  1509. ; Name ..........: _FFDispatchEvent
  1510. ; Description ...: Simulates a HTML event
  1511. ; Beschreibung ..: Simuliert ein HTML-Ereignis an einem Element.
  1512. ; AutoIt Version : V3.3.0.0
  1513. ; Syntax ........: _FFDispatchEvent($sElement[, $sEventType = "change"[, $iKeyCode = 0]])
  1514. ; Parameter(s): .: $sElement - Element where the event is fired (or object from _FFXpath/_FFObj*)
  1515. ; $sEventType - Optional: (Default = "change") :
  1516. ; | change
  1517. ; | select
  1518. ; | focus
  1519. ; | blur
  1520. ; | resize
  1521. ; | keydown
  1522. ; | keypress
  1523. ; | keyup
  1524. ; $iKeyCode - ASCII-KeyCode (decimal)
  1525. ; Return Value ..: Success - 1
  1526. ; Failure - 0
  1527. ; @ERROR -
  1528. ; Author(s) .....: Thorsten Willert
  1529. ; Date ..........: Fri Nov 06 19:35:04 CET 2009
  1530. ; Link ..........: http://www.w3.org/TR/DOM-Level-2-Events/events.html
  1531. ; Related .......:
  1532. ; Example .......: Yes
  1533. ; ==============================================================================
  1534. Func _FFDispatchEvent($sElement, $sEventType = "change", $iKeyCode = 13)
  1535. Local Const $sFuncName = "_FFDispatchEvent"
  1536. If $iKeyCode < 0 Or $iKeyCode > 255 Then
  1537. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(int) $iKeyCode: 0-255" & $iKeyCode))
  1538. Return 0
  1539. EndIf
  1540. Local $sType
  1541. $sEventType = StringLower($sEventType)
  1542. If StringLeft($sElement, 7) = "OBJECT|" Then $sElement = StringMid($sElement, 8)
  1543. Switch $sEventType
  1544. Case "change", "select", "focus", "blur", "resize"
  1545. $sType = "Event"
  1546. Case "keydown", "keypress", "keyup"
  1547. $sType = "KeyboardEvent"
  1548. Case Else
  1549. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(change|select|focus|blur|resizekeydown|keypress|keyup) $sEventType: " & $sEventType))
  1550. Return 0
  1551. EndSwitch
  1552. If StringLeft($sElement, 1) = "." Then $sElement = "window.content.document" & $sElement
  1553. Local $RetVal = _FFCmd(StringFormat("FFau3.simulateEvent(%s,'%s','%s',%s);",$sElement,$sType,$sEventType, $iKeyCode ))
  1554. If Not @error And $RetVal <> "_FFCmd_Err" Then
  1555. Return $RetVal
  1556. Else
  1557. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$sElement: " & $sElement))
  1558. Return 0
  1559. EndIf
  1560. Return 0
  1561. EndFunc ;==>_FFDispatchEvent
  1562. ; #FUNCTION# ===================================================================
  1563. ; Name ..........: _FFLoadWait
  1564. ; Description ...: Wait while the page is loading.
  1565. ; Beschreibung ..: Wartet bis die Seite geladen ist.
  1566. ; AutoIt Version : V3.3.0.0
  1567. ; Syntax ........: _FFLoadWait([$iTimeOut = $_FF_LOADWAIT_TIMEOUT])
  1568. ; Parameter(s): .: $iTimeOut - Optional: (Default = $_FF_LOADWAIT_TIMEOUT) : Timeout while waiting in ms
  1569. ; Return Value ..: Success - 1
  1570. ; @EXTENDED - loading time in ms
  1571. ; Failure - 0
  1572. ; @ERROR -
  1573. ; @EXTENDED - loading time in ms
  1574. ; Author(s) .....: Thorsten Willert
  1575. ; Date ..........: Thu Nov 05 18:27:55 CET 2009
  1576. ; Link ..........: https://developer.mozilla.org/en/nsIWebProgress
  1577. ; Related .......: _FFDialogWait
  1578. ; Example .......: Yes
  1579. ; ==============================================================================
  1580. Func _FFLoadWait($iTimeOut = $_FF_LOADWAIT_TIMEOUT)
  1581. Local Const $sFuncName = "_FFLoadWait"
  1582. Local $iLoadingTime = 0
  1583. If $iTimeOut < 1000 Then $iTimeOut = 1000
  1584. Local $bTrace = $_FF_COM_TRACE
  1585. $_FF_COM_TRACE = False
  1586. If Not $_FF_COM_TRACE Then ConsoleWrite("_FFLoadWait: ")
  1587. Local $TimeOutTimer = TimerInit()
  1588. While TimerDiff($TimeOutTimer) < $iTimeOut
  1589. If Not $_FF_COM_TRACE Then ConsoleWrite(".")
  1590. If Not _FFCmd("window.getBrowser().webProgress.isLoadingDocument") And _
  1591. _FFCmd("window.getBrowser().webProgress.busyFlags") = 0 Then
  1592. $iLoadingTime = Round(TimerDiff($TimeOutTimer))
  1593. ConsoleWrite(" loaded in " & $iLoadingTime & "ms" & @CRLF)
  1594. Sleep($_FF_CON_DELAY + 25)
  1595. $_FF_COM_TRACE = $bTrace
  1596. Return SetError(0, $iLoadingTime - $_FF_CON_DELAY - 25, 1)
  1597. EndIf
  1598. Sleep(250)
  1599. WEnd
  1600. $_FF_COM_TRACE = $bTrace
  1601. ConsoleWrite(@CRLF & @CRLF)
  1602. Return SetError(__FFError($sFuncName, $_FF_ERROR_Timeout, "Can not check site status."), $iLoadingTime, 0)
  1603. EndFunc ;==>_FFLoadWait
  1604. ; #FUNCTION# ===================================================================
  1605. ; Name ..........: _FFGetObjectInfo
  1606. ; Description ...: Returns a 2-dimensional array with every information of an object.
  1607. ; Beschreibung ..: Liefert ein 2-dimensionales Array mit allen Informationen über ein Objekt.
  1608. ; AutoIt Version : V3.3.0.0
  1609. ; Syntax ........: _FFGetObjectInfo([$sObject = "window"])
  1610. ; Parameter(s): .: $sObject - Optional: (Default = "window") :
  1611. ; Return Value ..: Success - Array with object information
  1612. ; Failure -
  1613. ; @ERROR -
  1614. ; Author(s) .....: Thorsten Willert
  1615. ; Date ..........: Mon Mar 23 23:05:55 CET 2009 @962 /Internet Time/
  1616. ; Link ..........:
  1617. ; Related .......:
  1618. ; Example .......: Yes
  1619. ; ==============================================================================
  1620. Func _FFGetObjectInfo($sObject = "window")
  1621. Local Const $sFuncName = "_FFGetObjectInfo"
  1622. Local $aRet[1][2], $aTmp
  1623. If StringLeft($sObject, 1) = "." Then $sObject = "window.content.document" & $sObject
  1624. Local $aInfo = StringSplit(_FFCmd("repl.inspect(" & $sObject & ");"), @CRLF, 2)
  1625. If Not @error And IsArray($aInfo) And $aInfo <> "_FFCmd_Err" Then
  1626. ReDim $aRet[UBound($aInfo)][2]
  1627. For $i = 0 To UBound($aInfo) - 1
  1628. $aTmp = StringRegExp($aInfo[$i], "<object>.(.*?)=(.*?)$", 3)
  1629. If Not @error And IsArray($aTmp) Then
  1630. $aRet[$i][0] = $aTmp[0]
  1631. $aRet[$i][1] = $aTmp[1]
  1632. EndIf
  1633. Next
  1634. Return $aRet
  1635. Else
  1636. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, $sObject))
  1637. Return $aRet[0][0] = 0
  1638. EndIf
  1639. EndFunc ;==>_FFGetObjectInfo
  1640. ; #FUNCTION# ===================================================================
  1641. ; Name ..........: _FFGetPosition
  1642. ; Description ...: Returns an array with the position of an element and/or the position and size of the FireFox content area, relative to the client area of the window
  1643. ; Beschreibung ..: Liefert ein Array mit der Position eines Elementes und/oder die Position und Größe des FireFox-Inhalts, relativ zur Client Area des Fensters
  1644. ; AutoIt Version : V3.3.0.0
  1645. ; Syntax ........: _FFGetPosition([$sElement = ""])
  1646. ; Parameter(s): .: $sElement - Optional: (Default = "") : Element or FFau3 - object.
  1647. ; An empty string returns only the position and size of the content area
  1648. ; Return Value ..: Success - array with the position and sizes
  1649. ; | [0] = X position of the element (relative to the document)
  1650. ; | [1] = Y position of the element (relative to the document)
  1651. ; | [2] = X position of the content area (relative to the window client)
  1652. ; | [3] = Y position of the content area (relative to the window client)
  1653. ; | [4] = width of the content area
  1654. ; | [6] = height of the content area
  1655. ; Failure -
  1656. ; @ERROR -
  1657. ; Author(s) .....: Thorsten Willert
  1658. ; Date ..........: Wed Nov 04 18:17:25 CET 2009
  1659. ; Link ..........:
  1660. ; Related .......:
  1661. ; Example .......: Yes
  1662. ; ==============================================================================
  1663. Func _FFGetPosition($sElement = "")
  1664. Local Const $sFuncName = "_FFGetPosition"
  1665. Local $aElement[2] = [-1,-1]
  1666. If $sElement <> "" Then
  1667. If StringLeft($sElement, 7) = "OBJECT|" Then $sElement = StringMid($sElement, 8)
  1668. If StringLeft($sElement, 1) = "." Then $sElement = "window.content.document" & $sElement
  1669. Local $sPos = _FFCmd("FFau3.findPos(" & $sElement & ")")
  1670. If $sPos <> "_FFCmd_Err" Then
  1671. $aElement = StringSplit($sPos,' ',2)
  1672. Else
  1673. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sElement not found: " & $sElement))
  1674. Return
  1675. EndIf
  1676. EndIf
  1677. Local $aContent = ControlGetPos(_FFCmd(".title"), "", "[CLASS:MozillaContentWindowClass]")
  1678. If @error Then
  1679. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "Cant find 'MozillaContentWindowClass'-control"))
  1680. Return
  1681. EndIf
  1682. Local $aRet[6] = [$aElement[0] , $aElement[1], $aContent[0], $aContent[1], $aContent[2], $aContent[3]]
  1683. Return $aRet
  1684. EndFunc ;==> _FF_GetPosition
  1685. ; #FUNCTION# ===================================================================
  1686. ; Name ..........: _FFOpenURL
  1687. ; Description ...: Opens a new URL
  1688. ; Beschreibung ..: Öffnet eine URL.
  1689. ; AutoIt Version : V3.3.0.0
  1690. ; Syntax ........: _FFOpenURL($sURL[, $bWait = True])
  1691. ; Parameter(s): .: $sURL - URL or chrome (shortcut)
  1692. ; $bLoadWait - Optional: (Default = True) :
  1693. ; Return Value ..: Success - 1
  1694. ; Failure - 0
  1695. ; @ERROR -
  1696. ; Author(s) .....: Thorsten Willert
  1697. ; Date ..........: Mon Mar 23 23:05:21 CET 2009 @962 /Internet Time/
  1698. ; Link ..........:
  1699. ; Related .......: _FFTabAdd
  1700. ; Example .......: Yes
  1701. ; ==============================================================================
  1702. Func _FFOpenURL($sURL, $bLoadWait = True)
  1703. Local Const $sFuncName = "_FFOpenURL"
  1704. If Not __FFCheckURL($sURL) Then
  1705. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(URL) $sURL: " & $sURL))
  1706. Return 0
  1707. EndIf
  1708. If StringLeft($sURL, 7) = "chrome:" Then $sURL = __FFChromeSelect(StringMid($sURL, 8))
  1709. ConsoleWrite("_FFOpenURL: " & $sURL & @CRLF)
  1710. Local $sRetVal = _FFCmd(StringFormat(".location.href='%s';", $sURL))
  1711. If Not @error And $sRetVal = $sURL Then
  1712. If $bLoadWait Then Return _FFLoadWait()
  1713. Return 1
  1714. Else
  1715. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, $sURL))
  1716. Return 0
  1717. EndIf
  1718. EndFunc ;==>_FFOpenURL
  1719. ; #FUNCTION# ===================================================================
  1720. ; Name ..........: _FFPrefReset
  1721. ; Description ...: Resets a config entry
  1722. ; Beschreibung ..: Setzt einen Eintrag in der Config zurück
  1723. ; Syntax ........: _FFPrefReset($sName)
  1724. ; Parameter(s): .: $sName - Name of the config entry
  1725. ; Return Value ..: Success - 1
  1726. ; Failure - 0
  1727. ; @ERROR -
  1728. ; Author(s) .....: Thorsten Willert
  1729. ; Modified ......: Wed Mar 25 18:06:53 CET 2009 @754 /Internet Time/
  1730. ; Link ..........: https://developer.mozilla.org/en/nsIPrefBranch, http://kb.mozillazine.org/About:config_entries
  1731. ; Related .......: _FFPrefSet, _FFPrefGet
  1732. ; Example .......: Yes
  1733. ; ==============================================================================
  1734. Func _FFPrefReset($sName)
  1735. Local Const $sFuncName = "_FFPrefReset"
  1736. Local $iType = _FFCmd('FFau3.obj=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);FFau3.obj.getPrefType("' & $sName & '");')
  1737. If @error Then
  1738. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$sName: " & $sName))
  1739. Return 0
  1740. EndIf
  1741. If $iType <> 0 Then
  1742. If Not _FFCmd('FFau3.obj.prefHasUserValue("' & $sName & '");') Then Return 1
  1743. _FFCmd('FFau3.obj.clearUserPref("' & $sName & '");')
  1744. If Not @error Then Return 1
  1745. Else
  1746. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sName: " & $sName))
  1747. EndIf
  1748. Return 0
  1749. EndFunc ;==>_FFPrefReset
  1750. ; #FUNCTION# ===================================================================
  1751. ; Name ..........: _FFPrefGet
  1752. ; Description ...: Gets a config entry
  1753. ; Beschreibung ..: Ließt einen Wert aus der Config aus
  1754. ; Syntax ........: _FFPrefGet($sName)
  1755. ; Parameter(s): .: $sName - Name of the config entry
  1756. ; Return Value ..: Success - Value of the entry
  1757. ; Failure - 0 and sets @error
  1758. ; @ERROR -
  1759. ; Author(s) .....: Thorsten Willert
  1760. ; Modified ......: Wed Mar 25 18:06:59 CET 2009 @754 /Internet Time/
  1761. ; Link ..........: https://developer.mozilla.org/en/nsIPrefBranch, http://kb.mozillazine.org/About:config_entries
  1762. ; Related .......: _FFPrefSet, _FFPrefReset
  1763. ; Example .......: Yes
  1764. ; ==============================================================================
  1765. Func _FFPrefGet($sName)
  1766. Local Const $sFuncName = "_FFPrefGet"
  1767. Local $sCommand
  1768. Local $iType = _FFCmd('FFau3.obj=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); FFau3.obj.getPrefType("' & $sName & '");')
  1769. If @error Then
  1770. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, $sName))
  1771. Return 0
  1772. EndIf
  1773. Switch $iType
  1774. Case 0
  1775. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sName: " & $sName))
  1776. Return 0
  1777. Case 32 ; PREF_STRING
  1778. $sCommand = "getCharPref"
  1779. Case 64 ; PREF_INT
  1780. $sCommand = "getIntPref"
  1781. Case 128 ; PREF_BOOL
  1782. $sCommand = "getBoolPref"
  1783. EndSwitch
  1784. $sCommand = StringFormat('FFau3.obj.%s("%s");', $sCommand, $sName)
  1785. Return _FFCmd($sCommand)
  1786. EndFunc ;==>_FFPrefGet
  1787. ; #FUNCTION# ===================================================================
  1788. ; Name ..........: _FFPrefSet
  1789. ; Description ...: Sets a config entry
  1790. ; Beschreibung ..: Setzt einen Wert in der Config.
  1791. ; Syntax ........: _FFPrefSet($sName, $vValue)
  1792. ; Parameter(s): .: $sName - Name of the config entry
  1793. ; $vValue - Value of the config entry
  1794. ; Return Value ..: Success - 1 and sets @EXTENDED
  1795. ; Failure - 0
  1796. ; @ERROR -
  1797. ; @EXTENDED - Old value
  1798. ; Author(s) .....: Thorsten Willert
  1799. ; Modified ......: Wed Mar 25 18:07:07 CET 2009 @754 /Internet Time/
  1800. ; Link ..........: https://developer.mozilla.org/en/nsIPrefBranch, http://kb.mozillazine.org/About:config_entries
  1801. ; Related .......: _FFPrefGet, _FFPrefReset
  1802. ; Example .......: Yes
  1803. ; ==============================================================================
  1804. Func _FFPrefSet($sName, $vValue)
  1805. Local Const $sFuncName = "_FFPrefSet"
  1806. Local $sCommand
  1807. Local $iType = _FFCmd('FFau3.obj=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);FFau3.obj.getPrefType("' & $sName & '");')
  1808. If @error Then
  1809. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, $sName))
  1810. Return 0
  1811. EndIf
  1812. Local $vOldValue = _FFPrefGet($sName)
  1813. Switch $iType
  1814. Case 0
  1815. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sName: " & $sName))
  1816. Return 0
  1817. Case 32 ; PREF_STRING
  1818. If Not IsString($vValue) Then
  1819. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(string) $vValue: " & $vValue))
  1820. Return 0
  1821. EndIf
  1822. $sCommand = StringFormat('FFau3.obj.%s("%s","%s");', "setCharPref", $sName, $vValue)
  1823. Case 64 ; PREF_INT
  1824. If Not IsInt($vValue) Then
  1825. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vValue: " & $vValue))
  1826. Return 0
  1827. EndIf
  1828. $sCommand = StringFormat('FFau3.obj.%s("%s",%s);', "setIntPref", $sName, $vValue)
  1829. Case 128 ; PREF_BOOL
  1830. If Not IsBool($vValue) Then
  1831. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(bool) $vValue: " & $vValue))
  1832. Return 0
  1833. EndIf
  1834. $sCommand = StringFormat('FFau3.obj.%s("%s",%s);', "setBoolPref", $sName, __FFB2S($vValue))
  1835. EndSwitch
  1836. _FFCmd($sCommand)
  1837. If Not @error Then
  1838. Local $vRetVal = _FFPrefGet($sName)
  1839. If Not @error And $vRetVal = $vValue Then
  1840. SetExtended($vOldValue)
  1841. Return 1
  1842. Else
  1843. SetError(__FFError($sFuncName, $_FF_ERROR_RetValue, "$vValue <> " & $vRetVal))
  1844. Return 0
  1845. EndIf
  1846. EndIf
  1847. Return 0
  1848. EndFunc ;==>_FFPrefSet
  1849. ; #FUNCTION# ===================================================================
  1850. ; Name ..........: _FFQuit
  1851. ; Description ...: Quits FireFox
  1852. ; Beschreibung ..: Schließt FireFox
  1853. ; AutoIt Version : V3.3.0.0
  1854. ; Syntax ........: _FFQuit()
  1855. ; Parameter(s): .:
  1856. ; Return Value ..: Success - 1 / $_FF_GLOBAL_SOCKET = -1
  1857. ; Failure - 0
  1858. ; @ERROR -
  1859. ; Author(s) .....: Thorsten Willert
  1860. ; Date ..........: Sat Mar 14 14:44:55 CET 2009 @614 /Internet Time/
  1861. ; Link ..........:
  1862. ; Related .......: _FFDisConnect
  1863. ; Example .......: Yes
  1864. ; ==============================================================================
  1865. Func _FFQuit()
  1866. Local Const $sFuncName = "_FFQuit"
  1867. If $_FF_GLOBAL_SOCKET = -1 Then Return
  1868. If Not __FFIsSocket($_FF_GLOBAL_SOCKET) Then
  1869. SetError(__FFError($sFuncName, $_FF_ERROR_SocketError))
  1870. Return 0
  1871. EndIf
  1872. TCPSend($_FF_GLOBAL_SOCKET, "close()" & @CRLF)
  1873. If Not @error Then
  1874. $_FF_FRAME = "top"
  1875. $_FF_GLOBAL_SOCKET = -1
  1876. If $_FF_COM_TRACE Then ConsoleWrite('__FFQuit: Closing FireFox ...' & @CRLF)
  1877. Return 1
  1878. Else
  1879. Return 0
  1880. EndIf
  1881. EndFunc ;==>_FFQuit
  1882. ; #FUNCTION# ===================================================================
  1883. ; Name ..........: _FFReadHTML
  1884. ; Description ...: Returns the HTML-source code of a page.
  1885. ; Beschreibung ..: Liefert den HTMl-Quellcode einer Seite.
  1886. ; AutoIt Version : V3.3.0.0
  1887. ; Syntax ........: _FFReadHTML([$sMode = "body"[, $iFilter = 0]])
  1888. ; Parameter(s): .: $sMode - Optional: (Default = "body") :
  1889. ; | body = innerHTML from <body>
  1890. ; | html = innerHTML from <html>
  1891. ; $iFilter - Optional: (Default = 0) : you can add them:
  1892. ; | 0 = No filter
  1893. ; | 1 = Remove all non ASCII
  1894. ; | 2 = Remove all double withespaces
  1895. ; | 4 = Remove all double linefeeds
  1896. ; | 8 = Remove all HTML-tags
  1897. ; | 16 = simple html-tag / entities convertor
  1898. ; Return Value ..: Success - String with the HTML-source code
  1899. ; Failure - ""
  1900. ; @ERROR -
  1901. ; Author(s) .....: Thorsten Willert
  1902. ; Date ..........: Mon Mar 23 22:55:56 CET 2009 @955 /Internet Time/
  1903. ; Link ..........:
  1904. ; Related .......: _FFReadText, _FFXPath
  1905. ; Example .......: Yes
  1906. ; ==============================================================================
  1907. Func _FFReadHTML($sMode = "body", $iFilter = 0)
  1908. Local Const $sFuncName = "_FFReadHTML"
  1909. Local $sCommand
  1910. Switch StringLower($sMode)
  1911. Case "body"
  1912. $sCommand = ".body"
  1913. Case "html"
  1914. $sCommand = ".documentElement"
  1915. Case Else
  1916. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(body|html) $sMode: " & $sMode))
  1917. Return 0
  1918. EndSwitch
  1919. Local $sRetVal = _FFCmd($sCommand & ".innerHTML;", 10000)
  1920. If Not @error And $sRetVal <> "_FFCmd_Err" Then
  1921. If $iFilter > 0 Then $sRetVal = __FFFilterString($sRetVal, $iFilter)
  1922. Return $sRetVal
  1923. Else
  1924. SetError(1)
  1925. Return ""
  1926. EndIf
  1927. EndFunc ;==>_FFReadHTML
  1928. ; #FUNCTION# ===================================================================
  1929. ; Name ..........: _FFReadText
  1930. ; Description ...: Returns the text of a page.
  1931. ; Beschreibung ..: Liefert den Text einer Seite.
  1932. ; AutoIt Version : V3.3.0.0
  1933. ; Syntax ........: _FFReadText([$iFilter = 0])
  1934. ; Parameter(s): .: $iFilter - Optional: (Default = 0) : you can add them:
  1935. ; | 0 = No filter
  1936. ; | 1 = Remove all non ASCII
  1937. ; | 2 = Remove all double withespaces
  1938. ; | 4 = Remove all double linefeeds
  1939. ; | 8 = Remove all HTML-tags
  1940. ; | 16 = simple html-tag / entities convertor
  1941. ; Return Value ..: Success - String
  1942. ; Failure - ""
  1943. ; @ERROR -
  1944. ; Author(s) .....: Thorsten Willert
  1945. ; Date ..........: Mon Mar 23 22:55:05 CET 2009 @954 /Internet Time/
  1946. ; Link ..........:
  1947. ; Related .......: _FFReadHTML, _FFXPath
  1948. ; Example .......: Yes
  1949. ; ==============================================================================
  1950. Func _FFReadText($iFilter = 0)
  1951. ;Local Const $sFuncName = "_FFReadText"
  1952. Local $sRetVal = _FFCmd(".documentElement.textContent;", 10000)
  1953. If Not @error And $sRetVal <> "_FFCmd_Err" Then
  1954. If $iFilter > 0 Then $sRetVal = __FFFilterString($sRetVal, $iFilter)
  1955. Return $sRetVal
  1956. Else
  1957. SetError(1)
  1958. Return ""
  1959. EndIf
  1960. EndFunc ;==>_FFReadText
  1961. ; #FUNCTION# ===================================================================
  1962. ; Name ..........: _FFSearch
  1963. ; Description ...: Searches a string
  1964. ; Beschreibung ..: Sucht einen Text.
  1965. ; AutoIt Version : V3.3.0.0
  1966. ; Syntax ........: _FFSearch($sSearchString[, $bCaseSensitive = false[, $bBackwards = false[, $bWrapAround = true[, $bWholeWord = false[, $bSearchInFrames = true]]]]])
  1967. ; Parameter(s): .: $sSearchString - String to search
  1968. ; $bCaseSensitive - Optional: (Default = false) :
  1969. ; $bBackwards - Optional: (Default = false) :
  1970. ; $bWrapAround - Optional: (Default = true) :
  1971. ; $bWholeWord - Optional: (Default = false) :
  1972. ; $bSearchInFrames - Optional: (Default = true) :
  1973. ; Return Value ..: Success - 1
  1974. ; Failure - 0 and sets
  1975. ; @ERROR -
  1976. ; Author(s) .....: Thorsten Willert
  1977. ; Date ..........: Mon Mar 23 22:54:33 CET 2009 @954 /Internet Time/
  1978. ; Link ..........:
  1979. ; Related .......: _FFAction
  1980. ; Example .......: Yes
  1981. ; ==============================================================================
  1982. Func _FFSearch($sSearchString, $bCaseSensitive = False, $bBackwards = False, $bWrapAround = True, $bWholeWord = False, $bSearchInFrames = True)
  1983. Local Const $sFuncName = "_FFSearch"
  1984. If $sSearchString = "" Then
  1985. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "Empty String $sSearchString"))
  1986. Return ""
  1987. EndIf
  1988. If $bCaseSensitive = Default Then $bCaseSensitive = False
  1989. If $bBackwards = Default Then $bBackwards = False
  1990. If $bWrapAround = Default Then $bWrapAround = True
  1991. If $bWholeWord = Default Then $bWholeWord = False
  1992. If $bSearchInFrames = Default Then $bSearchInFrames = True
  1993. Local $sCommand = 'content.find("' & $sSearchString & '", ' & _
  1994. __FFB2S($bCaseSensitive) & ', ' & _
  1995. __FFB2S($bBackwards) & ', ' & _
  1996. __FFB2S($bWrapAround) & ', ' & _
  1997. __FFB2S($bWholeWord) & ', ' & _
  1998. __FFB2S($bSearchInFrames) & ', false);'
  1999. Local $RetVal = _FFCmd($sCommand)
  2000. If Not @error And $RetVal <> "_FFCmd_Err" Then
  2001. Return 1
  2002. Else
  2003. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sSearchString: " & $sSearchString))
  2004. Return 0
  2005. EndIf
  2006. EndFunc ;==>_FFSearch
  2007. ; #FUNCTION# ===================================================================
  2008. ; Name ..........: _FFCmd
  2009. ; Description ...: Send and receive data from Firefox.
  2010. ; Beschreibung ..: Sendet und empfängt Daten von FireFox.
  2011. ; AutoIt Version : V3.3.0.0
  2012. ; Syntax ........: _FFCmd($sArg[, $iTimeOut = 30000[, $bTry = True[, $bRec = True]]])
  2013. ; Parameter(s): .: $sArg - Any JavaScript
  2014. ; $iTimeOut - Optional: (Default = 30000) :
  2015. ; $bTry - Optional: (Default = True) : adds try/catch to $sArg
  2016. ; $bRec - Optional: (Default = True) : record command
  2017. ; Return Value ..: Success - String
  2018. ; Failure - ""
  2019. ; @ERROR -
  2020. ; Author(s) .....: Thorsten Willert
  2021. ; Date ..........: Fri Sep 18 06:03:57 CEST 2009 @211 /Internet Time/
  2022. ; Link ..........:
  2023. ; Related .......:
  2024. ; Example .......: Yes
  2025. ; ==============================================================================
  2026. Func _FFCmd($sArg, $iTimeOut = 30000, $bTry = True)
  2027. Local Const $sFuncName = "_FFCmd"
  2028. Local $sRet
  2029. If StringLeft($sArg, 1) = "." Then $sArg = "window.content.document" & $sArg
  2030. If $bTry And Not StringInStr(StringLower($sArg), "try") Then $sArg = "try{" & $sArg & "}catch(e){'_FFCmd_Err';};"
  2031. Local $sArgWrapped = StringReplace($sArg, "window.content.document", "window.content.wrappedJSObject.document")
  2032. $sArg = StringReplace($sArg, "window.content.document", "window.content." & $_FF_FRAME & ".document")
  2033. $sArgWrapped = StringReplace($sArgWrapped, "window.content.wrappedJSObject.document", "window.content.wrappedJSObject." & $_FF_FRAME & ".document")
  2034. If (Not StringInStr($sArg, ".frames[")) Or StringInStr($sArg, "evaluate") Or (Not StringRegExp($sArg, "\.[a-zA-z]+\(.*?\)(\[.+\])?\.", 0)) Then
  2035. If __FFSend($sArg) Then
  2036. $sRet = __FFRecv($iTimeOut)
  2037. If Not @error Or String($sRet) <> "_FFCmd_Err" Then
  2038. Return $sRet
  2039. ElseIf StringInStr($sArgWrapped, "wrappedJSObject") Then
  2040. __FFSend($sArgWrapped)
  2041. $sRet = __FFRecv($iTimeOut)
  2042. If Not @error And String($sRet) <> "_FFCmd_Err" Then Return $sRet
  2043. EndIf
  2044. EndIf
  2045. Else
  2046. __FFSend($sArgWrapped)
  2047. $sRet = __FFRecv($iTimeOut)
  2048. If Not @error And String($sRet) <> "_FFCmd_Err" Then Return $sRet
  2049. EndIf
  2050. SetError(__FFError($sFuncName, $_FF_ERROR_RetValue, $sRet))
  2051. Return ""
  2052. EndFunc ;==>_FFCmd
  2053. ; #FUNCTION# ===================================================================
  2054. ; Name ..........: _FFSetValue
  2055. ; Description ...: Sets a value of an element
  2056. ; Beschreibung ..: Setzt den Wert (value) eines Elements
  2057. ; AutoIt Version : V3.3.0.0
  2058. ; Syntax ........: _FFSetValue($sValue, $sElement[, $sMode = "elements"[, $iIndex = 0]])
  2059. ; Parameter(s): .: $sElement -
  2060. ; $sMode - Optional: (Default = "elements") :
  2061. ; | elements: element or object from _FFXpath or _FFObj*
  2062. ; | id
  2063. ; | name
  2064. ; | class
  2065. ; | tag
  2066. ; $iIndex - Optional: (Default = 0) : index if $sMode = class, name, tag
  2067. ; Return Value ..: Success - 1
  2068. ; Failure - 0
  2069. ; @ERROR -
  2070. ; Author(s) .....: Thorsten Willert
  2071. ; Date ..........: Wed Sep 23 22:55:36 CEST 2009
  2072. ; Link ..........:
  2073. ; Related .......: _FFSetValue, _FFXPath
  2074. ; Example .......: Yes
  2075. ; ==============================================================================
  2076. Func _FFSetValue($sValue, $sElement, $sMode = "elements", $iIndex = 0)
  2077. Local Const $sFuncName = "_FFSetValue"
  2078. If Not IsInt($iIndex) Then
  2079. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iIndex: " & $iIndex))
  2080. Return 0
  2081. EndIf
  2082. Switch StringLower($sMode)
  2083. Case "elements"
  2084. If StringLeft($sElement, 7) = "OBJECT|" Then $sElement = StringMid($sElement, 8)
  2085. Case "id"
  2086. $sElement = ".getElementById('" & $sElement & "')"
  2087. Case "name"
  2088. $sElement = ".getElementsByName('" & $sElement & "')[" & $iIndex & "]"
  2089. Case "class"
  2090. $sElement = ".getElementsByClassName('" & $sElement & "')[" & $iIndex & "]"
  2091. Case "tag"
  2092. $sElement = ".getElementsByTagName('" & $sElement & "')[" & $iIndex & "]"
  2093. Case Else
  2094. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(elements|id|name|class|tag) $sMode: " & $sMode))
  2095. Return 0
  2096. EndSwitch
  2097. __FFValue2JavaScript($sValue)
  2098. Local $sRetVal = _FFCmd($sElement & ".value='" & $sValue & "'")
  2099. If Not @error And $sRetVal <> "_FFCmd_Err" Then
  2100. Return 1
  2101. Else
  2102. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sElement: " & $sElement))
  2103. Return 0
  2104. EndIf
  2105. EndFunc
  2106. ; #FUNCTION# ===================================================================
  2107. ; Name ..........: _FFStart
  2108. ; Description ...: Starts FireFox
  2109. ; Beschreibung ..: Startet FireFox
  2110. ; AutoIt Version : V3.3.0.0
  2111. ; Syntax ........: _FFStart([$sURL = "about:blank"[, $sProfile = "default"[, $iMode = 1[, $bHide = False[, $IP = "127.0.0.1"[, $iPort = 4242]]]]]])
  2112. ; Parameter(s): .: $sURL - Optional: (Default = "about:blank") : Start URL
  2113. ; $sProfile - Optional: (Default = "default") : User profile
  2114. ; $iMode - Optional: (Default = 1) : Start mode:
  2115. ; | 0 = Connect to existing process
  2116. ; | 1 = Start new process
  2117. ; | 2 = Connect to an existing process, on failure start a new process
  2118. ; | +8 = Starting FF with parameter -no-remote
  2119. ; $bHide - Optional: (Default = False) : Start in hidden mode
  2120. ; $IP - Optional: (Default = "127.0.0.1") : IP of MozRepl
  2121. ; $iPort - Optional: (Default = 4242) : Port number of MozRepl
  2122. ; Return Value ..: Success - 1
  2123. ; @EXTENDED - PID
  2124. ; Failure - 0
  2125. ; @ERROR -
  2126. ; Author(s) .....: Thorsten Willert
  2127. ; Date ..........: Thu Apr 30 22:10:07 CEST 2009
  2128. ; Link ..........:
  2129. ; Related .......: _FFQuit, _FFConnect, _FFDisConnect, _FFIsConnected
  2130. ; Example .......: Yes
  2131. ; ==============================================================================
  2132. Func _FFStart($sURL = "about:blank", $sProfile = "default", $iMode = 1, $bHide = False, $IP = "127.0.0.1", $iPort = 4242)
  2133. Local Const $sFuncName = "_FFStart"
  2134. ; Default parameters
  2135. If $sURL = Default Then $sURL = "about:blank"
  2136. If $IP = Default Then $IP = "127.0.0.1"
  2137. If $iPort = Default Then $iPort = 4242
  2138. If Not __FFCheckURL($sURL) Then
  2139. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(URL) $sURL: " & $sURL))
  2140. Return 0
  2141. EndIf
  2142. If Not __FFIsIP($IP) Then
  2143. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(IP) $IP: " & $IP))
  2144. Return 0
  2145. EndIf
  2146. If Not __FFIsPort($iPort) Then
  2147. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(PORT) $iPort: " & $iPort))
  2148. Return 0
  2149. EndIf
  2150. ; Default parameters
  2151. If $sProfile = Default Then $sProfile = "default"
  2152. If $iMode = Default Then $iMode = 1
  2153. If $bHide = Default Then $bHide = False
  2154. Local $PID = -1, $bNoRemote = False
  2155. If $iMode >= 8 Then
  2156. $iMode -= 8
  2157. $bNoRemote = True
  2158. EndIf
  2159. Switch $iMode
  2160. Case 2
  2161. ContinueCase
  2162. Case 0
  2163. If ProcessExists($_FF_PROC_NAME) Then _FFConnect($IP, $iPort)
  2164. If $_FF_GLOBAL_SOCKET > -1 Then
  2165. _FFOpenURL($sURL)
  2166. ElseIf $iMode = 2 Then
  2167. ContinueCase
  2168. EndIf
  2169. Case 1
  2170. __FFStartProcess($sURL, True, $sProfile, $bNoRemote, $bHide, $iPort)
  2171. $PID = @extended
  2172. If ProcessExists($_FF_PROC_NAME) Then _FFConnect($IP, $iPort)
  2173. If $_FF_GLOBAL_SOCKET > -1 Then _FFLoadWait()
  2174. Case Else
  2175. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$iMode: " & $iMode))
  2176. Return 0
  2177. EndSwitch
  2178. If $bHide Then
  2179. Local $hWin = _FFWindowGetHandle()
  2180. WinSetState($hWin, "", @SW_HIDE)
  2181. EndIf
  2182. SetExtended($PID)
  2183. Return 1
  2184. EndFunc ;==>_FFStart
  2185. ; #FUNCTION# ===================================================================
  2186. ; Name ..........: _FFTabAdd
  2187. ; Description ...: Opens a new tab.
  2188. ; Beschreibung ..: Öffnet einen neuen Tab
  2189. ; AutoIt Version : V3.3.0.0
  2190. ; Syntax ........: _FFTabAdd([$sURL = "about:blank"[, $bSelect = True[, $bLoadWait = True]]])
  2191. ; Parameter(s): .: $sURL - Optional: (Default = "about:blank") :
  2192. ; $bSelect - Optional: (Default = true) : Select new tab
  2193. ; $bLoadWait - Optional: (Default = true) : Wait while the page is loading
  2194. ; Return Value ..: Success - 1
  2195. ; Failure - 0
  2196. ; @ERROR -
  2197. ; Author(s) .....: Thorsten Willert
  2198. ; Date ..........: Mon Mar 23 22:44:43 CET 2009 @947 /Internet Time/
  2199. ; Link ..........: https://developer.mozilla.org/en/XUL/tabs
  2200. ; Related .......: _FFTabDuplicate, _FFTabClose, _FFTabCloseAll, _FFTabExists, _FFTabSetSelected, _FFTabGetSelected
  2201. ; Example .......: Yes
  2202. ; ==============================================================================
  2203. Func _FFTabAdd($sURL = "about:blank", $bSelect = True, $bLoadWait = True)
  2204. Local Const $sFuncName = "_FFOpenURL"
  2205. If $sURL = Default Then $sURL = "about:blank"
  2206. If Not __FFCheckURL($sURL) Then
  2207. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(URL) $sURL: " & $sURL))
  2208. Return 0
  2209. EndIf
  2210. If $bSelect Then
  2211. _FFCmd("gBrowser.selectedTab = gBrowser.addTab('" & $sURL & "')", 3000)
  2212. If Not @error Then
  2213. If $bLoadWait Then Return _FFLoadWait()
  2214. Return 1
  2215. EndIf
  2216. Else
  2217. _FFCmd("gBrowser.loadOneTab('" & $sURL & "',null,null,null,true)", 3000)
  2218. If Not @error Then
  2219. If $bLoadWait Then Return _FFLoadWait()
  2220. Return 1
  2221. EndIf
  2222. EndIf
  2223. Return 0
  2224. EndFunc ;==>_FFTabAdd
  2225. ; #FUNCTION# ===================================================================
  2226. ; Name ..........: _FFTabClose
  2227. ; Description ...: Closes one or all existing tabs.
  2228. ; Beschreibung ..: Schließt einen oder alle vorhandenen Tabs.
  2229. ; AutoIt Version : V3.3.0.0
  2230. ; Syntax ........: _FFTabClose([$vTab = -1[, $sMode = "index"]])
  2231. ; Parameter(s): .: $vTab - Optional: (Default = -1 = current tab) :
  2232. ; | index (0-n)
  2233. ; | label
  2234. ; | prev
  2235. ; | next
  2236. ; | first
  2237. ; | last
  2238. ; | all (except current)
  2239. ; $sMode - Optional: (Default = "index") :
  2240. ; | index
  2241. ; | label
  2242. ; | key or keyword
  2243. ; Return Value ..: Success - 1
  2244. ; Failure - 0
  2245. ; @ERROR -
  2246. ; Author(s) .....: Thorsten Willert
  2247. ; Date ..........: Mon Aug 03 16:13:15 CEST 2009
  2248. ; Link ..........: https://developer.mozilla.org/en/XUL/tabs
  2249. ; Related .......: _FFTabAdd, _FFTabDuplicate, _FFTabCloseAll, _FFTabExists, _FFTabSetSelected, _FFTabGetSelected
  2250. ; Example .......: Yes
  2251. ; ==============================================================================
  2252. Func _FFTabClose($vTab = -1, $sMode = "index")
  2253. Local Const $sFuncName = "_FFTabClose"
  2254. Local $sCommand
  2255. ;Local $bWarn
  2256. Local $iLength = _FFGetLength("tabs")
  2257. Switch StringLower($sMode)
  2258. Case "index"
  2259. If $vTab = -1 Then
  2260. $sCommand = "gBrowser.removeCurrentTab();"
  2261. ElseIf $vTab > -1 And $vTab < $iLength Then
  2262. $sCommand = "gBrowser.removeTab(gBrowser.mTabs[" & $vTab & "]);"
  2263. Else
  2264. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(int) $vTab: " & $vTab))
  2265. Return 0
  2266. EndIf
  2267. Case "label"
  2268. If _FFTabExists($vTab) Then
  2269. $sCommand = "gBrowser.removeTab(gBrowser.mTabs[" & @extended & "]);"
  2270. Else
  2271. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$vTab: " & $vTab))
  2272. Return 0
  2273. EndIf
  2274. Case "key", "keyword"
  2275. Switch StringLower($vTab)
  2276. Case "prev"
  2277. $sCommand = "gBrowser.removeTab(gBrowser.mTabs[gBrowser.tabContainer.selectedIndex-1]);"
  2278. Case "next"
  2279. $sCommand = "gBrowser.removeTab(gBrowser.mTabs[gBrowser.tabContainer.selectedIndex+1]);"
  2280. Case "first"
  2281. $sCommand = "gBrowser.removeTab(gBrowser.mTabs[0]);"
  2282. Case "last"
  2283. $sCommand = "gBrowser.removeTab(gBrowser.mTabs[gBrowser.tabContainer.childNodes.length-1]);"
  2284. Case "all"
  2285. ; browser.tabs.warnOnClose
  2286. $sCommand = "gBrowser.removeAllTabsBut(gBrowser.selectedTab);"
  2287. Case Else
  2288. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(prev|next|first|last|all) $vTab: " & $vTab))
  2289. Return 0
  2290. EndSwitch
  2291. Case Else
  2292. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|label|key|keyword) $sMode: " & $sMode))
  2293. Return 0
  2294. EndSwitch
  2295. If _FFCmd($sCommand & "gBrowser.tabContainer.childNodes.length", 3000) < $iLength - 1 Then
  2296. Sleep(100)
  2297. Return 1
  2298. EndIf
  2299. Return 0
  2300. EndFunc ;==>_FFTabClose
  2301. ; #FUNCTION# ===================================================================
  2302. ; Name ..........: _FFTabDuplicate
  2303. ; Description ...: Duplicates a tab
  2304. ; Beschreibung ..: Dupliziert einen Tab
  2305. ; AutoIt Version : V3.3.0.0
  2306. ; Syntax ........: _FFTabDuplicate([$vTab = -1[, $sMode = "index"[, $bSelect = False]]])
  2307. ; Parameter(s): .: $vTab - Optional: (Default = -1) : Tab to duplicate, -1 = current tab
  2308. ; $sMode - Optional: (Default = "index") :
  2309. ; | index
  2310. ; | label
  2311. ; $bToFront - Optional: (Default = false) : Bring duplicated tab to front
  2312. ; Return Value ..: Success - Lenght of tabs >= 1
  2313. ; Failure - 0
  2314. ; @ERROR -
  2315. ; Author(s) .....: Thorsten Willert
  2316. ; Date ..........: Mon Aug 03 16:13:08 CEST 2009
  2317. ; Link ..........: https://developer.mozilla.org/en/XUL/tabs
  2318. ; Related .......: _FFTabAdd, _FFTabClose, _FFTabCloseAll, _FFTabExists, _FFTabSetSelected, _FFTabGetSelected
  2319. ; Example .......: Yes
  2320. ; ==============================================================================
  2321. Func _FFTabDuplicate($vTab = -1, $sMode = "index", $bSelect = False)
  2322. Local Const $sFuncName = "_FFTabDuplicate"
  2323. If $sMode = "index" And Not IsInt($vTab) Then
  2324. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vTab: " & $vTab))
  2325. Return 0
  2326. EndIf
  2327. If $vTab = Default Then $vTab = -1
  2328. If $sMode = Default Then $sMode = "index"
  2329. Local $iRet
  2330. Local $sCommand
  2331. Switch StringLower($sMode)
  2332. Case "index"
  2333. If $vTab = -1 Then
  2334. $sCommand = "gBrowser.duplicateTab(gBrowser.mCurrentTab);"
  2335. ElseIf $vTab >= 0 And $vTab < _FFGetLength("tabs") Then
  2336. $sCommand = "gBrowser.duplicateTab(gBrowser.mTabs[" & $vTab & "]);"
  2337. Else
  2338. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$vTab: " & $vTab))
  2339. Return 0
  2340. EndIf
  2341. Case "label"
  2342. If _FFTabExists($vTab) Then
  2343. $sCommand = "gBrowser.duplicateTab(gBrowser.mTabs[" & @extended & "]);"
  2344. Else
  2345. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$vTab: " & $vTab))
  2346. Return 0
  2347. EndIf
  2348. Case Else
  2349. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|label) $sMode: " & $sMode))
  2350. Return 0
  2351. EndSwitch
  2352. $iRet = _FFCmd($sCommand & "gBrowser.tabContainer.childNodes.length;", 3000)
  2353. If $bSelect Then _FFTabSetSelected("last")
  2354. Return $iRet
  2355. EndFunc ;==>_FFTabDuplicate
  2356. ; #FUNCTION# ===================================================================
  2357. ; Name ..........: _FFTabExists
  2358. ; Description ...: Checks if a tab exists
  2359. ; Beschreibung ..: Prüft ob ein Tab existiert.
  2360. ; AutoIt Version : V3.3.0.0
  2361. ; Syntax ........: _FFTabExists($sLabel)
  2362. ; Parameter(s): .: $sLabel - Label of the tab (substring or RegEx)
  2363. ; Return Value ..: Success - 1
  2364. ; @EXTENDED - Index of the tab
  2365. ; Failure - 0
  2366. ; @ERROR -
  2367. ; Author(s) .....: Thorsten Willert
  2368. ; Date ..........: Mon Jul 27 08:47:03 CEST 2009
  2369. ; Link ..........: https://developer.mozilla.org/en/XUL/tabs
  2370. ; Related .......: _FFTabAdd, _FFTabDuplicate, _FFTabClose, _FFTabCloseAll, _FFTabSetSelected, _FFTabGetSelected
  2371. ; Example .......: Yes
  2372. ; ==============================================================================
  2373. Func _FFTabExists($sLabel)
  2374. Local Const $sFuncName = "_FFTabExists"
  2375. _FFLoadWait()
  2376. Local $RetVal = Int(_FFCmd("FFau3.SearchTab('" & $sLabel & "')", 3000))
  2377. Switch @error
  2378. Case $_FF_ERROR_Success
  2379. If $RetVal > -1 Then
  2380. SetExtended($RetVal)
  2381. Return 1
  2382. ElseIf $RetVal = -3 Then
  2383. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidExpression, "$sLabel: " & $sLabel))
  2384. Return 0
  2385. Else
  2386. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sLabel: " & $sLabel))
  2387. Return 0
  2388. EndIf
  2389. Case Else
  2390. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError))
  2391. Return 0
  2392. EndSwitch
  2393. EndFunc ;==>_FFTabExists
  2394. ; #FUNCTION# ===================================================================
  2395. ; Name ..........: _FFTabSetSelected
  2396. ; Description ...: Select a tab
  2397. ; Beschreibung ..: Wählt ein Tab aus.
  2398. ; AutoIt Version : V3.3.0.0
  2399. ; Syntax ........: _FFTabSetSelected([$vTab = 0[, $sMode = "index"]])
  2400. ; Parameter(s): .: $vTab - Optional: (Default = 0) :
  2401. ; | index (0-n)
  2402. ; | label = Substring or RegEx
  2403. ; | prev
  2404. ; | next
  2405. ; | first
  2406. ; | last
  2407. ; $sMode - Optional: (Default = "index") :
  2408. ; | index
  2409. ; | label
  2410. ; | otherwise the keywords in $vTab are used
  2411. ; Return Value ..: Success -
  2412. ; Failure - -1
  2413. ; @ERROR -
  2414. ; Author(s) .....: Thorsten Willert
  2415. ; Date ..........: Mon Aug 03 16:12:59 CEST 2009
  2416. ; Link ..........: https://developer.mozilla.org/en/XUL/tabs
  2417. ; Related .......: _FFTabAdd, _FFTabDuplicate, _FFTabClose, _FFTabCloseAll, _FFTabExists, _FFTabGetSelected
  2418. ; Example .......: Yes
  2419. ; ==============================================================================
  2420. Func _FFTabSetSelected($vTab = 0, $sMode = "index")
  2421. Local Const $sFuncName = "_FFTabSetSelected"
  2422. Local $sCommand = "gBrowser.tabContainer"
  2423. If $sMode = "index" Then
  2424. $sCommand &= ".selectedIndex = " & $vTab
  2425. ElseIf $sMode = "label" Then
  2426. If _FFTabExists($vTab) Then
  2427. $sCommand &= ".selectedIndex = " & @extended
  2428. Else
  2429. Return -1
  2430. EndIf
  2431. Else
  2432. Switch StringLower($vTab)
  2433. Case "prev"
  2434. $sCommand &= ".advanceSelectedTab( -1, true )"
  2435. Case "next"
  2436. $sCommand &= ".advanceSelectedTab( 1, true )"
  2437. Case "first"
  2438. $sCommand &= ".selectedIndex = 0"
  2439. Case "last"
  2440. $sCommand &= ".selectedIndex = gBrowser.tabContainer.childNodes.length -1"
  2441. Case Else
  2442. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|label|prev|next|first|last) $sMode: " & $sMode))
  2443. Return -1
  2444. EndSwitch
  2445. EndIf
  2446. Local $RetVal = _FFCmd($sCommand, 3000)
  2447. Sleep(50)
  2448. Return $RetVal
  2449. EndFunc ;==>_FFTabSetSelected
  2450. ; #FUNCTION# ===================================================================
  2451. ; Name ..........: _FFTabGetSelected
  2452. ; Description ...: Returns the name or the index of the selected tab.
  2453. ; Beschreibung ..: Gibt den Namen (label) oder den Index des aktuellen Tabs zurück.
  2454. ; AutoIt Version : V3.3.0.0
  2455. ; Syntax ........: _FFTabGetSelected([$sMode = "index"])
  2456. ; Parameter(s): .: $sMode - Optional: (Default = "index") :
  2457. ; | index
  2458. ; | label
  2459. ; Return Value ..: Success - Tab index 0-n or label
  2460. ; Failure - -1
  2461. ; @ERROR -
  2462. ; Author(s) .....: Thorsten Willert
  2463. ; Date ..........: Thu Apr 23 08:52:13 CEST 2009 @327 /Internet Time/
  2464. ; Link ..........: https://developer.mozilla.org/en/XUL/tabs
  2465. ; Related .......: _FFTabAdd, _FFTabDuplicate, _FFTabClose, _FFTabCloseAll, _FFTabExists, _FFTabSetSelected
  2466. ; Example .......: Yes
  2467. ; ==============================================================================
  2468. Func _FFTabGetSelected($sMode = "index")
  2469. Local Const $sFuncName = "_FFTabGetSelected"
  2470. _FFLoadWait()
  2471. Switch StringLower($sMode)
  2472. Case "index"
  2473. Return Int(_FFCmd("gBrowser.tabContainer.selectedIndex", 3000))
  2474. Case "label"
  2475. Return _FFCmd("gBrowser.mTabs[gBrowser.tabContainer.selectedIndex].label", 3000)
  2476. Case Else
  2477. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|label) $sMode: " & $sMode))
  2478. Return -1
  2479. EndSwitch
  2480. EndFunc ;==>_FFTabGetSelected
  2481. ; #FUNCTION# ===================================================================
  2482. ; Name ..........: _FFTableWriteToArray
  2483. ; Description ...: Writes a HTML-table to an array
  2484. ; Beschreibung ..: Kopiert eine HTML-Tabelle in ein Array.
  2485. ; AutoIt Version : V3.3.0.0
  2486. ; Syntax ........: _FFTableWriteToArray([$vTable = 0[, $sMode = "index"[, $sReturnMode = "text"[, $iFilter = 0[, $bTransponse = False]]]]])
  2487. ; Parameter(s): .: $vTable - Optional: (Default = 0) : Table selection by $sMode
  2488. ; $sMode - Optional: (Default = "index") :
  2489. ; | index (0-n)
  2490. ; | name
  2491. ; | id
  2492. ; $sReturnMode - Optional: (Default = "text") :
  2493. ; | text
  2494. ; | html
  2495. ; $iFilter - Optional: (Default = 0) :
  2496. ; | 0 = No filter
  2497. ; | 1 = Remove all non ASCII
  2498. ; | 2 = Remove all double withespaces
  2499. ; | 4 = Remove all double linefeeds
  2500. ; | 8 = Remove all HTML-tags
  2501. ; | 16 = simple html-tag / entities convertor
  2502. ; $bTransponse - Optional: (Default = False) : Switch Rows and Columns
  2503. ; Return Value ..: Success - Array containing contents of the table
  2504. ; Failure - 0
  2505. ; @ERROR -
  2506. ; Author(s) .....: Thorsten Willert, Johannes Schirmer
  2507. ; Date ..........: Fri Sep 18 17:38:05 CEST 2009 @693 /Internet Time/
  2508. ; Link ..........:
  2509. ; Related .......: _FFXpath
  2510. ; Example .......: Yes
  2511. ; ==============================================================================
  2512. Func _FFTableWriteToArray($vTable = 0, $sMode = "index", $sReturnMode = "text", $iFilter = 0, $bTransponse = False)
  2513. Local $sFuncName = "_FFTableWriteToArray"
  2514. Local $sTable, $sRnd
  2515. Local $bTrace = $_FF_COM_TRACE
  2516. $_FF_COM_TRACE = False
  2517. Switch StringLower($sMode)
  2518. Case "index"
  2519. If IsInt($vTable) And $vTable < _FFGetLength("tables") Then
  2520. $sTable = "//table[" & $vTable + 1 & "]"
  2521. Else
  2522. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(INT) $vTable: " & $vTable))
  2523. Return 0
  2524. EndIf
  2525. Case "name"
  2526. $sTable = "//table[@name='" & $vTable & "']"
  2527. Case "id"
  2528. $sTable = "//table[@id='" & $vTable & "']"
  2529. Case Else
  2530. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(index|name|id) $sMode: " & $sMode))
  2531. Return 0
  2532. EndSwitch
  2533. Switch StringLower($sReturnMode)
  2534. Case "text"
  2535. $sReturnMode = "textContent"
  2536. Case "html"
  2537. $sReturnMode = "innerHTML"
  2538. Case Else
  2539. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(text|html) $sReturnMode: " & $sReturnMode))
  2540. Return 0
  2541. EndSwitch
  2542. If Not IsInt($iFilter) Then
  2543. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iFilter: " & $iFilter))
  2544. Return 0
  2545. EndIf
  2546. If Not IsBool($bTransponse) Then
  2547. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(boolean) $bTransponse: " & $bTransponse))
  2548. Return 0
  2549. EndIf
  2550. Local $iRows = _FFXpath($sTable & "//tr", Default, 10)
  2551. If @error Or $iRows = 0 Then
  2552. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, $sTable & " not found."))
  2553. Return 0
  2554. EndIf
  2555. Local $aCols
  2556. If _FFXPath($sTable & "//@colspan", Default, 10) > 0 Or _FFXPath($sTable & "//@rowspan", Default, 10) > 0 Then
  2557. Local $iColsTmp[$iRows + 1]
  2558. Local $iCols = 0, $iSum, $iCol
  2559. For $i = 1 To $iRows
  2560. $iSum = 0
  2561. $aCols = _FFXpath($sTable & "//tr[" & $i & "]//td", "colSpan", 6)
  2562. $iColsTmp[$i - 1] = $aCols[0]
  2563. For $j = 1 To $aCols[0]
  2564. $iSum += $aCols[$j]
  2565. Next
  2566. If $iSum > $iCols Then $iCols = $iSum
  2567. Next
  2568. Local $aTable[$iRows][$iCols]
  2569. Local $iRow = 0
  2570. Local $sCmd, $aTmp
  2571. For $i = 0 To $iRows
  2572. $sRnd = "FF" & Random(100,999,1)
  2573. $iCol = 0
  2574. If $iColsTmp[$i] < $iCols Then
  2575. For $j = 0 To $iColsTmp[$i] - 1
  2576. $sCmd = "FFau3.xpath=window.content.document.evaluate('//tr[" & $i + 1 & "]//td[" & $j + 1 & "]',window.content.document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;FFau3.xpath." & $sReturnMode & "+'" & $sRnd & "'+FFau3.xpath.colSpan"
  2577. $aTmp = StringSplit(_FFCmd($sCmd), $sRnd, 3)
  2578. $aTable[$iRow][$iCol] = __FFFilterString($aTmp[0], $iFilter)
  2579. $iCol += $aTmp[1]
  2580. Next
  2581. Else
  2582. Local $aRows = _FFXpath($sTable & "//tr[" & $i + 1 & "]//td", $sReturnMode, 6, $iFilter)
  2583. If $aRows[0] > 0 Then
  2584. For $j = 1 To $aRows[0]
  2585. $aTable[$i][$j - 1] = $aRows[$j]
  2586. Next
  2587. EndIf
  2588. EndIf
  2589. $iRow += 1
  2590. Next
  2591. Else
  2592. $iCols = _FFXpath($sTable & "//tr[last()]//td", Default, 10)
  2593. Local $aTable[$iRows][$iCols]
  2594. If $iCols > $iRows Then
  2595. For $i = 0 To $iRows - 1
  2596. $aCols = _FFXpath($sTable & "//tr[" & $i + 1 & "]//td", $sReturnMode, 6, $iFilter)
  2597. If $aCols[0] > 0 Then
  2598. For $j = 0 To $iCols - 1
  2599. $aTable[$i][$j] = $aCols[$j + 1]
  2600. Next
  2601. EndIf
  2602. Next
  2603. Else
  2604. For $i = 0 To $iCols - 1
  2605. $aRows = _FFXpath($sTable & "//tr//td[" & $i + 1 & "]", $sReturnMode, 6, $iFilter)
  2606. If $aRows[0] > 0 Then
  2607. For $j = 0 To $iRows - 1
  2608. $aTable[$j][$i] = $aRows[$i + 1]
  2609. Next
  2610. EndIf
  2611. Next
  2612. EndIf
  2613. EndIf
  2614. If $bTransponse Then
  2615. Local $iD1 = UBound($aTable, 1), $iD2 = UBound($aTable, 2), $aTmp[$iD2][$iD1]
  2616. For $i = 0 To $iD2 - 1
  2617. For $j = 0 To $iD1 - 1
  2618. $aTmp[$i][$j] = $aTable[$j][$i]
  2619. Next
  2620. Next
  2621. $aTable = $aTmp
  2622. EndIf
  2623. $_FF_COM_TRACE = $bTrace
  2624. Return $aTable
  2625. EndFunc ;==>_FFTableWriteToArray
  2626. ; #FUNCTION# ===================================================================
  2627. ; Name ..........: _FFWindowClose
  2628. ; Description ...: Closes a browser window
  2629. ; Beschreibung ..: Schließt ein Browser Fenster.
  2630. ; Syntax ........: _FFWindowClose([$sSearch = ""[, $sSearchMode = "title"]])
  2631. ; Parameter(s): .: $sSearch - Optional: (Default = "") : "" = current window, Substring to search
  2632. ; $sSearchMode - Optional: (Default = "title") :
  2633. ; | "title" window title
  2634. ; | "label" tab label
  2635. ; | "href" current url
  2636. ; Return Value ..: Success - 1
  2637. ; Failure - 0
  2638. ; @ERROR -
  2639. ; Author(s) .....: Thorsten Willert
  2640. ; Date ..........: Mon Mar 23 22:33:01 CET 2009 @939 /Internet Time/
  2641. ; Link ..........: https://developer.mozilla.org/En/DOM/Window, https://developer.mozilla.org/En/NsIWindowMediator
  2642. ; Related .......: _FFWindowSelect, _FFWindowOpen
  2643. ; Example .......: Yes
  2644. ; ==============================================================================
  2645. Func _FFWindowClose($sSearch = "", $sSearchMode = "title")
  2646. Local Const $sFuncName = "_FFWindowClose"
  2647. If $sSearch = "" Then
  2648. _FFCmd("window.close();")
  2649. Return @error
  2650. EndIf
  2651. Switch StringLower($sSearchMode)
  2652. Case "title", "label", "href" ; current href
  2653. Local $sRetVal = _FFCmd(StringFormat("FFau3.CloseWin('%s','%s')", $sSearch, $sSearchMode))
  2654. If Not @error And $sRetVal = 1 Then
  2655. Return 1
  2656. Else
  2657. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sSearch: " & $sSearch))
  2658. EndIf
  2659. Case Else
  2660. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(title|label|href) $sSearchMode: " & $sSearchMode))
  2661. EndSwitch
  2662. Return 0
  2663. EndFunc ;==>_FFWindowClose
  2664. ; #FUNCTION# ===================================================================
  2665. ; Name ..........: _FFWindowGetHandle
  2666. ; Description ...: Returns the window-handle (hwnd) from the current browser-window.
  2667. ; Beschreibung ..: Liefert das Window-handle (hwnd) des aktuellen Browser Fenster.
  2668. ; AutoIt Version : V3.3.0.0
  2669. ; Syntax ........: _FFWindowGetHandle()
  2670. ; Parameter(s): .:
  2671. ; Return Value ..: Success - Window handle
  2672. ; Failure - ""
  2673. ; @ERROR -
  2674. ; Author(s) .....: Thorsten Willert
  2675. ; Date ..........: Sun Oct 18 21:35:12 CEST 2009
  2676. ; Link ..........:
  2677. ; Related .......: _FFWindowClose, _FFWindowSelect, _FFWindowOpen
  2678. ; Example .......: Yes
  2679. ; ==============================================================================
  2680. Func _FFWindowGetHandle()
  2681. Local Const $sFuncName = "_FFWindowGetHandle"
  2682. ; in the future to handle with XPCOM =#=
  2683. Local $bErr = False
  2684. Local $hWindow = ""
  2685. BlockInput(1) ; =#=
  2686. If Not @error Then
  2687. Local $sTitleRnd = "FFAU3" & Random(1000000000, 9999999999, 1)
  2688. _FFCmd("FFau3.tmp=document.title;document.title='" & $sTitleRnd & "'")
  2689. Local $iMatchMode = AutoItSetOption("WinTitleMatchMode", 1)
  2690. Sleep(500)
  2691. $hWindow = WinGetHandle($sTitleRnd)
  2692. If @error Then $bErr = True
  2693. AutoItSetOption("WinTitleMatchMode", $iMatchMode)
  2694. _FFCmd("document.title=FFau3.tmp")
  2695. ConsoleWrite("_FFWindowGetHandle: " & $hWindow & @CRLF)
  2696. EndIf
  2697. BlockInput(0)
  2698. If $bErr Then SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError))
  2699. Return $hWindow
  2700. EndFunc ;==>_FFWindowGetHandle
  2701. ; #FUNCTION# ===================================================================
  2702. ; Name ..........: _FFWindowSelect
  2703. ; Description ...: Selects the active window for all other functions
  2704. ; Beschreibung ..: Wählt das aktive Browser Fenster für alle nachfolgenden Befehle.
  2705. ; Syntax ........: _FFWindowSelect([$sSearch = ""[, $sSearchMode = "title"[, $bActivate = True]]])
  2706. ; Parameter(s): .: $sSearch - Optional: (Default = "") : "" = most recent window, Substring to search
  2707. ; $sSearchMode - Optional: (Default = "title") :
  2708. ; | "title" window title
  2709. ; | "label" tab label
  2710. ; | "href" current url
  2711. ; $bActivate - Optional: (Default = True) :
  2712. ; Return Value ..: Success - 1
  2713. ; @EXTENDED - Window handle
  2714. ; Failure - 0
  2715. ; @ERROR -
  2716. ; @EXTENDED - ""
  2717. ; Author(s) .....: Thorsten Willert
  2718. ; Date ..........: Mon Mar 23 22:32:05 CET 2009 @938 /Internet Time/
  2719. ; Link ..........: https://developer.mozilla.org/En/DOM/Window, https://developer.mozilla.org/En/NsIWindowMediator
  2720. ; Related .......: _FFWindowOpen, _FFWindowClose, _FFWindowGetHandle
  2721. ; Example .......: Yes
  2722. ; ==============================================================================
  2723. Func _FFWindowSelect($sSearch = "", $sSearchMode = "title", $bActivate = True)
  2724. Local Const $sFuncName = "_FFWindowSelect"
  2725. Local $hWin = ""
  2726. If $sSearch = "" Then
  2727. Local $sCommand = 'Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser")'
  2728. _FFCmd("repl.enter(" & $sCommand & ")")
  2729. If Not @error Then
  2730. $hWin = _FFWindowGetHandle()
  2731. If Not @error And $bActivate Then WinActivate($hWin)
  2732. SetExtended($hWin)
  2733. Return 1
  2734. EndIf
  2735. SetExtended($hWin)
  2736. Return 0
  2737. EndIf
  2738. Switch StringLower($sSearchMode)
  2739. Case "title", "label", "href"
  2740. Local $sRetVal = _FFCmd(StringFormat("FFau3.SelectWin('%s','%s','navigator:browser');", $sSearch, $sSearchMode))
  2741. If Not @error And $sRetVal = 1 Then
  2742. $hWin = _FFWindowGetHandle()
  2743. If Not @error And $bActivate Then WinActivate($hWin)
  2744. SetExtended($hWin)
  2745. Return 1
  2746. Else
  2747. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sSearch: " & $sSearch), $hWin)
  2748. EndIf
  2749. Case Else
  2750. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(title|label|href) $sSearchMode: " & $sSearchMode), $hWin)
  2751. EndSwitch
  2752. SetExtended($hWin)
  2753. Return 0
  2754. EndFunc ;==>_FFWindowSelect
  2755. ; #FUNCTION# ===================================================================
  2756. ; Name ..........: _FFWindowOpen
  2757. ; Description ...: Opens a new browser window
  2758. ; Beschreibung ..: Öffnet ein neues Browser Fenster.
  2759. ; Syntax ........: _FFWindowOpen([$sURL = "about:blank"[, $bActivate = True[, $bLoadWait = True]]])
  2760. ; Parameter(s): .: $sURL - Optional: (Default = "about:blank") :
  2761. ; $bActivate - Optional: (Default = True)
  2762. ; $bLoadWait - Optional: (Default = True) :
  2763. ; Return Value ..: Success - 1 and sets
  2764. ; @EXTENDED - Window handle
  2765. ; Failure - 0 and sets
  2766. ; @ERROR -
  2767. ; @EXTENDED - ""
  2768. ; Author(s) .....: Thorsten Willert
  2769. ; Date ..........: Fri Nov 13 18:31:06 CET 2009
  2770. ; Link ..........: https://developer.mozilla.org/En/DOM/Window, https://developer.mozilla.org/En/NsIWindowMediator
  2771. ; Related .......: _FFWindowSelect, _FFWindowClose, _FFWindowGetHandle
  2772. ; Example .......: Yes
  2773. ; ==============================================================================
  2774. Func _FFWindowOpen($sURL = "about:blank", $bActivate = True, $bLoadWait = True)
  2775. Local Const $sFuncName = "_FFWindowOpen"
  2776. If Not __FFCheckURL($sURL) Then
  2777. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(URL) $sURL: " & $sURL))
  2778. Return 0
  2779. EndIf
  2780. Local $bTrace = $_FF_COM_TRACE
  2781. $_FF_COM_TRACE = False
  2782. ConsoleWrite("_FFWindowOpen: " & $sURL & @CRLF)
  2783. _FFCmd("window.open('" & $sURL & "');")
  2784. If $bLoadWait Then _FFLoadWait()
  2785. If Not @error Then
  2786. If _FFWindowSelect() Then
  2787. Local $hWin = @extended
  2788. If Not @error And $bActivate Then WinActivate($hWin)
  2789. __FFSendJavaScripts()
  2790. $_FF_COM_TRACE = $bTrace
  2791. SetExtended($hWin)
  2792. Return 1
  2793. EndIf
  2794. EndIf
  2795. $_FF_COM_TRACE = $bTrace
  2796. SetExtended("")
  2797. Return 0
  2798. EndFunc ;==>_FFWindowOpen
  2799. ; #FUNCTION# ===================================================================
  2800. ; Name ..........: _FFWriteHTML
  2801. ; Description ...: Replaces the html of body element
  2802. ; Beschreibung ..: Ersetzt das HTML des Body Elements.
  2803. ; Syntax ........: _FFWriteHTML([$sHTML = ""[, $sMode = "body"]])
  2804. ; Parameter(s): .: $sHTML - Optional: (Default = "") :
  2805. ; $sMode - Optional: (Default = "body") :
  2806. ; | body
  2807. ; | html
  2808. ; Return Value ..: Success - 1
  2809. ; Failure - 0
  2810. ; @ERROR -
  2811. ; Author(s) .....: Thorsten Willert
  2812. ; Date ..........: Mon Mar 23 22:30:01 CET 2009 @937 /Internet Time/
  2813. ; Link ..........:
  2814. ; Related .......:
  2815. ; Example .......: Yes
  2816. ; ==============================================================================
  2817. Func _FFWriteHTML($sHTML = "", $sMode = "body")
  2818. Local Const $sFuncName = "_FFWriteHTML"
  2819. Local $sCommand
  2820. Switch StringLower($sMode)
  2821. Case "body"
  2822. $sCommand = "body"
  2823. Case "html"
  2824. $sCommand = "documentElement"
  2825. Case Else
  2826. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(body|html) $sMode: " & $sMode))
  2827. Return 0
  2828. EndSwitch
  2829. $sCommand = StringFormat("content.document.%s.innerHTML='" & $sHTML & "';", $sCommand)
  2830. Local $sRetVal = _FFCmd($sCommand)
  2831. If Not @error And $sRetVal <> "_FFCmd_Err" Then Return 1
  2832. Return 0
  2833. EndFunc ;==>_FFWriteHTML
  2834. ; #FUNCTION# ===================================================================
  2835. ; Name ..........: _FFXPath
  2836. ; Description ...: Returns and sets values due to a XPath-query.
  2837. ; Beschreibung ..: Abfrage und setzen von Werten anhand einer XPath-Abfrage.
  2838. ; AutoIt Version : V3.3.0.0
  2839. ; Syntax ........: _FFXPath($sQuery[, $sAttribute = "textContent"[, $iReturnType = 2[, $iFilter = 0]]])
  2840. ; Parameter(s): .: $sQuery - XPath query
  2841. ; $sAttribute - Optional: (Default = "textContent") : attribute OR searchstring for SEARCH
  2842. ; $iReturnType - Optional: (Default = 0) :
  2843. ; | 0 = ANY_TYPE
  2844. ; | 1 = NUMBER_TYPE (Returns numberValue)
  2845. ; | 2 = STRING_TYPE (Return stringValue)
  2846. ; | 3 = BOOLEAN_TYPE (Returns booleanValue)
  2847. ; | 4 = UNORDERED_NODE_ITERATOR_TYPE - not implemented
  2848. ; | 5 = ORDERED_NODE_ITERATOR_TYPE - not implemented
  2849. ; | 6 = UNORDERED_NODE_SNAPSHOT_TYPE (Returns arrray)
  2850. ; | 7 = ORDERED_NODE_SNAPSHOT_TYPE (Returns arrray)
  2851. ; | 8 = ANY_UNORDERED_NODE_TYPE (Returns singleNodeValue) (Object in FFau3.xpath)
  2852. ; | 9 = FIRST_ORDERED_NODE_TYPE (Returns singleNodeValue) (Object in FFau3.xpath)
  2853. ; | 10 = COUNT (Returns the number of matches)
  2854. ; | 11 = CONTAINS (stringValue contains substring in $sAttribute) (Returns booleanValue)
  2855. ; | 12 = STARTS-WITH (stringValue start-with string in $sAttribute) (Returns booleanValue)
  2856. ; | 13 = SUBSTRING-AFTER (stringValue substring-after in $sAttribute)
  2857. ; | 14 = SUBSTRING-BEFORE (stringValue substring-bevore in $sAttribute)
  2858. ; $iFilter - Optional: (Default = 0) :
  2859. ; | 0 = No filter
  2860. ; | 1 = Remove all non ASCII
  2861. ; | 2 = Remove all double withespaces
  2862. ; | 4 = Remove all double linefeeds
  2863. ; | 8 = Remove all HTML-tags
  2864. ; | 16 = simple html-tag / entities convertor
  2865. ; Return Value ..: Success - Value $iReturnType 0-5 and 8-10
  2866. ; | Value $iReturnType 8-9 + object FFau3.xpath
  2867. ; | Array $iReturnType 6-7 or if an attribute is set the number of the matches.
  2868. ; Failure - 0 and sets
  2869. ; @ERROR -
  2870. ; Author(s) .....: Thorsten Willert
  2871. ; Date ..........: Fri Sep 18 06:06:26 CEST 2009 @212 /Internet Time/
  2872. ; Link ..........: http://www.w3.org/TR/xpath, https://developer.mozilla.org/en/XPath, https://developer.mozilla.org/En/XPathResult, https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript
  2873. ; Related .......: _FFGetValue, _FFSetValue
  2874. ; Example .......: Yes
  2875. ; ==============================================================================
  2876. Func _FFXPath($sQuery, $sAttribute = "textContent", $iReturnType = 2, $iFilter = 0)
  2877. Local Const $sFuncName = "_FFXPath"
  2878. If $sQuery = "" Then
  2879. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "Empty String $sQuery"))
  2880. Return 0
  2881. EndIf
  2882. If Not IsInt($iFilter) Then
  2883. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $iFilter: " & $iFilter))
  2884. Return 0
  2885. EndIf
  2886. If $iReturnType < 10 And Not StringInStr($sAttribute, "=") And StringRegExp($sAttribute, "[\W]+") Then
  2887. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$sAttribute: " & $sAttribute))
  2888. Return 0
  2889. EndIf
  2890. If $sAttribute = Default Then $sAttribute = "textContent"
  2891. If $iReturnType = Default Then $iReturnType = 0
  2892. $sQuery = StringReplace($sQuery, '"', "'")
  2893. Local $sResult, $sValue
  2894. Switch StringLower($sAttribute)
  2895. Case "textcontent"
  2896. $sAttribute = "textContent"
  2897. Case "innerhtml"
  2898. $sAttribute = "innerHTML"
  2899. EndSwitch
  2900. Switch $iReturnType
  2901. Case 0
  2902. $sResult = "ANY_TYPE"
  2903. Case 1
  2904. $sResult = "NUMBER_TYPE"
  2905. $sValue = ".numberValue"
  2906. Case 2
  2907. $sResult = "STRING_TYPE"
  2908. $sValue = ".stringValue"
  2909. Case 3
  2910. $sResult = "BOOLEAN_TYPE"
  2911. $sValue = ".booleanValue"
  2912. #cs - not implemented yet
  2913. Case 4
  2914. $sResult = "UNORDERED_NODE_ITERATOR_TYPE"
  2915. Case 5
  2916. $sResult = "ORDERED_NODE_ITERATOR_TYPE"
  2917. #ce
  2918. Case 6
  2919. $sResult = "UNORDERED_NODE_SNAPSHOT_TYPE"
  2920. If $sAttribute <> "" And StringLeft($sAttribute, 1) <> "." Then $sValue &= "." & $sAttribute
  2921. Case 7
  2922. $sResult = "ORDERED_NODE_SNAPSHOT_TYPE"
  2923. If $sAttribute <> "" And StringLeft($sAttribute, 1) <> "." Then $sValue &= "." & $sAttribute
  2924. Case 8
  2925. $sResult = "ANY_UNORDERED_NODE_TYPE"
  2926. $sValue = ".singleNodeValue"
  2927. If $sAttribute <> "" And StringLeft($sAttribute, 1) <> "." Then $sValue &= "." & $sAttribute
  2928. Case 9
  2929. $sResult = "FIRST_ORDERED_NODE_TYPE"
  2930. $sValue = ".singleNodeValue"
  2931. If $sAttribute <> "" And StringLeft($sAttribute, 1) <> "." Then $sValue &= "." & $sAttribute
  2932. ; no datatypes
  2933. Case 10
  2934. $sQuery = "count(" & $sQuery & ")"
  2935. $sResult = "NUMBER_TYPE"
  2936. $sValue = ".numberValue"
  2937. Case 11
  2938. $sQuery = "contains(" & $sQuery & ",'" & $sAttribute & "')"
  2939. $sResult = "BOOLEAN_TYPE"
  2940. $sValue = ".booleanValue"
  2941. Case 12
  2942. $sQuery = "starts-with(" & $sQuery & ",'" & $sAttribute & "')"
  2943. $sResult = "BOOLEAN_TYPE"
  2944. $sValue = ".booleanValue"
  2945. Case 13
  2946. $sQuery = "substring-after(" & $sQuery & ",'" & $sAttribute & "')"
  2947. $sResult = "STRING_TYPE"
  2948. $sValue = ".stringValue"
  2949. Case 14
  2950. $sQuery = "substring-before(" & $sQuery & ",'" & $sAttribute & "')"
  2951. $sResult = "STRING_TYPE"
  2952. $sValue = ".stringValue"
  2953. Case Else
  2954. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(int) $iReturnType: 0-9 10-14: " & $iReturnType))
  2955. Return 0
  2956. EndSwitch
  2957. Local $sErrVal = "_FFXPath_Error: "
  2958. Local $sCommand
  2959. If $iReturnType < 6 Or $iReturnType >= 8 Then
  2960. $sCommand = 'try{FFau3.xpath=window.content.document.evaluate("' & $sQuery & '",window.content.document,null,XPathResult.' & $sResult & ',null)'
  2961. $sCommand &= $sValue & ";}catch(e){'" & $sErrVal & "'+e;};"
  2962. ElseIf $iReturnType = 6 Or $iReturnType = 7 Then
  2963. Local $sDelimiter = "FF" & Random(100, 999, 1)
  2964. $sCommand = 'try{with(FFau3){'
  2965. $sCommand &= 'this.obj=window.content.document.evaluate("' & $sQuery & '",window.content.document,null,XPathResult.' & $sResult & ',null);'
  2966. $sCommand &= 'this.tmp=this.obj.snapshotLength;'
  2967. If Not StringInStr($sAttribute, "=") Then
  2968. $sCommand &= 'for(var i=0;i<this.obj.snapshotLength;i++){this.tmp+="' & $sDelimiter & '"+this.obj.snapshotItem(i)' & $sValue & ';};'
  2969. Else
  2970. $sCommand &= 'for(var i=0;i<this.obj.snapshotLength;i++){this.obj.snapshotItem(i)' & $sValue & ';};'
  2971. EndIf
  2972. $sCommand &= "this.tmp;}}catch(e){'" & $sErrVal & "' +e;};"
  2973. EndIf
  2974. Local $sRetVal = _FFCmd("FFau3.xpath=null;" & $sCommand)
  2975. If Not StringInStr($sRetVal, $sErrVal) Then
  2976. __FFFilterString($sRetVal, $iFilter)
  2977. If $iFilter > 0 Then __FFFilterString($sRetVal, $iFilter)
  2978. If $iReturnType = 6 Or $iReturnType = 7 Then
  2979. Return StringSplit($sRetVal, $sDelimiter, 3)
  2980. Else
  2981. If $iReturnType < 10 And $sAttribute = "" Then Return "OBJECT|FFau3.xpath"
  2982. Return StringStripWS($sRetVal, 3)
  2983. EndIf
  2984. Else
  2985. If StringInStr($sRetVal, "TypeError") And StringInStr($sRetVal, "is null") Then
  2986. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "singleNodeValue is null $sQuery: " & $sQuery & " - " & $sAttribute))
  2987. ElseIf StringInStr($sRetVal, "NS_ERROR_DOM_INVALID_EXPRESSION_ERR") Then
  2988. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidExpression, "NS_ERROR_DOM_INVALID_EXPRESSION_ERR $sQuery: " & $sQuery))
  2989. Else
  2990. SetError(__FFError($sFuncName, $_FF_ERROR_RetValue, $sRetVal))
  2991. EndIf
  2992. Return 0
  2993. EndIf
  2994. EndFunc ;==>_FFXPath
  2995. ; #FUNCTION# ===================================================================
  2996. ; Name ..........: _FFObjGet
  2997. ; Description ...: Returns an object (string to use with the other _FFObj* functions)
  2998. ; Beschreibung ..: Liefert ein Object zurueck. (String zur Verwendung mit den anderen _FFObj* Funktionen)
  2999. ; AutoIt Version : V3.3.0.0
  3000. ; Syntax ........: _FFObjGet($sElement[, $sMode = "id"[, $iIndex = 0]])
  3001. ; Parameter(s): .: $sElement -
  3002. ; $sMode - Optional: (Default = "id") :
  3003. ; | ID
  3004. ; | Name + index
  3005. ; | Class + index
  3006. ; | Tag-name + index
  3007. ; $iIndex - Optional: (Default = 0) :
  3008. ; Return Value ..: Success - String (object to use in the _FFObj* functions)
  3009. ; Failure - Epmty string
  3010. ; @ERROR -
  3011. ; Author(s) .....: Thorsten Willert
  3012. ; Date ..........: Fri Oct 16 19:08:02 CEST 2009
  3013. ; Link ..........:
  3014. ; Related .......: _FFObj, _FFObjNew, _FFObjDelete, _FFClick
  3015. ; Example .......: Yes
  3016. ; ==============================================================================
  3017. Func _FFObjGet($sElement, $sMode = "id", $iIndex = 0)
  3018. Local Const $sFuncName = "_FFObjGet"
  3019. Local $sRet
  3020. Switch StringLower($sMode)
  3021. Case "id"
  3022. $sRet = ".getElementById('" & $sElement & "')"
  3023. Case "name"
  3024. $sRet = ".getElementsByName('" & $sElement & "')[" & $iIndex & "]"
  3025. Case "class"
  3026. $sRet = ".getElementsByClassName('" & $sElement & "')[" & $iIndex & "]"
  3027. Case "tag"
  3028. $sRet = ".getElementsByTagName('" & $sElement & "')[" & $iIndex & "]"
  3029. Case Else
  3030. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(id|name|class|tag) $sMode: " & $sMode))
  3031. Return ""
  3032. EndSwitch
  3033. Local $RetVal = _FFCmd( "window.content.document" & $sRet & "?1:0;")
  3034. If Not @error And $RetVal = 1 Then
  3035. Return "OBJECT|" & $sRet
  3036. Else
  3037. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sElement not found: " & $sElement))
  3038. Return ""
  3039. EndIf
  3040. EndFunc ;==>_FFObjGet
  3041. ; #FUNCTION# ===================================================================
  3042. ; Name ..........: _FFObj
  3043. ; Description ...: Returns or sets an value of an attribute.
  3044. ; Beschreibung ..: Liefert oder setzt den Wert eines Attributes.
  3045. ; AutoIt Version : V3.3.0.0
  3046. ; Syntax ........: _FFObj($sObject[, $sAttrib = ""[, $vValue = ""]])
  3047. ; Parameter(s): .: $sObject - Object or element in FireFox
  3048. ; $sAttrib - Optional: (Default = "") :
  3049. ; $vValue - Optional: (Default = "") :
  3050. ; Return Value ..: Success -
  3051. ; Failure - ""
  3052. ; @ERROR -
  3053. ; Author(s) .....: Thorsten Willert
  3054. ; Date ..........: Fri Oct 16 19:07:54 CEST 2009
  3055. ; Link ..........:
  3056. ; Related .......: _FFObjGet, _FFObjNew, _FFObjDelete
  3057. ; Example .......: Yes
  3058. ; ==============================================================================
  3059. Func _FFObj($sObject, $sAttrib = "", $vValue = "")
  3060. Local Const $sFuncName = "_FFObj"
  3061. If StringLeft($sObject, 7) = "OBJECT|" Then $sObject = StringMid($sObject, 8)
  3062. If StringLeft($sObject, 1) = "." Then $sObject = "window.content.document" & $sObject
  3063. If Not (StringInStr($sObject, "window.content") Or StringInStr($sObject, "FFau3.")) Then $sObject = "FFau3." & $sObject
  3064. If $sAttrib <> "" Then
  3065. If Not StringInStr($sAttrib, "(") Then
  3066. _FFCmd($sObject & ".hasAttribute('" & $sAttrib & "')")
  3067. If @error And $vValue <> "" Then
  3068. ;SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "$sAttrib not found: " & $sAttrib))
  3069. _FFCmd($sObject & "setAttributeNode('" & $sAttrib & "')")
  3070. EndIf
  3071. EndIf
  3072. $sObject &= "." & $sAttrib
  3073. If IsInt($vValue) Then
  3074. $sObject &= "=" & $vValue
  3075. ElseIf IsBool($vValue) Then
  3076. $sObject &= "=" & __FFB2S($vValue)
  3077. ElseIf $vValue <> "" Then
  3078. $sObject &= "='" & $vValue & "'"
  3079. EndIf
  3080. EndIf
  3081. Local $RetVal = _FFCmd($sObject)
  3082. If Not @error And $RetVal <> "_FFCmd_Err" Then
  3083. Return $RetVal
  3084. Else
  3085. SetError(__FFError($sFuncName, $_FF_ERROR_NoMatch, "$sObject not found: " & $sObject))
  3086. Return ""
  3087. EndIf
  3088. EndFunc ;==>_FFObj
  3089. ; #FUNCTION# ===================================================================
  3090. ; Name ..........: _FFObjNew
  3091. ; Description ...: Creates a new object in FireFox.
  3092. ; Beschreibung ..: Erzeugt ein neues Object in FireFox.
  3093. ; AutoIt Version : V3.3.0.0
  3094. ; Syntax ........: _FFObjNew($sNewObject, $sObject)
  3095. ; Parameter(s): .: $sNewObject -
  3096. ; $sObject -
  3097. ; Return Value ..: Success - 1
  3098. ; Failure - 0
  3099. ; @ERROR -
  3100. ; Author(s) .....: Thorsten Willert
  3101. ; Date ..........: Tue Apr 07 15:14:59 CEST 2009
  3102. ; Link ..........:
  3103. ; Related .......: _FFObjGet, _FFObj, _FFObjDelete
  3104. ; Example .......: Yes
  3105. ; ==============================================================================
  3106. Func _FFObjNew($sNewObject, $sObject)
  3107. If StringRegExp($sNewObject, "[\W]+") Then Return 0
  3108. Local $RetVal = _FFCmd("try{FFau3." & $sNewObject & "=" & $sObject & "}catch(e){};FFau3." & $sNewObject & "?1:0;", 3000, False)
  3109. Return SetError(Number($RetVal), @extended, $RetVal)
  3110. EndFunc ;==>_FFObjNew
  3111. ; #FUNCTION# ===================================================================
  3112. ; Name ..........: _FFObjDelete
  3113. ; Description ...: Deletes an object in FireFox.
  3114. ; Beschreibung ..: Loescht ein Objekt in FireFox.
  3115. ; AutoIt Version : V3.3.0.0
  3116. ; Syntax ........: _FFObjDelete($sObject)
  3117. ; Parameter(s): .: $sObject -
  3118. ; Return Value ..: Success - 1
  3119. ; Failure - 0
  3120. ; @ERROR -
  3121. ; Author(s) .....: Thorsten Willert
  3122. ; Date ..........: Wed Apr 08 14:21:26 CEST 2009 @556 /Internet Time/
  3123. ; Link ..........:
  3124. ; Related .......: _FFObjGet, _FFObjNew, _FFObj
  3125. ; Example .......: Yes
  3126. ; ==============================================================================
  3127. Func _FFObjDelete($sObject)
  3128. Local $sFFau3 = "simulateevent getlinkinfo getlinks searchimagebysize searchlink searchtab closewin selectwin"
  3129. If StringInStr($sFFau3, StringLower($sObject)) Then Return 0
  3130. Return _FFCmd("delete FFau3." & $sObject & ";!FFau3." & $sObject & "?1:0;")
  3131. EndFunc ;==>_FFObjDelete
  3132. ; #FUNCTION# ===================================================================
  3133. ; Name ..........: _FFAu3Option
  3134. ; Description ...: Sets and get options for the FF.au3
  3135. ; Beschreibung ..: Abfrage und Setzen von Optionen für die FF.au3
  3136. ; AutoIt Version : V3.3.0.0
  3137. ; Syntax ........: _FFAu3Option($sOption[, $vValue = ""])
  3138. ; Parameter(s): .: $sOption - LoadWaitTimeOut
  3139. ; | SearchMode
  3140. ; | ComTrace
  3141. ; | ErrorMsgBox
  3142. ; $vValue - Optional: (Default = "") : if noe value is given, the current value is returned
  3143. ; | LoadWaitTimeOut (int / min. 1000)
  3144. ; | ComTrace (bool)
  3145. ; | ErrorMsgBox (bool)
  3146. ; Return Value ..: Success - 1 / current value
  3147. ; Failure - 0
  3148. ; @ERROR -
  3149. ; Author(s) .....: Thorsten Willert
  3150. ; Date ..........: Fri Nov 06 17:53:58 CET 2009
  3151. ; Link ..........:
  3152. ; Related .......:
  3153. ; Example .......: Yes
  3154. ; ==============================================================================
  3155. Func _FFAu3Option($sOption, $vValue="")
  3156. Local Const $sFuncName = "_FFOption"
  3157. Switch $sOption
  3158. Case "SearchMode"
  3159. If $vValue = "" Then Return $_FF_SEARCH_MODE
  3160. If Not IsInt($vValue) Then
  3161. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vValue: " & $vValue))
  3162. Return 0
  3163. EndIf
  3164. If $vValue > 1 Then $vValue = 0
  3165. $_FF_SEARCH_MODE = $vValue
  3166. Case "LoadWaitTimeOut"
  3167. If $vValue = "" Then Return $_FF_LOADWAIT_TIMEOUT
  3168. If Not IsInt($vValue) Then
  3169. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(int) $vValue: " & $vValue))
  3170. Return 0
  3171. EndIf
  3172. If $vValue < 1000 Then $vValue = 1000
  3173. $_FF_LOADWAIT_TIMEOUT = $vValue
  3174. Case "ComTrace"
  3175. If $vValue = "" Then Return $_FF_COM_TRACE
  3176. If Not IsBool($vValue) Then
  3177. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(bool) $vValue: " & $vValue))
  3178. Return 0
  3179. EndIf
  3180. $_FF_COM_TRACE = $vValue
  3181. Case "ErrorMsgBox"
  3182. If $vValue = "" Then Return $_FF_ERROR_MSGBOX
  3183. If Not IsBool($vValue) Then
  3184. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidDataType, "(bool) $vValue: " & $vValue))
  3185. Return 0
  3186. EndIf
  3187. $_FF_ERROR_MSGBOX = $vValue
  3188. Case Else
  3189. SetError(__FFError($sFuncName, $_FF_ERROR_InvalidValue, "(LoadWaitTimeOut|ComTrace|ErrorMsgBox) $sOption" & $sOption))
  3190. EndSwitch
  3191. Return 1
  3192. EndFunc
  3193. ;===============================================================================
  3194. ;
  3195. ; Internal Functions with names starting with two underscores will not be documented
  3196. ; as user functions
  3197. ;
  3198. ; #INTERNAL_USE_ONLY# ==========================================================
  3199. ; Name ..........: __FFRecv
  3200. ; Description ...:
  3201. ; AutoIt Version : V3.3.0.0
  3202. ; Syntax ........: __FFRecv([$iTimeOut = 10000])
  3203. ; Parameter(s): .: $iTimeOut - Optional: (Default = 10000) : TimeOut for __FFWaitForRepl
  3204. ; Return Value ..: Success - Return value from MozRepl
  3205. ; Failure - ""
  3206. ; @ERROR -
  3207. ; Author(s) .....: Thorsten Willert
  3208. ; Date ..........: Mon Mar 23 22:27:52 CET 2009 @936 /Internet Time/
  3209. ; ==============================================================================
  3210. Func __FFRecv($iTimeOut = 30000)
  3211. Local $sRet = __FFWaitForRepl($iTimeOut)
  3212. Local $iErr = @error
  3213. $sRet = StringStripWS($sRet, 3)
  3214. ; Removing leading and trailing "
  3215. If StringLeft($sRet, 1) = '"' Then $sRet = StringTrimLeft($sRet, 1)
  3216. If StringRight($sRet, 1) = '"' Then $sRet = StringTrimRight($sRet, 1)
  3217. ; String to bool
  3218. If $sRet = "true" Then
  3219. $sRet = 1
  3220. ElseIf $sRet = "false" Then
  3221. $sRet = 0
  3222. EndIf
  3223. If $_FF_COM_TRACE Then ConsoleWrite("__FFRecv: " & $sRet & @CRLF)
  3224. SetError($iErr)
  3225. Return $sRet
  3226. EndFunc ;==>__FFRecv
  3227. ; #INTERNAL_USE_ONLY# ==========================================================
  3228. ; Name ..........: __FFSend
  3229. ; Description ...:
  3230. ; AutoIt Version : V3.3.0.0
  3231. ; Syntax ........: __FFSend($sCommand)
  3232. ; Parameter(s): .: $sCommand - String to send
  3233. ; Return Value ..: Success - 1
  3234. ; Failure - 0
  3235. ; @ERROR -
  3236. ; Author(s) .....: Thorsten Willert
  3237. ; Date ..........: Mon Mar 23 22:26:09 CET 2009 @934 /Internet Time/
  3238. ; ==============================================================================
  3239. Func __FFSend($sCommand)
  3240. Local Const $sFuncName = "__FFSend"
  3241. If Not __FFIsSocket($_FF_GLOBAL_SOCKET) Then
  3242. SetError(__FFError($sFuncName, $_FF_ERROR_SocketError))
  3243. Return 0
  3244. EndIf
  3245. TCPSend($_FF_GLOBAL_SOCKET, $sCommand & @CRLF)
  3246. If Not @error Then
  3247. If $_FF_COM_TRACE Then ConsoleWrite("__FFSend: " & $sCommand & @CRLF)
  3248. Return 1
  3249. Else
  3250. SetError(__FFError($sFuncName, $_FF_ERROR_SendRecv, "TCPSend: " & $sCommand))
  3251. Return 0
  3252. EndIf
  3253. EndFunc ;==>__FFSend
  3254. ; #INTERNAL_USE_ONLY# ==========================================================
  3255. ; Name ..........: __FFChromeSelect
  3256. ; Description ...: Some shortcuts for chrome
  3257. ; AutoIt Version : V3.3.0.0
  3258. ; Syntax ........: __FFChromeSelect($sOpt)
  3259. ; Parameter(s): .: $sOpt - Shortcut
  3260. ; Return Value ..: Success - crome: + ....xul
  3261. ; Failure - crome: + $sOpt
  3262. ; @ERROR -
  3263. ; Author(s) .....: Thorsten Willert
  3264. ; Date ..........: Sat Feb 14 12:33:16 CET 2009 @523 /Internet Time/
  3265. ; ==============================================================================
  3266. Func __FFChromeSelect($sOpt)
  3267. Local $sXUL
  3268. Switch StringLower($sOpt)
  3269. Case "bookmarks"
  3270. $sXUL = "//browser/content/bookmarks/bookmarksPanel.xul"
  3271. Case "history"
  3272. $sXUL = "//browser/content/history/history-panel.xul"
  3273. Case "extensions"
  3274. $sXUL = "//mozapps/content/extensions/extensions.xul?type=extensions"
  3275. Case "advanced-scripts"
  3276. $sXUL = "//browser/content/preferences/advanced-scripts.xul"
  3277. Case "changeaction"
  3278. $sXUL = "//browser/content/preferences/changeaction.xul"
  3279. Case "prefs"
  3280. $sXUL = "//browser/content/preferences/preferences.xul"
  3281. Case "colors"
  3282. $sXUL = "//browser/content/preferences/colors.xul"
  3283. Case "connection"
  3284. $sXUL = "//browser/content/preferences/connection.xul"
  3285. Case "cookies"
  3286. $sXUL = "//browser/content/preferences/cookies.xul"
  3287. Case "downloads"
  3288. $sXUL = "//mozapps/content/downloads/downloads.xul"
  3289. Case "downloadactions"
  3290. $sXUL = "//browser/content/preferences/downloadactions.xul"
  3291. Case "fonts"
  3292. $sXUL = "//browser/content/preferences/fonts.xul"
  3293. Case "languages"
  3294. $sXUL = "//browser/content/preferences/languages.xul"
  3295. Case "permissions"
  3296. $sXUL = "//browser/content/preferences/permissions.xul"
  3297. Case "sanitize"
  3298. $sXUL = "//browser/content/preferences/sanitize.xul"
  3299. Case "fireftp"
  3300. $sXUL = "//fireftp/content/fireftp.xul"
  3301. Case Else
  3302. $sXUL = $sOpt
  3303. EndSwitch
  3304. Return "chrome:" & $sXUL
  3305. EndFunc ;==>__FFChromeSelect
  3306. ; #FUNCTION# ===================================================================
  3307. ; Name ..........: __FFFilterString
  3308. ; Description ...: Filter for strings
  3309. ; AutoIt Version : V3.3.0.0
  3310. ; Syntax ........: __FFFilterString(ByRef $sString[, $iMode = 1])
  3311. ; Parameter(s): .: $sString - String to filter
  3312. ; $iMode - Optional: (Default = 0) : removes nothing
  3313. ; - 0 = no filter
  3314. ; - 1 = removes non ascii characters
  3315. ; - 2 = removes all double whitespaces
  3316. ; - 4 = removes all double linefeeds
  3317. ; - 8 = removes all html-tags
  3318. ; - 16 = simple html-tag / entities convertor
  3319. ; Return Value ..: Success - Filterd String
  3320. ; Failure - Input String
  3321. ; Author(s) .....: Thorsten Willert
  3322. ; Date ..........: Wed Apr 08 20:58:17 CEST 2009 @832 /Internet Time/
  3323. ; ==============================================================================
  3324. Func __FFFilterString(ByRef $sString, $iMode = 0)
  3325. If $iMode = 0 Then Return $sString
  3326. ;16 simple HTML tag converter
  3327. If $iMode >= 16 And $iMode < 32 Then
  3328. Local $sRepl[2][6] = [["<br>", "&nbsp;", ">", "<", "&", """], _
  3329. [@CRLF, " ", ">", "<", "&", '"']]
  3330. $sString = StringRegExpReplace($sString, "<p.*>", @CRLF & @CRLF)
  3331. For $i = 0 To UBound($sRepl, 2) - 1
  3332. $sString = StringReplace($sString, $sRepl[0][$i], $sRepl[1][$i])
  3333. Next
  3334. $iMode -= 16
  3335. EndIf
  3336. ;8 Tag filter
  3337. If $iMode >= 8 And $iMode < 16 Then
  3338. $sString = StringRegExpReplace($sString, "<[^>]*>", "")
  3339. $iMode -= 8
  3340. EndIf
  3341. ; 4 remove all double cr, lf
  3342. If $iMode >= 4 And $iMode < 8 Then
  3343. $sString = StringRegExpReplace($sString, "([ \t]*[\n\r]+[ \t]*)", @CRLF)
  3344. $sString = StringRegExpReplace($sString, "[\n\r]+", @CRLF)
  3345. $iMode -= 4
  3346. EndIf
  3347. ; 2 remove all double withespaces
  3348. If $iMode = 2 Or $iMode = 3 Then
  3349. $sString = StringRegExpReplace($sString, "[[:blank:]]+", " ")
  3350. $sString = StringRegExpReplace($sString, "\n[[:blank:]]+", @CRLF)
  3351. $sString = StringRegExpReplace($sString, "[[:blank:]]+\n", "")
  3352. $iMode -= 2
  3353. EndIf
  3354. ; 1 remove all non ASCII
  3355. If $iMode = 1 Then
  3356. $sString = StringRegExpReplace($sString, "[^\x00-\x7F]", " ")
  3357. EndIf
  3358. Return $sString
  3359. EndFunc ;==>__FFFilterString
  3360. ; #INTERNAL_USE_ONLY# ==========================================================
  3361. ; Name ..........: __FFError
  3362. ; Description ...: Writes Error to the console and show message-boxes if the script is compiled
  3363. ; AutoIt Version : V3.3.0.0
  3364. ; Syntax ........: __FFError($sWhere, ByRef $i_FF_ERROR[, $sMessage = ""])
  3365. ; Parameter(s): .: $i_FF_ERROR - Error Const
  3366. ; $sMessage - Optional: (Default = "") : Additional Information
  3367. ; Return Value ..: Success - Error Const from $i_FF_ERROR
  3368. ; Author(s) .....: Thorsten Willert
  3369. ; Date ..........: Sat Jul 18 11:52:36 CEST 2009
  3370. ; ==============================================================================
  3371. Func __FFError($sWhere, Const ByRef $i_FF_ERROR, $sMessage = "")
  3372. Local $sOut, $sMsg
  3373. Sleep(200)
  3374. Switch $i_FF_ERROR
  3375. Case $_FF_ERROR_Success
  3376. Return $_FF_ERROR_Success
  3377. Case $_FF_ERROR_GeneralError
  3378. $sOut = "General Error"
  3379. Case $_FF_ERROR_SocketError
  3380. $sOut = "Socket Error"
  3381. Case $_FF_ERROR_InvalidDataType
  3382. $sOut = "Invalid data type"
  3383. Case $_FF_ERROR_InvalidValue
  3384. $sOut = "Invalid value"
  3385. Case $_FF_ERROR_Timeout
  3386. $sOut = "Timeout"
  3387. Case $_FF_ERROR_NoMatch
  3388. $sOut = "No match"
  3389. Case $_FF_ERROR_RetValue
  3390. $sOut = "Error return value"
  3391. Case $_FF_ERROR_SendRecv
  3392. $sOut = "Error TCPSend / TCPRecv"
  3393. Case $_FF_ERROR_ReplException
  3394. $sOut = "MozRepl Exception"
  3395. Case $_FF_ERROR_SendRecv
  3396. $sOut = "Error TCPSend / TCPRecv"
  3397. Case $_FF_ERROR_InvalidExpression
  3398. $sOut = "Invalid Expression"
  3399. EndSwitch
  3400. If $sMessage = "" Then
  3401. $sMsg = $sWhere & " ==> " & $sOut & @CRLF
  3402. ConsoleWriteError($sMsg)
  3403. If @Compiled Then
  3404. If $_FF_ERROR_MSGBOX And $i_FF_ERROR < 6 Then MsgBox(16, "FF.au3 Error:", $sMsg)
  3405. DllCall("kernel32.dll", "none", "OutputDebugString", "str", $sMsg)
  3406. EndIf
  3407. Else
  3408. $sMsg = $sWhere & " ==> " & $sOut & ": " & $sMessage & @CRLF
  3409. ConsoleWriteError($sMsg)
  3410. If @Compiled Then
  3411. If $_FF_ERROR_MSGBOX And $i_FF_ERROR < 6 Then MsgBox(16, "FF.au3 Error:", $sMsg)
  3412. DllCall("kernel32.dll", "none", "OutputDebugString", "str", $sMsg)
  3413. EndIf
  3414. EndIf
  3415. Return $i_FF_ERROR
  3416. EndFunc ;==>__FFError
  3417. ; #INTERNAL_USE_ONLY# ==========================================================
  3418. ; Name ..........: __FFIsIP
  3419. ; Description ...: IP4 check
  3420. ; AutoIt Version : V3.3.0.0
  3421. ; Syntax ........: __FFIsIP(ByRef $IP[, $bSubstring = False])
  3422. ; Parameter(s): .: $IP - IP4 Address
  3423. ; Return Value ..: Success - 1
  3424. ; Failure - 0
  3425. ; Author(s) .....: Thorsten Willert
  3426. ; Date ..........: Sun Feb 15 00:21:41 CET 2009
  3427. ; ==============================================================================
  3428. Func __FFIsIP(ByRef $IP, $bSubstring = False)
  3429. If $bSubstring Then
  3430. Return StringRegExp(StringStripWS($IP, 3), "(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])")
  3431. Else
  3432. Return StringRegExp(StringStripWS($IP, 3), "^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$")
  3433. EndIf
  3434. EndFunc ;==>__FFIsIP
  3435. ; #INTERNAL_USE_ONLY# ==========================================================
  3436. ; Name ..........: __FFIsPort
  3437. ; Description ...: Port check
  3438. ; AutoIt Version : V3.3.0.0
  3439. ; Syntax ........: __FFIsPort(ByRef $iPort)
  3440. ; Parameter(s): .: $iPort - Port number 1024-65535
  3441. ; Return Value ..: Success - 1
  3442. ; Failure - 0
  3443. ; Author(s) .....: Thorsten Willert
  3444. ; Date ..........: 28. August 2007
  3445. ; ==============================================================================
  3446. Func __FFIsPort(ByRef $iPort)
  3447. Return (IsInt($iPort) And $iPort >= 1024 And $iPort <= 65535)
  3448. EndFunc ;==>__FFIsPort
  3449. ; #INTERNAL_USE_ONLY# ==========================================================
  3450. ; Name ..........: __FFIsSocket
  3451. ; Description ...: Socket check
  3452. ; AutoIt Version : V3.3.0.0
  3453. ; Syntax ........: __FFIsSocket(ByRef $Socket)
  3454. ; Parameter(s): .: $Socket -
  3455. ; Return Value ..: Success - 1
  3456. ; Failure - 0
  3457. ; Author(s) .....: Thorsten Willert
  3458. ; Date ..........: Tue Apr 07 11:08:05 CEST 2009 @422 /Internet Time/
  3459. ; ==============================================================================
  3460. Func __FFIsSocket(ByRef $Socket)
  3461. Return ($Socket > 0 And IsInt($Socket))
  3462. EndFunc ;==>__FFIsSocket
  3463. ; #INTERNAL_USE_ONLY# ==========================================================
  3464. ; Name ..........: __FFIsURL
  3465. ; Description ...: URL check
  3466. ; AutoIt Version : V3.3.0.0
  3467. ; Syntax ........: __FFIsURL(ByRef $URL)
  3468. ; Parameter(s): .: $URL - http/https/ftp/about/chrome/file
  3469. ; Return Value ..: Success - 1
  3470. ; Failure - 0
  3471. ; Author(s) .....: Thorsten Willert
  3472. ; Date ..........: Tue Jul 07 11:32:45 CEST 2009
  3473. ; Link ..........: http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx
  3474. ; ==============================================================================
  3475. Func __FFIsURL(ByRef $URL)
  3476. Return (StringRegExp($URL, '^^((ht|f)tp(s?)\:\/\/|~/|/)([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?') Or _
  3477. StringRegExp($URL, '^^((ht|f)tp(s?)\:\/\/|~/|/)(\d{1,3}\.){3}\d{1,3}(:[\d]{1,5})?(/.*)?$') Or _
  3478. StringLeft($URL, 6) = "about:" Or _
  3479. StringLeft($URL, 7) = "chrome:" Or _
  3480. StringLeft($URL, 10) = "localhost:" Or _
  3481. StringLeft($URL, 8) = "file:///")
  3482. EndFunc ;==>__FFIsURL
  3483. Func __FFCheckURL(ByRef $URL)
  3484. If Not __FFIsURL($URL) Then
  3485. If Not StringRegExp($URL, '^((ht|f)tp(s?)\:\/\/|~/|/)') Then $URL = "http://" & $URL
  3486. EndIf
  3487. Return __FFIsURL($URL)
  3488. EndFunc ;==>__FFCheckURL
  3489. ; #INTERNAL_USE_ONLY# ==========================================================
  3490. ; Name ..........: __FFB2S
  3491. ; Description ...: Bool to string
  3492. ; AutoIt Version : V3.3.0.0
  3493. ; Syntax ........: __FFB2S($bBool)
  3494. ; Parameter(s): .: $bBool - true / false
  3495. ; Return Value ..: Success - String "true" or "false"
  3496. ; Failure - ""
  3497. ; Author(s) .....: Thorsten Willert
  3498. ; Date ..........: Sun Feb 15 00:26:46 CET 2009
  3499. ; ==============================================================================
  3500. Func __FFB2S($bBool)
  3501. If $bBool Then
  3502. Return "true"
  3503. Else
  3504. Return "false"
  3505. EndIf
  3506. EndFunc ;==>__FFB2S
  3507. ; #INTERNAL_USE_ONLY# ==========================================================
  3508. ; Name ..........: __FFValue2JavaScript
  3509. ; Description ...:
  3510. ; AutoIt Version : V3.3.0.0
  3511. ; Syntax ........: __FFValue2JavaScript(ByRef $sValue)
  3512. ; Parameter(s): .: $sValue -
  3513. ; Return Value ..: Success -
  3514. ; Failure -
  3515. ; Author(s) .....: Thorsten Willert
  3516. ; Date ..........: Mon Apr 13 15:42:21 CEST 2009
  3517. ; ==============================================================================
  3518. Func __FFValue2JavaScript(ByRef $sValue)
  3519. If $sValue = "" Then Return ""
  3520. Local $sTmp = "", $c
  3521. $sValue = StringRegExpReplace($sValue, "([\\""'])", "\\$1")
  3522. $sValue = StringReplace($sValue, @CRLF, "\n")
  3523. $sValue = StringReplace($sValue, @CR, "\r")
  3524. $sValue = StringReplace($sValue, @TAB, "\t")
  3525. If StringRegExp($sValue, "[^\x00-\x7F]", 0) Then
  3526. ;$sValue = BinaryToString(StringToBinary($sValue,1),4)
  3527. For $i = 0 To StringLen($sValue)
  3528. $c = StringMid($sValue, $i, 1)
  3529. If StringRegExp($c, "[^\x00-\x7F]", 0) Then $c = StringFormat("\\u%0000s", Hex(AscW($c), 4))
  3530. $sTmp &= $c
  3531. Next
  3532. $sValue = $sTmp
  3533. EndIf
  3534. Return $sValue
  3535. EndFunc ;==>__FFValue2JavaScript
  3536. ; #INTERNAL_USE_ONLY# ==========================================================
  3537. ; Name ..........: __FFSendJavaScripts
  3538. ; Description ...: JavaScript functions
  3539. ; AutoIt Version : V3.3.0.0
  3540. ; Syntax ........: __FFSendJavaScripts([$bRefresh = False[, $bTrace = False]])
  3541. ; Parameter(s): .: $bRefresh - Optional: (Default = false) : Send again to FF
  3542. ; Return Value ..: Success - 1
  3543. ; Failure - 0
  3544. ; Author(s) .....: Thorsten Willert
  3545. ; Date ..........: Wed Oct 28 15:33:16 CET 2009 @648 /Internet Time/
  3546. ; Link ..........: http://developer.mozilla.org/en/docs/DOM:event.initMouseEvent
  3547. ; ==============================================================================
  3548. Func __FFSendJavaScripts($bRefresh = true, $bTrace = False)
  3549. Local $bTrc = $_FF_COM_TRACE
  3550. $_FF_COM_TRACE = $bTrace
  3551. If _FFCmd("repl.search(/FFau3/i)", 3000) = "FFau3" And Not $bRefresh Then
  3552. $_FF_COM_TRACE = $bTrace
  3553. Return 1
  3554. EndIf
  3555. If $bRefresh Then _FFCmd('try{delete FFau3;}catch(e){e};')
  3556. ConsoleWrite("__FFSendJavaScripts: Sending functions to FireFox .")
  3557. Local $sJavaScript = 'FFau3=new Object();FFau3.tmp="";FFau3.obj=null;FFau3.WCD=window.content.top.document;'
  3558. _FFCmd($sJavaScript)
  3559. ConsoleWrite(".")
  3560. ; sEvent = MouseEvents | KeyboardEvent | Event
  3561. ; sType:
  3562. ; MouseEvents: click
  3563. ; KeyboardEvent: keyup | keydown | keypress
  3564. ; Event: change | select | focus | blur | resize
  3565. ; args: oObject, sEvent, sType[, Key[, X[ ,Y]]]
  3566. ; key = dec-ASCII-code
  3567. ; X = clientX
  3568. ; Y = clientY
  3569. $sJavaScript = 'FFau3.simulateEvent=function simulateEvent(oObject,sEvent,sType){'
  3570. $sJavaScript &= 'try{ var evt=document.createEvent(sEvent);'
  3571. $sJavaScript &= 'switch(sEvent){'
  3572. $sJavaScript &= ' case "MouseEvents":'
  3573. $sJavaScript &= ' evt.initMouseEvent(sType,true,true,window,0,0,0,simulateEvent.arguments[4],simulateEvent.arguments[5],false,false,false,false,0,null);break;'
  3574. $sJavaScript &= ' case "KeyboardEvent":'
  3575. $sJavaScript &= ' evt.initKeyEvent(sType,true,true,null,false,false,false,false,simulateEvent.arguments[3],0);break;'
  3576. $sJavaScript &= ' case "Event":'
  3577. $sJavaScript &= ' evt.initEvent(sType,true,true);break; }'
  3578. $sJavaScript &= 'oObject.dispatchEvent(evt);'
  3579. $sJavaScript &= 'return 1;'
  3580. $sJavaScript &= '}catch(e){return -3;}return 0;};'
  3581. _FFCmd($sJavaScript)
  3582. ConsoleWrite(".")
  3583. ; GetLinkInfo(): JavaScript to get all informations about a link
  3584. $sJavaScript = 'FFau3.GetLinkInfo = function GetLinkInfo(i,sLimiter)'
  3585. $sJavaScript &= '{ var info=""; with(FFau3.WCD) {'
  3586. $sJavaScript &= 'try {'
  3587. $sJavaScript &= 'info = links[i].href + sLimiter;'
  3588. $sJavaScript &= 'info += links[i].hash + sLimiter;'
  3589. $sJavaScript &= 'info += links[i].search + sLimiter;'
  3590. $sJavaScript &= 'info += links[i].name + sLimiter;'
  3591. $sJavaScript &= 'info += links[i].id + sLimiter;'
  3592. $sJavaScript &= 'info += links[i].text + sLimiter;'
  3593. $sJavaScript &= 'info += links[i].innerHTML + sLimiter;'
  3594. $sJavaScript &= 'info += (links[i].hasAttribute("target") ? links[i].target + sLimiter : sLimiter);'
  3595. $sJavaScript &= 'info += links[i].protocol + sLimiter;'
  3596. $sJavaScript &= 'info += links[i].port;'
  3597. $sJavaScript &= 'return info.replace(/[\s]+/g," ");'
  3598. $sJavaScript &= '}catch(e){return -3;}'
  3599. $sJavaScript &= '}};'
  3600. _FFCmd($sJavaScript)
  3601. ConsoleWrite(".")
  3602. ; GetLinks(): JavaScript to get an information of all links
  3603. $sJavaScript = 'FFau3.GetLinks = function GetLinks(sLimiter)'
  3604. $sJavaScript &= '{ var res=""; with(FFau3.WCD) {try{'
  3605. $sJavaScript &= 'for (var i=0;i<links.length;i++){res += this.GetLinkInfo(i,sLimiter) + "\n";}'
  3606. $sJavaScript &= 'return res; } catch(e) {return -3;}}};'
  3607. _FFCmd($sJavaScript)
  3608. ConsoleWrite(".")
  3609. ; SearchImageBySize(): JavaScript
  3610. $sJavaScript = 'FFau3.SearchImageBySize = function SearchImageBySize(iH, iW, sMode, iP){'
  3611. $sJavaScript &= 'var sRet=""; with(FFau3.WCD) {'
  3612. $sJavaScript &= 'for (var i=0;i<images.length;i++){'
  3613. $sJavaScript &= 'var iWidth=images[i].width;'
  3614. $sJavaScript &= 'var iHeight=images[i].height;'
  3615. $sJavaScript &= 'switch (sMode) {'
  3616. $sJavaScript &= 'case "eq": if ((iWidth<=iW+iW/100*iP && iHeight<=iH+iH/100*iP && iWidth>=iW-iW/100*iP && iHeight>=iH-iH/100*iP)) sRet += " " + i; break;'
  3617. $sJavaScript &= 'case "lt": if ((iWidth<=iW && iHeight<=iH) && (iWidth>=iW-iW/100*iP && iHeight>=iH-iH/100*iP)) sRet += " " + i; break;'
  3618. $sJavaScript &= 'case "gt": if ((iWidth>=iW && iHeight>=iH) && (iWidth<=iW+iW/100*iP && iHeight<=iH+iH/100*iP)) sRet += " " + i; break;'
  3619. $sJavaScript &= 'default: return -1}'
  3620. $sJavaScript &= '} return sRet; } };'
  3621. _FFCmd($sJavaScript)
  3622. ConsoleWrite(".")
  3623. $sJavaScript = "FFau3.findPos = function findPos(obj){try{"
  3624. $sJavaScript &= "var curleft=curtop=0;"
  3625. $sJavaScript &= "if (obj.offsetParent) {"
  3626. $sJavaScript &= "do {curleft+=obj.offsetLeft;"
  3627. $sJavaScript &= " curtop+=obj.offsetTop;"
  3628. $sJavaScript &= "} while (obj=obj.offsetParent);"
  3629. $sJavaScript &= "return curleft+' '+curtop;"
  3630. $sJavaScript &= "}}catch(e){return -3}}"
  3631. _FFCmd($sJavaScript)
  3632. ConsoleWrite(".")
  3633. ; SearchTab(); JavaScript to search a tab by label
  3634. $sJavaScript = 'FFau3.SearchTab = function SearchTab(RegEx)'
  3635. $sJavaScript &= '{try{'
  3636. $sJavaScript &= 'for (var i=0;i<gBrowser.mTabs.length;i++){'
  3637. $sJavaScript &= 'if (RegExp(RegEx).test(gBrowser.mTabs[i].label)) return i;};'
  3638. $sJavaScript &= 'return -1;}catch(e){return -3;}};'
  3639. _FFCmd($sJavaScript)
  3640. ConsoleWrite(".")
  3641. ; CloseWin()
  3642. $sJavaScript = 'FFau3.CloseWin = function CloseWin(sSearch,sMode){'
  3643. $sJavaScript &= 'var win;var enum = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getEnumerator("navigator:browser");'
  3644. $sJavaScript &= 'while(enum.hasMoreElements() ){'
  3645. $sJavaScript &= 'win=enum.getNext();'
  3646. $sJavaScript &= 'switch(sMode){'
  3647. $sJavaScript &= 'case "title": if (win.title.indexOf(sSearch) != -1){win.close();return 1;};break;'
  3648. $sJavaScript &= 'case "label": if (FFau3.SearchTab(sSearch)>-1){win.close();return 1;};break;'
  3649. $sJavaScript &= 'case "href": if (win.content.document.location.href.indexOf(sSearch) != -1){win.close();return 1;}break;'
  3650. $sJavaScript &= 'default: return -1;'
  3651. $sJavaScript &= '}}return -1;};'
  3652. _FFCmd($sJavaScript)
  3653. ConsoleWrite(".")
  3654. ; SelectWin()
  3655. $sJavaScript = 'FFau3.SelectWin = function SelectWin(sSearch,sMode,sType){'
  3656. $sJavaScript &= 'var win;var enum = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getEnumerator(sType);'
  3657. $sJavaScript &= 'while(enum.hasMoreElements() ){'
  3658. $sJavaScript &= 'win=enum.getNext();'
  3659. $sJavaScript &= 'switch(sMode){'
  3660. $sJavaScript &= 'case "title": if (win.title.indexOf(sSearch) != -1){repl.enter(win);return 1;};break;'
  3661. $sJavaScript &= 'case "label": if (FFau3.SearchTab(sSearch)>-1){repl.enter(win);return 1;};break;'
  3662. $sJavaScript &= 'case "href": if (win.content.document.location.href.indexOf(sSearch) != -1){repl.enter(win);return 1;};break;'
  3663. $sJavaScript &= 'default: return -1};'
  3664. $sJavaScript &= '}return -1;};'
  3665. _FFCmd($sJavaScript)
  3666. ConsoleWrite(". done" & @CRLF)
  3667. $_FF_COM_TRACE = $bTrc
  3668. ;
  3669. Return 1
  3670. EndFunc ;==>__FFSendJavaScripts
  3671. ; #INTERNAL_USE_ONLY# ==========================================================
  3672. ; Name ..........: __FFWaitForRepl
  3673. ; Description ...:
  3674. ; AutoIt Version : V3.3.0.0
  3675. ; Syntax ........: __FFWaitForRepl($iTimeOut)
  3676. ; Parameter(s): .: $iTimeOut
  3677. ; Return Value ..: Success - Return value from MozRepl
  3678. ; Failure - ""
  3679. ; @ERROR -
  3680. ; Author(s) .....: Thorsten Willert
  3681. ; Date ..........: Mon Mar 23 22:19:52 CET 2009 @930 /Internet Time/
  3682. ; ==============================================================================
  3683. Func __FFWaitForRepl($iTimeOut)
  3684. Local Const $sFuncName = "__FFWaitForRepl"
  3685. Local $recv, $sRet = "", $TimeOutTimer = TimerInit()
  3686. If $iTimeOut < 200 Then $iTimeOut = 200
  3687. While TimerDiff($TimeOutTimer) < $iTimeOut
  3688. ; connection delay
  3689. Sleep($_FF_CON_DELAY)
  3690. $recv = TCPRecv($_FF_GLOBAL_SOCKET, 4096)
  3691. ;ConsoleWrite($recv & @CRLF)
  3692. ; TCP error
  3693. If @error Then
  3694. SetError(__FFError($sFuncName, $_FF_ERROR_SendRecv, "TCPRecv :" & @error))
  3695. Return ""
  3696. EndIf
  3697. $sRet &= $recv
  3698. ; error from MozRepl
  3699. If StringRegExp($recv, "!!!(.*?)(TypeError|Exception|ReferenceError):?") Then
  3700. $recv = StringLeft($recv, StringInStr($recv, "location") - 1)
  3701. SetError(__FFError($sFuncName, $_FF_ERROR_ReplException, StringStripWS($recv, 3)))
  3702. Return ""
  3703. ElseIf StringInStr($recv, "....>") Then
  3704. __FFSend(";") ; MozRepl-Reset
  3705. Sleep(100)
  3706. SetError(__FFError($sFuncName, $_FF_ERROR_RetValue, "MozRepl ....>"))
  3707. Return ""
  3708. ElseIf StringInStr($recv, "beginning of the line to force evaluation") Then
  3709. Sleep(500) ; first connection delay
  3710. EndIf
  3711. ; multiple connections to MozRepl (e.g repl2?> ...)
  3712. If StringRegExp($recv, "repl[\d]?>") Then Return StringRegExpReplace($sRet, "repl[\d]?>", "")
  3713. WEnd
  3714. ; Timeout
  3715. SetError(__FFError($sFuncName, $_FF_ERROR_Timeout, Round(TimerDiff($TimeOutTimer)) & "ms > " & $iTimeOut & "ms $iTimeOut"))
  3716. Return ""
  3717. EndFunc ;==>__FFWaitForRepl
  3718. ; #INTERNAL_USE_ONLY# ==========================================================
  3719. ; Name ..........: __FFStartProcess
  3720. ; Description ...: Starts the firefox.exe
  3721. ; AutoIt Version : V3.3.0.0
  3722. ; Syntax ........: __FFStartProcess([$sURL = "about:blank"[, $bNewWin = False[, $sProfile = "default"[, $bNoRemote = False[, $bHide = False[, $iPort = 4242[, $iTimeOut = 30000]]]]]]])
  3723. ; Parameter(s): .: $sProfile - Optional: (Default = "default") :
  3724. ; $bNewWin - Optional: (Default = false) :
  3725. ; $bNoRemote - Optional: (Default = false) :
  3726. ; $bHide - Optional: (Default = False) :
  3727. ; $iPort - Optional: (Default = 4242) :
  3728. ; $iTimeOut - Optional: (Default = 30000) : min. 2000ms
  3729. ; Return Value ..: Success - 1
  3730. ; Failure - 0
  3731. ; @ERROR -
  3732. ; @EXTENDED - PID from the firefox.exe
  3733. ; Author(s) .....: Thorsten Willert
  3734. ; Date ..........: Wed Nov 04 16:01:59 CET 2009
  3735. ; ==============================================================================
  3736. Func __FFStartProcess($sURL = "about:blank", $bNewWin = False, $sProfile = "default", $bNoRemote = False, $bHide = False, $iPort = 4242, $iTimeOut = 30000)
  3737. Local Const $sFuncName = "__FFStartProcess"
  3738. Local $PID = -1
  3739. Local $sNoRemote = "", $sNewWin
  3740. Local $sProcName = $_FF_PROC_NAME
  3741. If $sProfile = "default" Then
  3742. $sProfile = ''
  3743. Else
  3744. $sProfile = ' -P "' & $sProfile & '"'
  3745. EndIf
  3746. If $bNoRemote Then $sNoRemote = "-no-remote"
  3747. If $bNewWin Then $sNewWin = "-new-window"
  3748. $sURL = '"' & $sURL & '"'
  3749. If $iTimeOut < 2000 Then $iTimeOut = 2000
  3750. Local $sHKLM = "HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox"
  3751. Local $sFFExe = RegRead($sHKLM & "\" & RegRead($sHKLM, "CurrentVersion") & "\Main", "PathToExe")
  3752. If @error Then
  3753. SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "Error reading registry entry for FireFox." & @crlf & _
  3754. "HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\*CurrentVersion*\Main\PathToExe" & @crlf & _
  3755. "Error from RegRead: " & @error))
  3756. Return 0
  3757. EndIf
  3758. Local $sCommand = StringFormat('"%s" %s %s %s -repl %i %s', $sFFExe, $sNewWin, $sURL, $sNoRemote, $iPort, $sProfile)
  3759. $PID = Run($sCommand)
  3760. If $bHide Then BlockInput(1)
  3761. Local $iTimeOutTimer = TimerInit()
  3762. While 1
  3763. Sleep(2000)
  3764. If ProcessExists($sProcName) Then ExitLoop
  3765. If (TimerDiff($iTimeOutTimer) > $iTimeOut) Then
  3766. SetError(__FFError($sFuncName, $_FF_ERROR_Timeout, "Browser process not exists: " & $sProcName))
  3767. BlockInput(0)
  3768. Return 0
  3769. EndIf
  3770. WEnd
  3771. If $bHide Then
  3772. Local $WINTITLE_MATCH_MODE = AutoItSetOption("WinTitleMatchMode", 4)
  3773. WinWaitActive("[CLASS:MozillaUIWindowClass]")
  3774. Sleep(500)
  3775. WinSetState("[CLASS:MozillaUIWindowClass]", "", @SW_MINIMIZE)
  3776. BlockInput(0)
  3777. AutoItSetOption("WinTitleMatchMode", $WINTITLE_MATCH_MODE)
  3778. Else
  3779. Sleep(1000)
  3780. EndIf
  3781. If $_FF_COM_TRACE Then ConsoleWrite('__FFStartProcess: "' & $sCommand & @CRLF)
  3782. SetExtended($PID)
  3783. Return 1
  3784. EndFunc ;==>__FFStartProcess

comments powered by Disqus