#include #include #include #include AutoItSetOption("MustDeclareVars", 1) _IEErrorHandlerRegister() Global $oIE, $GUIActiveX, $GUI_Button_Host, $GUI_Button_Home, $GUI_Button_Start, $GUI_Status Global $urlHost, $urlHome, $urlStart, $urlFirst, $urlLast, $waitTime Global $winWidth, $winHeight $urlHost = "http://www.insanejournal.com/" $urlHome = "http://asylums.insanejournal.com/scans_daily/" $urlFirst = "http://asylums.insanejournal.com/scans_daily/298.html" $urlLast = $urlHome & _sdLastFile() $waitTime = 5000 $winWidth = 800 $winHeight = 600 $oIE = _IECreateEmbedded() GUICreate("Embedded Web control Test", $winWidth, $winHeight, _ (@DesktopWidth - $winWidth) / 2, (@DesktopHeight - $winHeight) / 2, _ BitOr($WS_OVERLAPPEDWINDOW, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $winWidth - 100, $winHeight) $GUI_Button_Host = GUICtrlCreateButton("Host Login", 705, 5, 90, 30) $GUI_Button_Home = GUICtrlCreateButton("Go Home", 705, 40, 90, 30) $GUI_Button_Start = GUICtrlCreateButton("Start", 705, 75, 90, 30) $GUI_Status = GUICtrlCreateLabel("", 705, 110, 90, 15) GUISetState() _sdSetStatus("Ready...", 0x00aa00) _IENavigate($oIE, $urlHome) # Waiting for user to close the window While 1 Local $msg $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE _sdSetStatus("Goodbye", 0xff0000) ExitLoop Case $msg = $GUI_Button_Host _sdSetStatus("Login now", 0x00aa00) _IENavigate ($oIE, $urlHost) _IELoadWait($oIE) Case $msg = $GUI_Button_Home _sdSetStatus("Loading home", 0x00aa00) _IENavigate ($oIE, $urlHome) _IELoadWait($oIE) Case $msg = $GUI_Button_Start _sdSetStatus("Backing up...", 0xff0000) Local $oLinks, $oLink, $theLink $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks If $oLink.innerText == "Link" Then $theLink = $oLink.href ExitLoop EndIf Next _sdGoBack($theLink) _sdSetStatus("Backup complete", 0x00aa00) EndSelect WEnd GUIDelete() Exit # Loads a page in the browser, calls the save function, and goes to the next Func _sdGoBack($url) Local $oLinks, $oLink, $theLink, $oDoc, $lCount, $yesno _IENavigate($oIE, $url) _IELoadWait($oIE) $yesno = 1 $oLinks = _IELinkGetCollection($oIE) $lCount = @extended $oDoc = _IEDocGetObj($oIE) For $oLink In $oLinks If StringRight($oLink.href, 4) == "prev" Then _sdSaveHtml($oDoc.URL, _IEDocReadHTML($oIE)) $theLink = $oLink.href ExitLoop EndIf Next Sleep(5000) If StringLen($theLink) == 0 Then $yesno = 0 If $urlFirst == $oDoc.URL Then $yesno = 0 If $urlLast == $oDoc.URL Then $yesno = 0 If $lCount == 0 Then $yesno = 0 If $yesno == 1 Then _sdGoBack($theLink) EndIf EndFunc # Saves the the HTML in the document to a similarly named HTML file Func _sdSaveHtml($url, $html) Local $filename, $fh $filename = StringReplace($url, $urlHome, "") $fh = FileOpen($filename, 129) FileWrite($fh, $html) FileClose($fh) EndFunc # Finds the newest SD post in the directory to know where to stop backing up Func _sdLastFile() Local $search, $fn, $fArray[1000] Local $fCount = 0, $rSize = 1000 $search = FileFindFirstFile("*.html") # Check if the search was successful If $search <> -1 Then While 1 Dim $file, $temp $file = FileFindNextFile($search) If @error Then ExitLoop $fCount = $fCount + 1 If $fCount == $rSize Then $rSize = $rSize + 1000 ReDim $fArray[$rSize] EndIf $temp = $file $fArray[$fCount] = StringReplace($temp, ".html", "") WEnd ReDim $fArray[$fCount] $fn = _ArrayMax($fArray, 1) EndIf FileClose($search) return $fn & ".html" EndFunc # Updates the status box Func _sdSetStatus($words, $color) GUICtrlSetColor($GUI_Status, $color) GUICtrlSetData($GUI_Status, $words) EndFunc