Added functions from Social Media Poster Shared Functions file so SharedFunctions.ahk can be replaced by this submodule
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "Lib/Freedomain-Posters-Shared-Functions"]
|
||||
path = Lib/Freedomain-Posters-Shared-Functions
|
||||
url = https://git.freedomainplaylists.com/yuriy/Freedomain-Posters-Shared-Functions.git
|
||||
1
Lib/Freedomain-Posters-Shared-Functions
Submodule
1
Lib/Freedomain-Posters-Shared-Functions
Submodule
Submodule Lib/Freedomain-Posters-Shared-Functions added at 694c440a6a
@@ -15,6 +15,7 @@ global CurrentTabURL
|
||||
; #Include %A_ScriptDir%\RunCMD.ahk
|
||||
|
||||
|
||||
; @todo: add error checks for all winhttp requests.
|
||||
|
||||
|
||||
DevModeMsgBox(Message){
|
||||
@@ -26,7 +27,7 @@ DevModeMsgBox(Message){
|
||||
}
|
||||
|
||||
|
||||
CheckForUpdates(){
|
||||
CheckForUpdates(GitReleasesAPIURL){
|
||||
; msgbox, checking for updates
|
||||
Message = Checking For Updates
|
||||
SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile")
|
||||
@@ -39,10 +40,10 @@ CheckForUpdates(){
|
||||
UpdateVersionNumber := parsed.1.name
|
||||
|
||||
if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){
|
||||
ToolTip
|
||||
return
|
||||
}
|
||||
else, {
|
||||
ToolTip
|
||||
return
|
||||
}
|
||||
else, {
|
||||
UpdateAvailable := 1
|
||||
; msgbox, update found!
|
||||
Message = Program Update Found
|
||||
@@ -148,24 +149,24 @@ TakeScreenshotOfPage(SaveFilepath := ""){
|
||||
; sleep, 5000
|
||||
|
||||
if(SaveFilepath = ""){
|
||||
SaveFilepath := ErrorLoggingDirectory
|
||||
}
|
||||
SaveFilepath := ErrorLoggingDirectory
|
||||
}
|
||||
|
||||
; if(!FileExist(SaveFilepath))
|
||||
FileCreateDir, %SaveFilepath%
|
||||
; if(!FileExist(SaveFilepath))
|
||||
FileCreateDir, %SaveFilepath%
|
||||
|
||||
if(!TakeScreenshotsOfErrors)
|
||||
Return
|
||||
if(!TakeScreenshotsOfErrors)
|
||||
Return
|
||||
|
||||
; Take a screenshot of the page and save it.
|
||||
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
|
||||
; Take a screenshot of the page and save it.
|
||||
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
|
||||
|
||||
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
|
||||
savepath = %SaveFilepath%\%TodayDate%.jpg
|
||||
; Msgbox % "savepath: " savepath
|
||||
try driver.TakeScreenshot().SaveAs(savepath)
|
||||
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
|
||||
savepath = %SaveFilepath%\%TodayDate%.jpg
|
||||
; Msgbox % "savepath: " savepath
|
||||
try driver.TakeScreenshot().SaveAs(savepath)
|
||||
|
||||
; ScreenshotsTaken := 1
|
||||
; ScreenshotsTaken := 1
|
||||
|
||||
}
|
||||
|
||||
@@ -174,6 +175,7 @@ TakeScreenshotOfPage(SaveFilepath := ""){
|
||||
|
||||
; -------------------------------TooltipThis-------------------------------
|
||||
TooltipThis(String){
|
||||
; msgbox
|
||||
; Xposition := StrLen(String)
|
||||
StringFirstLine := StrSplit(String, "`n")
|
||||
StringFirstLine := StringFirstLine[1]
|
||||
@@ -922,155 +924,76 @@ if(TotalTabsFound = 1){
|
||||
; / END OF FUNC
|
||||
}
|
||||
|
||||
InputFilePathIntoOpenWindow(Filepath){
|
||||
; Msgbox % "Filepath: " Filepath
|
||||
Message = Waiting for "Open" window to appear to input filepath into
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0
|
||||
; WinWait, Open
|
||||
WinWait,Open,,5 ; Wait for 10 seconds for window
|
||||
if(ErrorLevel)
|
||||
{
|
||||
; msgbox, failed to find window.
|
||||
Return "Failed"
|
||||
}
|
||||
WinActivate, Open
|
||||
sleep, 1000
|
||||
ControlSetText, Edit1, %Filepath%, Open
|
||||
sleep, 1000
|
||||
ControlSend, Edit1, {Enter}, Open
|
||||
sleep, 1000
|
||||
/*
|
||||
*/
|
||||
InputFilePathIntoOpenWindow(Filepath){
|
||||
; Msgbox % "Filepath: " Filepath
|
||||
Message = Waiting for "Open" window to appear to input filepath into
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0
|
||||
; WinWait, Open
|
||||
WinWait,Open,,5 ; Wait for 10 seconds for window
|
||||
if(ErrorLevel)
|
||||
{
|
||||
; msgbox, failed to find window.
|
||||
Return "Failed"
|
||||
}
|
||||
WinActivate, Open
|
||||
sleep, 1000
|
||||
ControlSetText, Edit1, %Filepath%, Open
|
||||
sleep, 1000
|
||||
ControlSend, Edit1, {Enter}, Open
|
||||
sleep, 1000
|
||||
|
||||
; Do an extra check in case the Open window is still open.
|
||||
OpenWindowExist := WinExist("Open")
|
||||
if(OpenWindowExist)
|
||||
ControlSend, Edit1, {Enter}, Open
|
||||
ToolTip,
|
||||
}
|
||||
; Do an extra check in case the Open window is still open.
|
||||
OpenWindowExist := WinExist("Open")
|
||||
if(OpenWindowExist)
|
||||
ControlSend, Edit1, {Enter}, Open
|
||||
ToolTip,
|
||||
}
|
||||
|
||||
CheckCurrentTabForCurrentSite(){
|
||||
try CurrentTabURL := driver.url
|
||||
CheckCurrentTabForCurrentSite(){
|
||||
try CurrentTabURL := driver.url
|
||||
|
||||
if(!InStr(CurrentTabURL, CurrentSite)){
|
||||
Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on.
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
return "Failed"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
; msgbox % InStr(CurrentTabURL,CurrentSite)
|
||||
|
||||
}
|
||||
|
||||
|
||||
; -------------------------------NavigateFromBaseURLTo-------------------------------
|
||||
NavigateFromBaseURLTo(URL){
|
||||
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
|
||||
Status := CheckSeleniumDriver()
|
||||
if(Status)
|
||||
Return "Failed"
|
||||
|
||||
CreateArrayOfTabs() ; store all open tabs to memory for later usage
|
||||
}
|
||||
|
||||
|
||||
if(ReuseTabs){ ; pull out base of URL and check if it's within the array of tabs
|
||||
URLBase := StrReplace(URL,"https://","")
|
||||
URLBase := StrSplit(URLBase, "/")
|
||||
URLBase := URLBase[1]
|
||||
URLBase := StrReplace(URLBase, "www.","")
|
||||
}
|
||||
|
||||
; if base url is not in tab array, create new tab and push url to array
|
||||
if(!HasSubstringVal(DriverURLArray, URLBase))
|
||||
{
|
||||
try CurrentTabTitle := driver.window.title
|
||||
|
||||
; if currently in new tab navigate to the site in the current tab
|
||||
if(CurrentTabTitle = "New Tab"){
|
||||
try driver.Get(URL) ;Open selected URL
|
||||
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
|
||||
catch e {
|
||||
; msgbox, error caught. trying something
|
||||
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
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
Return "Failed"
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
else, {
|
||||
try, run "%ChromeFilepath%" "%URL%"
|
||||
DriverURLArray.Push(URL) ; Append an item to the array
|
||||
NewTabCreated := 1
|
||||
; sleep, 2000
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Message = Finding Tab
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
|
||||
TabFoundSuccessfully :=
|
||||
|
||||
NumberOfTabLoops := DriverURLArray.Length()
|
||||
|
||||
; loop through tabs to find matching tab
|
||||
loop % NumberOfTabLoops {
|
||||
try driver.SwitchToNextWindow()
|
||||
|
||||
; sleep, 1000
|
||||
; msgbox, looping through tabs
|
||||
try CurrentTabTitle := driver.window.title
|
||||
try CurrentTabURL := driver.Url
|
||||
|
||||
; DevModeMsgBox(CurrentTabURL)
|
||||
; DevModeMsgBox(CurrentTabTitle)
|
||||
|
||||
; caused by tab being manually closed. Not sure if this is the only cause though.
|
||||
if(CurrentTabTitle = "") {
|
||||
Message = CurrentTabTitle: %CurrentTabTitle%
|
||||
; DevModeMsgBox(Message)
|
||||
|
||||
Message = CurrenttabURL: %CurrentTabURL%
|
||||
; DevModeMsgBox(Message)
|
||||
|
||||
; try driver.SwitchToNextWindow
|
||||
Continue
|
||||
}
|
||||
|
||||
|
||||
if(InStr(CurrentTabURL, URLBase)){
|
||||
Message = CurrentTabURL is %CurrentTabURL% and it contains %URLBase%
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
|
||||
|
||||
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
|
||||
TabFoundSuccessfully := 1
|
||||
; message = %CurrentTabTitle%: %PageTitle%
|
||||
; DevModeMsgBox(message)
|
||||
; msgbox %CurrentTabURL% = %URL%
|
||||
Break
|
||||
}
|
||||
if(!InStr(CurrentTabURL, CurrentSite)){
|
||||
Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on.
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
return "Failed"
|
||||
}
|
||||
|
||||
; if failed to switch to tab and a new tab was not created, then chrome failed to switch to the tab
|
||||
; this happens sometimes. most likely to a chromedriver bug or maybe tab being offloaded?
|
||||
if(!TabFoundSuccessfully AND !NewTabCreated){
|
||||
; @todo : not sure how to best solve this problem currently. It doesn't happen very often.
|
||||
; last time it happened was when there were only 2 chrome tabs open, gab + subscribestar. chrome was stuck on subscribestar page and wouldn't nextwindow() to gab
|
||||
|
||||
|
||||
|
||||
; msgbox % InStr(CurrentTabURL,CurrentSite)
|
||||
|
||||
}
|
||||
|
||||
|
||||
; -------------------------------NavigateFromBaseURLTo-------------------------------
|
||||
NavigateFromBaseURLTo(URL, Title:="REmoveMe"){
|
||||
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
|
||||
Status := CheckSeleniumDriver()
|
||||
if(Status)
|
||||
Return "Failed"
|
||||
|
||||
CreateArrayOfTabs() ; store all open tabs to memory for later usage
|
||||
}
|
||||
|
||||
; Message = TabFoundSuccessfully: %TabFoundSuccessfully%
|
||||
; DevModeMsgBox(Message)
|
||||
|
||||
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
|
||||
if(ReuseTabs){ ; pull out base of URL and check if it's within the array of tabs
|
||||
URLBase := StrReplace(URL,"https://","")
|
||||
URLBase := StrSplit(URLBase, "/")
|
||||
URLBase := URLBase[1]
|
||||
URLBase := StrReplace(URLBase, "www.","")
|
||||
}
|
||||
|
||||
; if base url is not in tab array, create new tab and push url to array
|
||||
if(!HasSubstringVal(DriverURLArray, URLBase))
|
||||
{
|
||||
try CurrentTabTitle := driver.window.title
|
||||
|
||||
; if currently in new tab navigate to the site in the current tab
|
||||
if(CurrentTabTitle = "New Tab"){
|
||||
try driver.Get(URL) ;Open selected URL
|
||||
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
|
||||
catch e {
|
||||
@@ -1083,12 +1006,93 @@ if(TotalTabsFound = 1){
|
||||
Return "Failed"
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
else, {
|
||||
try, run "%ChromeFilepath%" "%URL%"
|
||||
DriverURLArray.Push(URL) ; Append an item to the array
|
||||
NewTabCreated := 1
|
||||
; sleep, 2000
|
||||
}
|
||||
; msgbox, no error caught
|
||||
; }
|
||||
|
||||
|
||||
Return
|
||||
|
||||
}
|
||||
|
||||
Message = Finding Tab
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
|
||||
TabFoundSuccessfully :=
|
||||
|
||||
NumberOfTabLoops := DriverURLArray.Length()
|
||||
|
||||
; loop through tabs to find matching tab
|
||||
loop % NumberOfTabLoops {
|
||||
try driver.SwitchToNextWindow()
|
||||
|
||||
; sleep, 1000
|
||||
; msgbox, looping through tabs
|
||||
try CurrentTabTitle := driver.window.title
|
||||
try CurrentTabURL := driver.Url
|
||||
|
||||
; DevModeMsgBox(CurrentTabURL)
|
||||
; DevModeMsgBox(CurrentTabTitle)
|
||||
|
||||
; caused by tab being manually closed. Not sure if this is the only cause though.
|
||||
if(CurrentTabTitle = "") {
|
||||
Message = CurrentTabTitle: %CurrentTabTitle%
|
||||
; DevModeMsgBox(Message)
|
||||
|
||||
Message = CurrenttabURL: %CurrentTabURL%
|
||||
; DevModeMsgBox(Message)
|
||||
|
||||
; try driver.SwitchToNextWindow
|
||||
Continue
|
||||
}
|
||||
|
||||
|
||||
if(InStr(CurrentTabURL, URLBase)){
|
||||
Message = CurrentTabURL is %CurrentTabURL% and it contains %URLBase%
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
|
||||
|
||||
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
|
||||
TabFoundSuccessfully := 1
|
||||
; message = %CurrentTabTitle%: %PageTitle%
|
||||
; DevModeMsgBox(message)
|
||||
; msgbox %CurrentTabURL% = %URL%
|
||||
Break
|
||||
}
|
||||
}
|
||||
|
||||
; if failed to switch to tab and a new tab was not created, then chrome failed to switch to the tab
|
||||
; this happens sometimes. most likely to a chromedriver bug or maybe tab being offloaded?
|
||||
if(!TabFoundSuccessfully AND !NewTabCreated){
|
||||
; @todo : not sure how to best solve this problem currently. It doesn't happen very often.
|
||||
; last time it happened was when there were only 2 chrome tabs open, gab + subscribestar. chrome was stuck on subscribestar page and wouldn't nextwindow() to gab
|
||||
}
|
||||
|
||||
; Message = TabFoundSuccessfully: %TabFoundSuccessfully%
|
||||
; DevModeMsgBox(Message)
|
||||
|
||||
if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
|
||||
try driver.Get(URL) ;Open selected URL
|
||||
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
|
||||
catch e {
|
||||
; msgbox, error caught. trying something
|
||||
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
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
Return "Failed"
|
||||
}
|
||||
}
|
||||
}
|
||||
; msgbox, no error caught
|
||||
; }
|
||||
|
||||
|
||||
Return
|
||||
}
|
||||
; End of Function
|
||||
; -------------------------------/NavigateFromBaseURL-------------------------------
|
||||
@@ -1165,19 +1169,19 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
|
||||
try Driver.Start()
|
||||
catch e {
|
||||
ShowSeleniumErrorMsgbox()
|
||||
}
|
||||
}
|
||||
|
||||
return Driver
|
||||
}
|
||||
; -------------------------------/SChrome_Get-------------------------------
|
||||
return Driver
|
||||
}
|
||||
; -------------------------------/SChrome_Get-------------------------------
|
||||
|
||||
ShowSeleniumErrorMsgbox(){
|
||||
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
||||
Chromeversion := RunCMD(GetChromeVersionCommand)
|
||||
ChromeVersion := StrReplace(ChromeVersion, "`n", "")
|
||||
ShowSeleniumErrorMsgbox(){
|
||||
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
||||
Chromeversion := RunCMD(GetChromeVersionCommand)
|
||||
ChromeVersion := StrReplace(ChromeVersion, "`n", "")
|
||||
|
||||
Message = Failed to connect to Chrome
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
Message = Failed to connect to Chrome
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
|
||||
/*
|
||||
; check for alert popup
|
||||
|
||||
Reference in New Issue
Block a user