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
|
; #Include %A_ScriptDir%\RunCMD.ahk
|
||||||
|
|
||||||
|
|
||||||
|
; @todo: add error checks for all winhttp requests.
|
||||||
|
|
||||||
|
|
||||||
DevModeMsgBox(Message){
|
DevModeMsgBox(Message){
|
||||||
@@ -26,7 +27,7 @@ DevModeMsgBox(Message){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CheckForUpdates(){
|
CheckForUpdates(GitReleasesAPIURL){
|
||||||
; msgbox, checking for updates
|
; msgbox, checking for updates
|
||||||
Message = Checking For Updates
|
Message = Checking For Updates
|
||||||
SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile")
|
SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile")
|
||||||
@@ -39,10 +40,10 @@ CheckForUpdates(){
|
|||||||
UpdateVersionNumber := parsed.1.name
|
UpdateVersionNumber := parsed.1.name
|
||||||
|
|
||||||
if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){
|
if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){
|
||||||
ToolTip
|
ToolTip
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
else, {
|
else, {
|
||||||
UpdateAvailable := 1
|
UpdateAvailable := 1
|
||||||
; msgbox, update found!
|
; msgbox, update found!
|
||||||
Message = Program Update Found
|
Message = Program Update Found
|
||||||
@@ -148,24 +149,24 @@ TakeScreenshotOfPage(SaveFilepath := ""){
|
|||||||
; sleep, 5000
|
; sleep, 5000
|
||||||
|
|
||||||
if(SaveFilepath = ""){
|
if(SaveFilepath = ""){
|
||||||
SaveFilepath := ErrorLoggingDirectory
|
SaveFilepath := ErrorLoggingDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
; if(!FileExist(SaveFilepath))
|
; if(!FileExist(SaveFilepath))
|
||||||
FileCreateDir, %SaveFilepath%
|
FileCreateDir, %SaveFilepath%
|
||||||
|
|
||||||
if(!TakeScreenshotsOfErrors)
|
if(!TakeScreenshotsOfErrors)
|
||||||
Return
|
Return
|
||||||
|
|
||||||
; Take a screenshot of the page and save it.
|
; Take a screenshot of the page and save it.
|
||||||
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
|
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
|
||||||
|
|
||||||
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
|
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
|
||||||
savepath = %SaveFilepath%\%TodayDate%.jpg
|
savepath = %SaveFilepath%\%TodayDate%.jpg
|
||||||
; Msgbox % "savepath: " savepath
|
; Msgbox % "savepath: " savepath
|
||||||
try driver.TakeScreenshot().SaveAs(savepath)
|
try driver.TakeScreenshot().SaveAs(savepath)
|
||||||
|
|
||||||
; ScreenshotsTaken := 1
|
; ScreenshotsTaken := 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +175,7 @@ TakeScreenshotOfPage(SaveFilepath := ""){
|
|||||||
|
|
||||||
; -------------------------------TooltipThis-------------------------------
|
; -------------------------------TooltipThis-------------------------------
|
||||||
TooltipThis(String){
|
TooltipThis(String){
|
||||||
|
; msgbox
|
||||||
; Xposition := StrLen(String)
|
; Xposition := StrLen(String)
|
||||||
StringFirstLine := StrSplit(String, "`n")
|
StringFirstLine := StrSplit(String, "`n")
|
||||||
StringFirstLine := StringFirstLine[1]
|
StringFirstLine := StringFirstLine[1]
|
||||||
@@ -922,155 +924,76 @@ if(TotalTabsFound = 1){
|
|||||||
; / END OF FUNC
|
; / END OF FUNC
|
||||||
}
|
}
|
||||||
|
|
||||||
InputFilePathIntoOpenWindow(Filepath){
|
/*
|
||||||
; Msgbox % "Filepath: " Filepath
|
*/
|
||||||
Message = Waiting for "Open" window to appear to input filepath into
|
InputFilePathIntoOpenWindow(Filepath){
|
||||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
; Msgbox % "Filepath: " Filepath
|
||||||
; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0
|
Message = Waiting for "Open" window to appear to input filepath into
|
||||||
; WinWait, Open
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||||
WinWait,Open,,5 ; Wait for 10 seconds for window
|
; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0
|
||||||
if(ErrorLevel)
|
; WinWait, Open
|
||||||
{
|
WinWait,Open,,5 ; Wait for 10 seconds for window
|
||||||
; msgbox, failed to find window.
|
if(ErrorLevel)
|
||||||
Return "Failed"
|
{
|
||||||
}
|
; msgbox, failed to find window.
|
||||||
WinActivate, Open
|
Return "Failed"
|
||||||
sleep, 1000
|
}
|
||||||
ControlSetText, Edit1, %Filepath%, Open
|
WinActivate, Open
|
||||||
sleep, 1000
|
sleep, 1000
|
||||||
ControlSend, Edit1, {Enter}, Open
|
ControlSetText, Edit1, %Filepath%, Open
|
||||||
sleep, 1000
|
sleep, 1000
|
||||||
|
ControlSend, Edit1, {Enter}, Open
|
||||||
|
sleep, 1000
|
||||||
|
|
||||||
; Do an extra check in case the Open window is still open.
|
; Do an extra check in case the Open window is still open.
|
||||||
OpenWindowExist := WinExist("Open")
|
OpenWindowExist := WinExist("Open")
|
||||||
if(OpenWindowExist)
|
if(OpenWindowExist)
|
||||||
ControlSend, Edit1, {Enter}, Open
|
ControlSend, Edit1, {Enter}, Open
|
||||||
ToolTip,
|
ToolTip,
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckCurrentTabForCurrentSite(){
|
CheckCurrentTabForCurrentSite(){
|
||||||
try CurrentTabURL := driver.url
|
try CurrentTabURL := driver.url
|
||||||
|
|
||||||
if(!InStr(CurrentTabURL, CurrentSite)){
|
if(!InStr(CurrentTabURL, CurrentSite)){
|
||||||
Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on.
|
Message = Chromedriver failed to switch to %CurrentSite%. Please see errorlog for website it got stuck on.
|
||||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||||
return "Failed"
|
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 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.
|
; msgbox % InStr(CurrentTabURL,CurrentSite)
|
||||||
; 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
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
; -------------------------------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.Get(URL) ;Open selected URL
|
||||||
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
|
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
|
||||||
catch e {
|
catch e {
|
||||||
@@ -1083,12 +1006,93 @@ if(TotalTabsFound = 1){
|
|||||||
Return "Failed"
|
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
|
; End of Function
|
||||||
; -------------------------------/NavigateFromBaseURL-------------------------------
|
; -------------------------------/NavigateFromBaseURL-------------------------------
|
||||||
@@ -1165,19 +1169,19 @@ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
|
|||||||
try Driver.Start()
|
try Driver.Start()
|
||||||
catch e {
|
catch e {
|
||||||
ShowSeleniumErrorMsgbox()
|
ShowSeleniumErrorMsgbox()
|
||||||
}
|
}
|
||||||
|
|
||||||
return Driver
|
return Driver
|
||||||
}
|
}
|
||||||
; -------------------------------/SChrome_Get-------------------------------
|
; -------------------------------/SChrome_Get-------------------------------
|
||||||
|
|
||||||
ShowSeleniumErrorMsgbox(){
|
ShowSeleniumErrorMsgbox(){
|
||||||
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
||||||
Chromeversion := RunCMD(GetChromeVersionCommand)
|
Chromeversion := RunCMD(GetChromeVersionCommand)
|
||||||
ChromeVersion := StrReplace(ChromeVersion, "`n", "")
|
ChromeVersion := StrReplace(ChromeVersion, "`n", "")
|
||||||
|
|
||||||
Message = Failed to connect to Chrome
|
Message = Failed to connect to Chrome
|
||||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
; check for alert popup
|
; check for alert popup
|
||||||
|
|||||||
Reference in New Issue
Block a user