tmetcalfe89

Chrome Bookmark expansion script (rv3)

Feb 12th, 2016
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.28 KB | None | 0 0
  1. ;On a 1 second poll
  2. ; If Chrome window is active
  3. ;  Get mouse position
  4. ;  Get Chrome header area bounds
  5. ;  If mouse position is in the Chrome header area bounds and bookmarks are expanded or mouse position is not in the Chrome header area bounds and bookmarks aren't expanded
  6. ;   Send Chrome bookmark toggle combo
  7. ;  End If
  8. ; End If
  9. ;Loop
  10.  
  11. #include <MsgBoxConstants.au3>
  12. #include "AssocArrays.au3"
  13.  
  14. Global $avTopBarHeight
  15. AssocArrayCreate($avTopBarHeight, 5)
  16. While 1
  17.     $hWnd = WinActive("[CLASS:Chrome_WidgetWin_1]")
  18.     $aControlPos = ControlGetPos($hWnd, "", "Chrome_RenderWidgetHostHWND1")
  19.     If $hWnd And Not @error Then
  20.         Local $aMousePos = MouseGetPos()
  21.  
  22.         Local $aBoundPos[4]
  23.         $aBoundPos[0] = WinGetPos($hWnd)[1]
  24.         $aBoundPos[1] = $aBoundPos[0] + (WinGetPos($hWnd)[3] - ControlGetPos($hWnd, "", "Chrome_RenderWidgetHostHWND1")[3])
  25.         $aBoundPos[2] = WinGetPos($hWnd)[0]
  26.         $aBoundPos[3] = $aBoundPos[2] + WinGetPos($hWnd)[2]
  27.  
  28.         If (Not AssocArrayExists($avTopBarHeight, "" & $hWnd & "." & BitAND(WinGetState($hWnd), 32))) Then
  29.             AssocArrayAssign($avTopBarHeight, "" & $hWnd & "." & BitAND(WinGetState($hWnd), 32), $aBoundPos[1] - $aBoundPos[0]) ;Assumes bookmarks are currently not expanded
  30.         EndIf
  31.  
  32.         If (IsInside($aMousePos, $aBoundPos) And Not IsOpen($aBoundPos, $hWnd)) Then
  33.             Sleep(100)
  34.             Send("^+b")
  35.             Sleep(50)
  36.         EndIf
  37.  
  38.         If (Not IsInside($aMousePos, $aBoundPos) And IsOpen($aBoundPos, $hWnd)) Then
  39.             Sleep(100)
  40.             Send("^+b")
  41.             Sleep(50)
  42.         EndIf
  43.     EndIf
  44.  
  45.     sleep(100)
  46.  WEnd
  47.  
  48. Func IsOpen(ByRef $vBoundPos, ByRef $hWnd)
  49.     Local $iMinTopBarHeight = AssocArrayGet($avTopBarHeight, "" & $hWnd & "." & BitAND(WinGetState($hWnd), 32))
  50.     Local $iCurrentTopBarHeight = $vBoundPos[1] - $vBoundPos[0]
  51.  
  52.     If ($iMinTopBarHeight > $iCurrentTopBarHeight And $iCurrentTopBarHeight > 0) Then
  53.         AssocArrayAssign($avTopBarHeight, "" & $hWnd & "." & BitAND(WinGetState($hWnd), 32), $iCurrentTopBarHeight)
  54.         Return 0
  55.     EndIf
  56.  
  57.     If ($iMinTopBarHeight = $iCurrentTopBarHeight) Then
  58.         Return 0
  59.     EndIf
  60.  
  61.     If ($iMinTopBarHeight < $iCurrentTopBarHeight) Then
  62.         Return 1
  63.     EndIf
  64. EndFunc
  65.  
  66. Func IsInside(ByRef $vMousePos, ByRef $vBoundPos)
  67.     Return ($vMousePos[0] < $vBoundPos[3] And $vMousePos[0] > $vBoundPos[2] And $vMousePos[1] < $vBoundPos[1] And $vMousePos[1] > $vBoundPos[0])
  68. EndFunc
Advertisement