Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Simply install Autohotkey (https://autohotkey.com/download/), save this file as whatever.ahk, and double click.
- ; A macro for when there are no download links available; takes care of opening images in new tabs and downloading them.
- ; V2.6 Changelog: Previous version still has problems with multiple "save as" dialogues. Because of this, keyboard shortcut method has been reverted to clicking for easier compatibility. New method for detecting successful dialogue implemented (color check of context menu). Delays set manually. [.65: adjusted timing issues that would begin save dialogue before next page could load]
- ; README
- ; A hacky AutoHotKey macro by meterion for idle downloading
- ; To use: Navigate to page 1 of desired gallery. Press Ctrl+q.
- ; Follow the prompt, leave computer alone as it does its thing (currently cannot function in background).
- ; Speed: ~1.5 minutes per 50 pages
- ; Press Ctrl+i for extra beeps lol (don't do this while it's running tho)
- ; NOTE: Makes an .ini file in the same directory it's used called "autosaversettings.ini"
- numPages = 0 ; Number of pages set to download: 0 by default
- CoordMode, Mouse, Relative
- SetMouseDelay, 1
- setFormat, IntegerFast, d
- SetTitleMatchMode, 1
- ^q::
- Gui, Name: New, , Online Reader Autodownloader by meterion
- GUI, Add, Button, x10 w380 h20 gstartButton, Select a folder in which to download images
- IniRead, folderStart, autosaversettings.ini, User Settings, iniStart, %A_Space% ; Reads ini file for previously set download location
- if(folderStart)
- {
- GUI, Add, Text, x10 r2 w400 vupdateStart, Images will be downloaded to: `n%folderStart%
- }
- else
- {
- GUI, Add, Text, x10 r2 w400 vupdateStart, There is no download folder selected
- }
- Gui, Add, Checkbox, vrenamePages, Check to numerically rename files starting at 001
- Gui, Add, Edit, x10 w50 vnumPages gPageButton Number ; Set number of pages to download here
- Gui, Add, UpDown, gpagebutton, %numPages%
- Gui, Add, Text, x+m yp+3 w300 vpageText, %numPages% pages to download
- GUI, Add, Button, x10 w380 h40 Default gdownloadButton, Begin Downloading
- GUI, Add, Button, x10 y+20 w380 h20 gfavoriteButton, Select a default folder from which to browse download folder
- IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
- if(folderFavorite) ; Same as above for a set default location
- {
- GUI, Add, Text, x10 r2 w400 vupdateFavorite, Current default folder is: `n%folderFavorite%
- }
- else
- {
- GUI, Add, Text, x10 r2 w400 vupdateFavorite, There is no current default folder selected
- }
- GUI, Add, Text, w400 y+10 Center, NOTE: make sure you are on page 1 of desired gallery before starting.
- Gui, Show, W400 H250 Center, Online Reader Autodownloader by meterion
- return
- startButton: ; Brings up folder select, saves download folder path to ini file, updates GUI
- IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
- FileSelectFolder, toIniStart, *%folderFavorite%, 3, Choose where to save images
- IniWrite, %toIniStart%, autosaversettings.ini, User Settings, iniStart
- folderStart := toIniStart
- GuiControl, , updateStart, Images will be downloaded to: `n%folderStart%
- return
- pageButton: ; Need to submit value from GUI because the variable isn't being created here
- Gui, Submit, noHide
- GuiControl, , pageText, %numPages% pages to download
- return
- favoriteButton: ; As above for the default folder path
- FileSelectFolder, toIniFavorite, *%folderFavorite%, 3, Choose a Preferred Default Folder
- IniWrite, %toIniFavorite%, autosaversettings.ini, User Settings, iniFavorite
- folderFavorite := toIniFavorite
- Guicontrol, , updateFavorite, Current default folder is: `n%folderFavorite%
- return
- downloadButton: ; Where the magic happens
- Gui, Submit
- Gui, Destroy ; Ensures proper window is active
- WinGetActiveStats, Title, Width, Height, X, Y
- winXClick := Width/2 ; X/Y coords for where image probably is (top 1/3 of screen in the middle). If you have a lot of toolbars this probably has to be adjusted.
- winYClick := Height/3
- winXSClick := winXClick + 50 ; X/Y coords for where relative "Save Image As..." right-click dialogue is on Chrome. Probably has to be adjusted for other browsers/extensions installed.
- winYSClick := winYClick + 175
- loopNumber := numPages - 1 ; Since first page is downloaded out of loop, loopNumber is 1 less than page number
- numRename :=0 ; If rename option is selected, this will be used later. If it was used before, it will be reset to 0 now.
- Sleep, 1000 ; allow for user to lift hand from keyboard/mouse
- pageSaveCheck()
- Send, {F4} ; This brings you to the filepath edit box in chrome. Might need to be adjusted for other browsers.
- Send, ^a
- SendRaw, %folderStart% ; Enters directory from initial GUI
- loop, 4
- {
- Send, {Enter} ; It takes many enters to go from filepath edit to confirming image save. Might need to be adjusted for other browsers. Can cause issues without the delay.
- sleep, 200
- }
- Sleep, 200
- Loop, %loopNumber% ; Now loops the rest of the pages
- {
- Click, %winXClick%, %winYClick% ; Advance page
- Sleep, 500
- pageSaveCheck()
- Send, {Enter} ; Save Image
- Sleep, 300 ; Needs some buffer time for the dialogue to exit before starting loop
- }
- playTune()
- MsgBox, 0, Autosave Completed, %numPages% pages downloaded.
- return
- pageSaveCheck() ; Does save image dialogue and any renaming
- {
- global ; setting scope to access/write global variables
- Loop ; infinfite loop until broken
- {
- Click, %winXClick%, %winYClick%, right ; Opening first page
- Sleep, 50
- PixelGetColor, controlA, winXClick +40, winYClick +80 ; Gets pixel color sample of context menu
- PixelGetColor, controlB, winXClick +80, winYClick +40
- Click, %winXSClick%, %winYSClick% ; Save Image As
- Sleep, 50
- PixelGetColor, matchA, winXClick +40, winYClick +80 ; Gets pixel color sample of context menu (if fail) or base page (if success)
- PixelGetColor, matchB, winXClick +80, winYClick +40
- If (controlA != matchA OR controlB != matchB) ; If either sample changes (context menu exits on success) then wait for dialogue
- break
- Sleep, 150 ; Checks 4x per second
- }
- WinWaitActive, Save As ; Wait for Save window to open
- if renamePages = 1
- {
- numRename := ++numRename
- numSend := SubStr("00" . numRename, -2)
- Send, %numSend%
- Sleep, 200
- }
- }
- playTune()
- {
- tones := [131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976]
- Random, toneStart, 1, 40 ; This part just plays a short chord and loads a dialogue box to show completion
- Random, jumpOne, 3, 4
- Random, jumpTwo, 3, 4
- SoundBeep, tones[ToneStart], 150
- SoundBeep, tones[ToneStart + jumpOne], 150
- SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
- }
- ^i:: ; If you just want to play tones
- playTune()
- return
Add Comment
Please, Sign In to add comment