diff --git a/Freedomain-Posters-Shared-Functions.ahk b/Freedomain-Posters-Shared-Functions.ahk index 03c6fd8..7deff04 100644 --- a/Freedomain-Posters-Shared-Functions.ahk +++ b/Freedomain-Posters-Shared-Functions.ahk @@ -41,10 +41,10 @@ CheckForUpdates(GitReleasesAPIURL){ if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){ - ToolTip - return 0 - } - else, { + ToolTip + return 0 + } + else, { UpdateAvailable := 1 ; msgbox, update found! Message = Program Update Found @@ -153,11 +153,11 @@ TakeScreenshotOfPage(SaveFilepath := ""){ ; sleep, 5000 if(SaveFilepath = ""){ - SaveFilepath := ErrorLoggingDirectory - } + SaveFilepath := ErrorLoggingDirectory + } - ; if(!FileExist(SaveFilepath)) - FileCreateDir, %SaveFilepath% + ; if(!FileExist(SaveFilepath)) + FileCreateDir, %SaveFilepath% /* if(!TakeScreenshotsOfErrors) Return @@ -217,13 +217,13 @@ TimedToolTip(Text, x="", y="",RemoveAfterTime:=2000, SetWhichToolTip="") { Func_LogErrorsToTextFile(Text){ ; ErrorLoggingFile := Filepath FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss -text = -( + text = + ( ----------------%TodayDate%--------------- -%Text% + ---------------%TodayDate%--------------- + %Text% -) + ) FileAppend, %Text%, %ErrorLoggingFilePath% } ; -------------------------------/LogErrorsToTextFile------------------------------- @@ -730,26 +730,6 @@ CheckIfUpdateAvailable(Filepath, CurrentVersion){ -FindUpdateChangeLog(Filepath){ - FileRead, ScriptUpdateContents, %Filepath% - - ; Set Variables - ChangelogStart =;---Changelog------------------------------------------------------ - ChangelogEnd =;---/Changelog------------------------------------------------------ - - ; Msgbox % "ScriptUpdateContents: " ScriptUpdateContents - ChangeLog := StrSplit(ScriptUpdateContents, ChangelogStart) - ChangeLog := ChangeLog[2] - ChangeLog := StrSplit(ChangeLog, ChangelogEnd) - ChangeLog := ChangeLog[1] - Return Changelog -} - - - - - - CheckSeleniumDriver(){ try Driver := SChrome_Get("", ChromeProfile := "") ; open new tab page with with specified profile catch e { @@ -790,6 +770,9 @@ SeleniumConnectToActiveTab(IP_Port := "127.0.0.1:9222"){ return Driver } +/* +*/ + CreateArrayOfChromeTabs() { Message = Creating an Array of All Chrome Tabs SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") @@ -895,10 +878,12 @@ CreateArrayOfChromeTabs() { return - } - InputFilePathIntoOpenWindow(Filepath){ +/* +*/ + +InputFilePathIntoOpenWindow(Filepath){ ; Msgbox % "Filepath: " Filepath Message = Waiting for "Open" window to appear to input filepath into SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") @@ -969,27 +954,31 @@ ActivateChromeTab(URL){ ; NumberOfTabLoops := Driver.Windows.Count + 2 loop % NumberOfTabActivationLoops { ; loop through tabs to find matching tab - try driver.SwitchToNextWindow() - ; sleep, 1000 - ; msgbox, looping through tabs - try CurrentTabTitle := driver.window.title - try CurrentTabURL := driver.Url + Message = Looping through tabs to activate with: %URLBase% + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - if(InStr(CurrentTabURL, URLBase)){ + try driver.SwitchToNextWindow() - ; Message = Found Tab:.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase% - ; DevModeMsgBox(message) + ; sleep, 1000 + ; msgbox, looping through tabs + try CurrentTabTitle := driver.window.title + try CurrentTabURL := driver.Url - TabFoundSuccessfully := 1 - ; msgbox %CurrentTabTitle% = %PageTitle% - ; msgbox %CurrentTabURL% = %URL% - return - } + if(InStr(CurrentTabURL, URLBase)){ - ; / loop through tabs -} -return "Failed" + ; Message = Found Tab:.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase% + ; DevModeMsgBox(message) + + TabFoundSuccessfully := 1 + ; msgbox %CurrentTabTitle% = %PageTitle% + ; msgbox %CurrentTabURL% = %URL% + return + } + + ; / loop through tabs + } + return "Failed" } /*ActivateChromeTab(URL){ @@ -1014,8 +1003,12 @@ return "Failed" NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){ if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect Status := CheckSeleniumDriver() - if(Status) - Return "Failed" + if(Status){ + Message = Failed to Connect to Chrome. Please Check for any open dialog boxes or ChromeDriver being out of date. + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return "Failed" + } + ; CreateArrayOfChromeTabs() ; moved to the end of checkseleniumdriver() } @@ -1044,11 +1037,16 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){ if(!HasSubstringVal(ChromeTabsURLArray, URLBase)) { ; DevModeMsgBox("Creating new tab") + Message = Tab for %urlBase% does not exist. Creating new tab with URL: %URL% try, run "%ChromeFilepath%" "%URL%" ChromeTabsURLArray.Push(URL) ; Append the new url to the array NewTabCreated := 1 sleep, 1000 } + else, { + Message = %URLBase% is within ChromeTabsURLArray. Trying to Activate. + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + } ; message = NewTabCreated: %NewTabCreated% ; DevModeMsgBox(message) @@ -1059,6 +1057,25 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){ try currentURL := driver.url Message = Failed to switch active tab to %URLBase%. Current tab is: %currentURL% SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + + CheckForAlerts() + + ; create a new tab and try to switch to it again + Message = Creating new tab with URL: %URL% + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + + try, run "%ChromeFilepath%" "%URL%" + ChromeTabsURLArray.Push(URL) ; Append the new url to the array + NewTabCreated := 1 + sleep, 1000 + status := ActivateChromeTab(URLBase) + if(Status = "Failed"){ + Message = Failed to activate tab for %urlBase% after 2 atteppts. Chrome stuck on a dialog box of some sort? + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + Return "Failed" + } + + } ; message = ActivateChromeTab Status: %status% ; DevModeMsgBox(message) @@ -1083,16 +1100,14 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){ try driver.switchToalert().accept() try driver.Get(URL) ;Open selected URL catch e { - Message = Failed to Navigate to %URL%: Please Check for Any Open Dialogue Boxes + Message = Failed to Navigate to URL: %URL%. Please Check for any open dialog boxes or ChromeDriver being out of date. SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") Return "Failed" + } } try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding } - ; msgbox, no error caught - ; } - Return } @@ -1100,7 +1115,7 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){ CheckForAlerts(){ Message = Checking for Any Obstructing Alerts in Chrome - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") status := 1 try driver.SwitchToAlert() @@ -1123,11 +1138,11 @@ CheckForAlerts(){ } CheckURLForSubstring(Substring){ -try CurrentTabURL := driver.url + try CurrentTabURL := driver.url -if(InStr(CurrentTabURL, Substring)) + if(InStr(CurrentTabURL, Substring)) return "True" -else, + else, return } @@ -1210,235 +1225,239 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ ; Save current chrome version to ini file return Driver } + ; -------------------------------/SChrome_Get------------------------------- +/* +*/ +ShowSeleniumErrorMsgbox(){ + GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion + Chromeversion := RunCMD(GetChromeVersionCommand) + ChromeVersion := StrReplace(ChromeVersion, "`n", "") + + ; Clipboard := ChromeVersion + ; Msgbox % "Chromeversion: " Chromeversion + IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space% + ; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion + ; msgbox, failed to connect to Chrome for some reason. + ; Message = Failed to Connect to Chrome. Most likely problem is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated. + ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + + OnMessage(0x44, "OnMsgBoxChromeDriverFailed") + MsgBox 0x40043, Error, Failed to Connect to Chrome. `nMost likely issue is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated.`n`nClick "Reload" to reload the script to try again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up .pdf file with instructions for updating chromedriver.exe`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion% + OnMessage(0x44, "") - ShowSeleniumErrorMsgbox(){ - GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion - Chromeversion := RunCMD(GetChromeVersionCommand) - ChromeVersion := StrReplace(ChromeVersion, "`n", "") - - ; Clipboard := ChromeVersion - ; Msgbox % "Chromeversion: " Chromeversion - IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space% - ; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion - ; msgbox, failed to connect to Chrome for some reason. - ; Message = Failed to Connect to Chrome. Most likely problem is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated. - ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") - - OnMessage(0x44, "OnMsgBoxChromeDriverFailed") - MsgBox 0x40043, Error, Failed to Connect to Chrome. `nMost likely issue is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated.`n`nClick "Reload" to reload the script to try again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up .pdf file with instructions for updating chromedriver.exe`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion% - OnMessage(0x44, "") - - IfMsgBox Yes, { - ; Reload script - Reload - } Else IfMsgBox No, { - run, https://chromedriver.chromium.org/downloads - ExitApp - ; open chromedriver site - } Else IfMsgBox Cancel, { - URL = https://freedomainplaylists.com/wp-content/FreedomainScripts/Update`%20Selenium`%20ChromeDriver.pdf - Filepath = %A_ScriptDir%\Lib\Update Selenium ChromeDriver.pdf - if(!FileExist(Filepath)){ - UrlDownloadToFile, %URL%, %Filepath% - - run, %Filepath% - } - ExitApp - - } + IfMsgBox Yes, { + ; Reload script + Reload + } Else IfMsgBox No, { + run, https://chromedriver.chromium.org/downloads + ExitApp + ; open chromedriver site + } Else IfMsgBox Cancel, { + URL = https://freedomainplaylists.com/wp-content/FreedomainScripts/Update`%20Selenium`%20ChromeDriver.pdf + Filepath = %A_ScriptDir%\Lib\Update Selenium ChromeDriver.pdf + if(!FileExist(Filepath)){ + UrlDownloadToFile, %URL%, %Filepath% + + run, %Filepath% } + ExitApp + } + } - ; -------------------------------HasVal------------------------------- - ; Function needed for finding a value in an array - HasVal(haystack, needle) - { - if !(IsObject(haystack)) || (haystack.Length() = 0) - return 0 - for index, value in haystack - if (value = needle) - return index - return 0 - } - ; -------------------------------/HasVal------------------------------- - HasSubstringVal(haystack, needle) - { - if !(IsObject(haystack)) || (haystack.Length() = 0) - return 0 - for index, value in haystack - if (InStr(value, Needle)) - return index - return 0 - } + ; -------------------------------HasVal------------------------------- + ; Function needed for finding a value in an array + HasVal(haystack, needle) + { + if !(IsObject(haystack)) || (haystack.Length() = 0) + return 0 + for index, value in haystack + if (value = needle) + return index + return 0 + } + ; -------------------------------/HasVal------------------------------- - ; SubStr(String, StartingPos [, Length]) + HasSubstringVal(haystack, needle) + { + if !(IsObject(haystack)) || (haystack.Length() = 0) + return 0 + for index, value in haystack + if (InStr(value, Needle)) + return index + return 0 + } - ; InStr(value, Needle) + ; SubStr(String, StartingPos [, Length]) + ; InStr(value, Needle) - ; -------------------------------FileXPro Get File Attributes------------------------------- - ;https://www.autohotkey.com/boards/viewtopic.php?t=59882 +/* +*/ - Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9 - Local - Static xDetails +; -------------------------------FileXPro Get File Attributes------------------------------- +;https://www.autohotkey.com/boards/viewtopic.php?t=59882 - If ( sFile = "" ) - { ; Deinit static variable - xDetails := "" - Return - } +Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9 + Local + Static xDetails - fex := {}, _FileExt := "" + If ( sFile = "" ) + { ; Deinit static variable + xDetails := "" + Return + } - Loop, Files, % RTrim(sfile,"\*/."), DF - { - If not FileExist( sFile:=A_LoopFileLongPath ) - { - Return - } + fex := {}, _FileExt := "" - SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv + Loop, Files, % RTrim(sfile,"\*/."), DF + { + If not FileExist( sFile:=A_LoopFileLongPath ) + { + Return + } + + SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv + + If ( p[p.length()] = "xInfo" ) ; Last parameter is xInfo + { + p.Pop() ; Delete parameter + fex.SetCapacity(11) ; Make room for Extra info + fex["_Attrib"] := A_LoopFileAttrib + fex["_Dir"] := _Dir + fex["_Drv"] := _Drv + fex["_Ext"] := _Ext + fex["_File"] := _File + fex["_File.Ext"] := _FileExt + fex["_FilePath"] := sFile + fex["_FileSize"] := A_LoopFileSize + fex["_FileTimeA"] := A_LoopFileTimeAccessed + fex["_FileTimeC"] := A_LoopFileTimeCreated + fex["_FileTimeM"] := A_LoopFileTimeModified + } + Break + } - If ( p[p.length()] = "xInfo" ) ; Last parameter is xInfo - { - p.Pop() ; Delete parameter - fex.SetCapacity(11) ; Make room for Extra info - fex["_Attrib"] := A_LoopFileAttrib - fex["_Dir"] := _Dir - fex["_Drv"] := _Drv - fex["_Ext"] := _Ext - fex["_File"] := _File - fex["_File.Ext"] := _FileExt - fex["_FilePath"] := sFile - fex["_FileSize"] := A_LoopFileSize - fex["_FileTimeA"] := A_LoopFileTimeAccessed - fex["_FileTimeC"] := A_LoopFileTimeCreated - fex["_FileTimeM"] := A_LoopFileTimeModified - } - Break - } + If Not ( _FileExt ) ; Filepath not resolved + { + Return +} - If Not ( _FileExt ) ; Filepath not resolved - { - Return - } +objShl := ComObjCreate("Shell.Application") +objDir := objShl.NameSpace(_Dir) +objItm := objDir.ParseName(_FileExt) - objShl := ComObjCreate("Shell.Application") - objDir := objShl.NameSpace(_Dir) - objItm := objDir.ParseName(_FileExt) +If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable +{ + i:=-1, xDetails:={}, xDetails.SetCapacity(309) - If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable - { - i:=-1, xDetails:={}, xDetails.SetCapacity(309) + While ( i++ < 309 ) + { + xDetails[ objDir.GetDetailsOf(0,i) ] := i + } - While ( i++ < 309 ) - { - xDetails[ objDir.GetDetailsOf(0,i) ] := i - } + xDetails.Delete("") +} - xDetails.Delete("") - } +If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind +{ + Return +} - If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind - { - Return - } +i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11) - i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11) +While ( i++ < nParams ) +{ + Prop := p[i] - While ( i++ < nParams ) - { - Prop := p[i] - - If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) ) - { - fex[Prop] := objItm.ExtendedProperty(Prop) - Continue - } - - If ( PropNum := xDetails[Prop] ) > -1 - { - fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum) - Continue - } - } - - fex.SetCapacity(-1) - Return fex - - } ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; GuiButtonIcon - ;------------------------------------------------ - GuiButtonIcon(Handle, File, Index := 1, Options := "") - { - RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 : - RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 : - RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S : - RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 : - RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 : - RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 : - RegExMatch(Options, "i)b\K\d+", B), (B="") ? B := 0 : - RegExMatch(Options, "i)a\K\d+", A), (A="") ? A := 4 : - Psz := A_PtrSize = "" ? 4 : A_PtrSize, DW := "UInt", Ptr := A_PtrSize = "" ? DW : "Ptr" - VarSetCapacity( button_il, 20 + Psz, 0 ) - NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height - NumPut( L, button_il, 0 + Psz, DW ) ; Left Margin - NumPut( T, button_il, 4 + Psz, DW ) ; Top Margin - NumPut( R, button_il, 8 + Psz, DW ) ; Right Margin - NumPut( B, button_il, 12 + Psz, DW ) ; Bottom Margin - NumPut( A, button_il, 16 + Psz, DW ) ; Alignment - SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle% - return IL_Add( normal_il, File, Index ) - } + If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) ) + { + fex[Prop] := objItm.ExtendedProperty(Prop) + Continue + } - ; \GuiButtonIcon - ;------------------------------------------------ + If ( PropNum := xDetails[Prop] ) > -1 + { + fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum) + Continue + } +} +fex.SetCapacity(-1) +Return fex - ToggleTestingMode(){ +} ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IniRead, TestingMode, Settings.ini, General, TestingMode, 0 - ; Msgbox % "TestingMode: " TestingMode - if(TestingMode) - IniWrite, 0, Settings.ini, General, TestingMode - else, - IniWrite, 1, Settings.ini, General, TestingMode - } - ToggleManualSubmit(){ - IniRead, ManualSubmit, Settings.ini, General, ManualSubmit, 0 - ; Msgbox % "TestingMode: " TestingMode - if(ManualSubmit) - IniWrite, 0, Settings.ini, General, ManualSubmit - else, - IniWrite, 1, Settings.ini, General, ManualSubmit - } +; GuiButtonIcon +;------------------------------------------------ +GuiButtonIcon(Handle, File, Index := 1, Options := "") +{ + RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 : + RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 : + RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S : + RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 : + RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 : + RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 : + RegExMatch(Options, "i)b\K\d+", B), (B="") ? B := 0 : + RegExMatch(Options, "i)a\K\d+", A), (A="") ? A := 4 : + Psz := A_PtrSize = "" ? 4 : A_PtrSize, DW := "UInt", Ptr := A_PtrSize = "" ? DW : "Ptr" + VarSetCapacity( button_il, 20 + Psz, 0 ) + NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height + NumPut( L, button_il, 0 + Psz, DW ) ; Left Margin + NumPut( T, button_il, 4 + Psz, DW ) ; Top Margin + NumPut( R, button_il, 8 + Psz, DW ) ; Right Margin + NumPut( B, button_il, 12 + Psz, DW ) ; Bottom Margin + NumPut( A, button_il, 16 + Psz, DW ) ; Alignment + SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle% + return IL_Add( normal_il, File, Index ) +} + +; \GuiButtonIcon +;------------------------------------------------ - ToggleDevMode(){ +ToggleTestingMode(){ - IniRead, DevMode, Settings.ini, General, DevMode, 0 - ; Msgbox % "TestingMode: " TestingMode - if(DevMode) - IniWrite, 0, Settings.ini, General, DevMode - else, - IniWrite, 1, Settings.ini, General, DevMode - } + IniRead, TestingMode, Settings.ini, General, TestingMode, 0 + ; Msgbox % "TestingMode: " TestingMode + if(TestingMode) + IniWrite, 0, Settings.ini, General, TestingMode + else, + IniWrite, 1, Settings.ini, General, TestingMode +} +ToggleManualSubmit(){ + + IniRead, ManualSubmit, Settings.ini, General, ManualSubmit, 0 + ; Msgbox % "TestingMode: " TestingMode + if(ManualSubmit) + IniWrite, 0, Settings.ini, General, ManualSubmit + else, + IniWrite, 1, Settings.ini, General, ManualSubmit +} - FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones + +ToggleDevMode(){ + + IniRead, DevMode, Settings.ini, General, DevMode, 0 + ; Msgbox % "TestingMode: " TestingMode + if(DevMode) + IniWrite, 0, Settings.ini, General, DevMode + else, + IniWrite, 1, Settings.ini, General, DevMode +} + + +FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones /*\b Backspace \f Form Feed \n New Line - done @@ -1631,53 +1650,53 @@ js_SendAndCheckWithID(Element:="",ValueToCheck:="textContent",SleepLength:=1000, Selenium_LoopToClickID(IDName,NumOfLoops:=1,SleepLength:=1000){ loop, %NumOfLoops% { - try driver.findElementsByID(IDName).item[1].click() ; Click on "upload image" button - catch e { - if(A_index = NumOfLoops){ - Return "Failed" - } - sleep, %SleepLength% - Continue + try driver.findElementsByID(IDName).item[1].click() ; Click on "upload image" button + catch e { + if(A_index = NumOfLoops){ + Return "Failed" } - Return + sleep, %SleepLength% + Continue +} +Return } } Selenium_LoopToClickName(ElementName,NumOfLoops:=1,SleepLength:=1000){ loop, %NumOfLoops% { - try driver.findElementsByName(ElementName).item[1].click() - catch e { - if(A_index = NumOfLoops){ - Return "Failed" - } - sleep, %SleepLength% - Continue + try driver.findElementsByName(ElementName).item[1].click() + catch e { + if(A_index = NumOfLoops){ + Return "Failed" } - Return + sleep, %SleepLength% + Continue +} +Return } } Selenium_LoopToSendValueToID(IDName,NumOfLoops:=1,SleepLength:=1000,StringTextContent:=""){ loop, %NumOfLoops% { - try driver.findElementsByID(IDName).item[1].sendKeys(StringTextContent) ; Click on "upload image" button - catch e { - if(A_index = NumOfLoops){ - Return "Failed" - } - sleep, %SleepLength% - Continue + try driver.findElementsByID(IDName).item[1].sendKeys(StringTextContent) ; Click on "upload image" button + catch e { + if(A_index = NumOfLoops){ + Return "Failed" } - Return + sleep, %SleepLength% + Continue +} +Return } } ; Selenium_LoopToSendValueByName(ElementName:="NAME",NumOfLoops:=2,SleepLength:=1000,StringTextContent:="TEXT") Selenium_LoopToSendValueByName(ElementName,NumOfLoops:=1,SleepLength:=1000,StringTextContent:=""){ loop, %NumOfLoops% { - try driver.findElementsByName(ElementName).item[1].SendKeys(StringTextContent) - catch e { - if(A_index = NumOfLoops){ + try driver.findElementsByName(ElementName).item[1].SendKeys(StringTextContent) + catch e { + if(A_index = NumOfLoops){ Return "Failed" } sleep, %SleepLength% @@ -1692,7 +1711,7 @@ Selenium_LoopToSendValueToXpath(Xpath,NumOfLoops:=1,SleepLength:=1000,StringText ; ToolTip, Loop attempt: %A_index% try driver.FindElementByXPath(Xpath).sendKeys(StringTextContent) ; Click on "upload image" button catch e { - if(A_index = NumOfLoops){ + if(A_index = NumOfLoops){ Return "Failed" } sleep, %SleepLength% @@ -1705,15 +1724,15 @@ Selenium_LoopToSendValueToXpath(Xpath,NumOfLoops:=1,SleepLength:=1000,StringText Selenium_LoopToClickXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){ loop, %NumOfLoops% { - try driver.FindElementByXPath(Xpath).click() - catch e { - if(A_index = NumOfLoops){ - Return "Failed" - } - sleep, %SleepLength% - Continue + try driver.FindElementByXPath(Xpath).click() + catch e { + if(A_index = NumOfLoops){ + Return "Failed" } - Return + sleep, %SleepLength% + Continue +} +Return } } @@ -1722,7 +1741,7 @@ Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath,NumOfLoops:=1,SleepLength:=1 ; TooltipThis("Clicking xpath") try driver.FindElementByXPath(Xpath).click() catch e { - if(A_index = NumOfLoops){ + if(A_index = NumOfLoops){ Return "Failed to Click Xpath or Open File window did not show up on click" } sleep, %SleepLength% @@ -1745,15 +1764,15 @@ Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath,NumOfLoops:=1,SleepLength:=1 Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){ loop, %NumOfLoops% { - try driver.FindElementByXPath(Xpath).clear() - catch e { - if(A_index = NumOfLoops){ - Return "Failed" - } - sleep, %SleepLength% - Continue + try driver.FindElementByXPath(Xpath).clear() + catch e { + if(A_index = NumOfLoops){ + Return "Failed" } - Return + sleep, %SleepLength% + Continue +} +Return } } @@ -1762,109 +1781,117 @@ Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){ ; -------------------------------Javascript------------------------------- ReturnAndDisplayJSData(jsref){ -; msgbox, here goes -; https://www.w3schools.com/jsref/dom_obj_all.asp -; -----TEXT CONTENT----- -js = return %jsref%.textContent; -try status := driver.executeScript(js) - -OnMessage(0x44, "OnMsgBoxJSReturnData") -MsgBox 0x3,.TextContent:,%status% -OnMessage(0x44, "") - + ; msgbox, here goes + ; https://www.w3schools.com/jsref/dom_obj_all.asp + ; -----TEXT CONTENT----- + js = return %jsref%.textContent; + try status := driver.executeScript(js) + + OnMessage(0x44, "OnMsgBoxJSReturnData") + MsgBox 0x3,.TextContent:,%status% + OnMessage(0x44, "") +/* +*/ IfMsgBox Yes,{ -} Else IfMsgBox No, { -TextForClip = js = %js% `n try, status := driver.executeScript(js) -Clipboard := TextForClip -} Else IfMsgBox Cancel, { -return -} - -; -----VALUE----- -js = return %jsref%.value; -try status := driver.executeScript(js) + } Else IfMsgBox No, { + TextForClip = js = %js% `n try, status := driver.executeScript(js) + Clipboard := TextForClip + } Else IfMsgBox Cancel, { + return + } + ; -----VALUE----- + js = return %jsref%.value; + try status := driver.executeScript(js) -OnMessage(0x44, "OnMsgBoxJSReturnData") -MsgBox 0x3,.value:,%status% -OnMessage(0x44, "") + OnMessage(0x44, "OnMsgBoxJSReturnData") + MsgBox 0x3,.value:,%status% + OnMessage(0x44, "") +/* +*/ IfMsgBox Yes,{ -} Else IfMsgBox No, { -TextForClip = js = %js% `n try, status := driver.executeScript(js) -Clipboard := TextForClip -} Else IfMsgBox Cancel, { -return -} - -; -----INNERTEXT----- -js = return %jsref%.innerText; -try status := driver.executeScript(js) + } Else IfMsgBox No, { + TextForClip = js = %js% `n try, status := driver.executeScript(js) + Clipboard := TextForClip + } Else IfMsgBox Cancel, { + return + } + ; -----INNERTEXT----- + js = return %jsref%.innerText; + try status := driver.executeScript(js) -OnMessage(0x44, "OnMsgBoxJSReturnData") -MsgBox 0x3, .innerText,%status% -OnMessage(0x44, "") + OnMessage(0x44, "OnMsgBoxJSReturnData") + MsgBox 0x3, .innerText,%status% + OnMessage(0x44, "") +/* +*/ IfMsgBox Yes,{ -} Else IfMsgBox No, { -TextForClip = js = %js% `n try, status := driver.executeScript(js) -Clipboard := TextForClip -} Else IfMsgBox Cancel, { - return -} + } Else IfMsgBox No, { + TextForClip = js = %js% `n try, status := driver.executeScript(js) + Clipboard := TextForClip + } Else IfMsgBox Cancel, { + return + } -; -----OuterText----- -js = return %jsref%.outerText; -try status := driver.executeScript(js) + ; -----OuterText----- + js = return %jsref%.outerText; + try status := driver.executeScript(js) -OnMessage(0x44, "OnMsgBoxJSReturnData") -MsgBox 0x3, .outerText,%status% -OnMessage(0x44, "") + OnMessage(0x44, "OnMsgBoxJSReturnData") + MsgBox 0x3, .outerText,%status% + OnMessage(0x44, "") +/* +*/ IfMsgBox Yes,{ -} Else IfMsgBox No, { -TextForClip = js = %js% `n try, status := driver.executeScript(js) -Clipboard := TextForClip -} Else IfMsgBox Cancel, { -return -} + } Else IfMsgBox No, { + TextForClip = js = %js% `n try, status := driver.executeScript(js) + Clipboard := TextForClip + } Else IfMsgBox Cancel, { + return + } -;-----innerHTML----- -js = return %jsref%.innerHTML; -try status := driver.executeScript(js) + ;-----innerHTML----- + js = return %jsref%.innerHTML; + try status := driver.executeScript(js) -OnMessage(0x44, "OnMsgBoxJSReturnData") -MsgBox 0x3, .innerHTML,%status% -OnMessage(0x44, "") + OnMessage(0x44, "OnMsgBoxJSReturnData") + MsgBox 0x3, .innerHTML,%status% + OnMessage(0x44, "") +/* +*/ IfMsgBox Yes,{ -} Else IfMsgBox No, { -TextForClip = js = %js% `n try, status := driver.executeScript(js) -Clipboard := TextForClip -} Else IfMsgBox Cancel, { - return -} - + } Else IfMsgBox No, { + TextForClip = js = %js% `n try, status := driver.executeScript(js) + Clipboard := TextForClip + } Else IfMsgBox Cancel, { + return + } -; -----outerHTML----- -js = return %jsref%.outerHTML; -try status := driver.executeScript(js) + ; -----outerHTML----- + js = return %jsref%.outerHTML; + try status := driver.executeScript(js) -OnMessage(0x44, "OnMsgBoxJSReturnData") -MsgBox 0x3, .outerHTML,%status% -OnMessage(0x44, "") + OnMessage(0x44, "OnMsgBoxJSReturnData") + MsgBox 0x3, .outerHTML,%status% + OnMessage(0x44, "") +/* +*/ IfMsgBox Yes,{ } Else IfMsgBox No, { @@ -1875,9 +1902,9 @@ IfMsgBox Yes,{ } - } - - + } +/* +*/ OnMsgBoxJSReturnData() { DetectHiddenWindows, On Process, Exist