formatting updates

main
Yuriy 2 years ago
parent de5b8afdf0
commit 2286c13ceb

@ -14,8 +14,7 @@ global CurrentTabURL
; #Include %A_ScriptDir%\ChromeAutomationFunctions.ahk ; #Include %A_ScriptDir%\ChromeAutomationFunctions.ahk
; #Include %A_ScriptDir%\RunCMD.ahk ; #Include %A_ScriptDir%\RunCMD.ahk
#Include C:\Users\%A_username%\Syncthing\Freedomain\Uploaders\Lib\ChromeAutomationFunctions.ahk
#Include C:\Users\%A_username%\Syncthing\Freedomain\Uploaders\Lib\RunCMD.ahk
DevModeMsgBox(Message){ DevModeMsgBox(Message){
@ -35,8 +34,6 @@ CheckForUpdates(){
data := URLDownloadToVar(GitReleasesAPIURL) data := URLDownloadToVar(GitReleasesAPIURL)
; Msgbox % "data: " data ; Msgbox % "data: " data
; [{"id":3,"tag_name":"v2.71","target_commitish":"main","name":"2.71","body":"- Fixed and expanded Parler login check\r\n- Fixed long time bug where a newly created website tab would not get connected to properly\r\n- Temporarily removed Auto Update Support until I can integrate with gitea API","url":"https://git.zinchuk.xyz/api/v1/repos/yuriy/Freedomain_Social_Media_Poster/releases/3","html_url":"https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/releases/tag/v2.71","tarball_url":"https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/archive/v2.71.tar.gz","zipball_url":"https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/archive/v2.71.zip","draft":false,"prerelease":true,"created_at":"2023-01-26T23:45:25-05:00","published_at":"2023-01-26T23:45:25-05:00","author":{"id":1,"login":"yuriy","login_name":"","full_name":"Yuriy Zinchuk","email":"yuriy@noreply.localhost","avatar_url":"https://secure.gravatar.com/avatar/82acf184352c9232da15222248417df0?d=identicon","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-01-02T16:40:09-05:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"yuriy"},"assets":[{"id":4,"name":"Freedomain Social Media Poster.exe","size":1708544,"download_count":0,"created_at":"2023-01-26T23:45:19-05:00","uuid":"2ee05d49-a314-4079-bcc8-b6857dc29e98","browser_download_url":"https://git.zinchuk.xyz/attachments/2ee05d49-a314-4079-bcc8-b6857dc29e98"}]},{"id":2,"tag_name":"v2.70","target_commitish":"main","name":"2.70","body":"* Initial commit of V2.7 to git\r\n* Pushed codebase to personal [git instance](https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/)\r\n* Fixed Locals Posting\r\n* Fixed Gettr Posting\r\n* Fixed Flote Posting\r\n* Fixed MeWe Posting\r\n* Fixed Minds Posting\r\n* Fixed Steemit Posting\r\n* Fixed LinkedIn Image Posting\r\n* Removed Tumblr Support\r\n* Removed Pintrest support","url":"https://git.zinchuk.xyz/api/v1/repos/yuriy/Freedomain_Social_Media_Poster/releases/2","html_url":"https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/releases/tag/v2.70","tarball_url":"https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/archive/v2.70.tar.gz","zipball_url":"https://git.zinchuk.xyz/yuriy/Freedomain_Social_Media_Poster/archive/v2.70.zip","draft":false,"prerelease":true,"created_at":"2023-01-25T22:38:24-05:00","published_at":"2023-01-25T22:38:24-05:00","author":{"id":1,"login":"yuriy","login_name":"","full_name":"Yuriy Zinchuk","email":"yuriy@noreply.localhost","avatar_url":"https://secure.gravatar.com/avatar/82acf184352c9232da15222248417df0?d=identicon","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2023-01-02T16:40:09-05:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"yuriy"},"assets":[{"id":2,"name":"Freedomain Social Media Poster.exe","size":1707520,"download_count":1,"created_at":"2023-01-25T22:36:17-05:00","uuid":"d91a4ab0-b1fb-4c2f-adfa-e986e587cf0a","browser_download_url":"https://git.zinchuk.xyz/attachments/d91a4ab0-b1fb-4c2f-adfa-e986e587cf0a"}]}]
parsed := JSON.Load(data) parsed := JSON.Load(data)
UpdateVersionNumber := parsed.1.name UpdateVersionNumber := parsed.1.name
@ -58,8 +55,6 @@ CheckForUpdates(){
} }
UpdateScript(){ UpdateScript(){
data := URLDownloadToVar(GitReleasesAPIURL) data := URLDownloadToVar(GitReleasesAPIURL)
@ -95,81 +90,82 @@ UpdateScript(){
IfMsgBox Yes, { IfMsgBox Yes, {
Return Return
} Else IfMsgBox No, {
SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
; Msgbox, downloading to: %A_ScriptDir%\%UpdateExeName%
UrlDownloadToFile, %exeURL%, %UpdateExeFilepath%
run, "%UpdateExeFilepath%" "%A_ScriptFullPath%"
ExitApp
}
return
} }
Else IfMsgBox No, {
SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile")
; Msgbox, downloading to: %A_ScriptDir%\%UpdateExeName%
UrlDownloadToFile, %exeURL%, %UpdateExeFilepath%
run, "%UpdateExeFilepath%" "%A_ScriptFullPath%"
ExitApp
}
return
}
; -------------------------------SaveOrPostProgress------------------------------- ; -------------------------------SaveOrPostProgress-------------------------------
; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos" ; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos"
SaveOrPostProgress(Message:="",PostType:=""){ SaveOrPostProgress(Message:="",PostType:=""){
MessageBU := Message MessageBU := Message
; Msgbox % "PostType: " PostType ; Msgbox % "PostType: " PostType
; Msgbox % "CurrentSite: " CurrentSite ; Msgbox % "CurrentSite: " CurrentSite
if(CurrentSite != "") if(CurrentSite != "")
Message := CurrentSite . ": " . Message Message := CurrentSite . ": " . Message
if(InStr(PostType, "Tooltip")){ if(InStr(PostType, "Tooltip")){
TooltipThis(Message) TooltipThis(Message)
} }
if(InStr(PostType, "ErrorLoggingTextFile")){ if(InStr(PostType, "ErrorLoggingTextFile")){
Func_LogErrorsToTextFile(Message) Func_LogErrorsToTextFile(Message)
} }
if(InStr(PostType, "ErrorSummaryVar")){ if(InStr(PostType, "ErrorSummaryVar")){
Func_LogErrorsToVar(Message) Func_LogErrorsToVar(Message)
} }
if(InStr(PostType, "DiscordErrorLogging")){ if(InStr(PostType, "DiscordErrorLogging")){
PostToDiscordChannel(Message,DiscordErrorLoggingWebhookBotURL) PostToDiscordChannel(Message,DiscordErrorLoggingWebhookBotURL)
} }
if(InStr(PostType, "DiscordVideos")){ if(InStr(PostType, "DiscordVideos")){
Message := MessageBU Message := MessageBU
PostToDiscordChannel(Message,DiscordVideosWebhookURL) PostToDiscordChannel(Message,DiscordVideosWebhookURL)
} }
if(InStr(PostType, "DiscordParler")){ if(InStr(PostType, "DiscordParler")){
Message := MessageBU Message := MessageBU
PostToDiscordChannel(Message,DiscordParlerWebhookURL) PostToDiscordChannel(Message,DiscordParlerWebhookURL)
} }
} }
; -------------------------------/SaveOrPostProgress------------------------------- ; -------------------------------/SaveOrPostProgress-------------------------------
TakeScreenshotOfPage(SaveFilepath := ""){ TakeScreenshotOfPage(SaveFilepath := ""){
if(!ScreenshotResult) if(!ScreenshotResult)
return return
TooltipThis("Sleeping 5 Seconds Before Taking Screenshot") TooltipThis("Sleeping 5 Seconds Before Taking Screenshot")
; 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.
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory ; Take a screenshot of the page and save it.
savepath = %SaveFilepath%\%TodayDate%.jpg FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
; Msgbox % "savepath: " savepath
try driver.TakeScreenshot().SaveAs(savepath)
; ScreenshotsTaken := 1 ; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
savepath = %SaveFilepath%\%TodayDate%.jpg
; Msgbox % "savepath: " savepath
try driver.TakeScreenshot().SaveAs(savepath)
; ScreenshotsTaken := 1
} }
@ -896,448 +892,448 @@ if(TotalTabsFound = 1){
; Msgbox % "A_index: " A_index ; Msgbox % "A_index: " A_index
; DevModeMsgBox("breaking early on loop 1?") ; DevModeMsgBox("breaking early on loop 1?")
break break
} ; if there is only 1 tab, then break out of loop and don't bother looping through same tab ; if there is only 1 tab, then break out of loop and don't bother looping through same tab
}
*/ */
try driver.SwitchToNextWindow ;Focuses Selenium on the newly opened/next window. try driver.SwitchToNextWindow ;Focuses Selenium on the newly opened/next window.
} ; end of loop ; end of loop
}
; Iterate from 1 to the end of the array:
Loop % DriverURLArray.Length()
{
ARRAYNAMEList .= DriverURLArray[A_Index] . "`n"
; ArrayItem := DriverURLArray[A_Index]
; MsgBox % DriverURLArray[A_Index]
}
; Msgbox % "ARRAYNAMEList: " ARRAYNAMEList
TimeToLoopThroughAllTabs := A_TickCount - StartTime
Message = Time to Loop through all tabs: %TimeToLoopThroughAllTabs%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(Message)
return
} ; /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
; Do an extra check in case the Open window is still open.
OpenWindowExist := WinExist("Open")
if(OpenWindowExist)
ControlSend, Edit1, {Enter}, Open
ToolTip,
}
; -------------------------------NavigateFromBaseURLTo------------------------------- ; Iterate from 1 to the end of the array:
NavigateFromBaseURLTo(URL){ Loop % DriverURLArray.Length()
if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect {
Status := CheckSeleniumDriver() ARRAYNAMEList .= DriverURLArray[A_Index] . "`n"
if(Status) ; ArrayItem := DriverURLArray[A_Index]
Return "Failed" ; MsgBox % DriverURLArray[A_Index]
CreateArrayOfTabs() ; store all open tabs to memory for later usage }
} ; Msgbox % "ARRAYNAMEList: " ARRAYNAMEList
TimeToLoopThroughAllTabs := A_TickCount - StartTime
Message = Time to Loop through all tabs: %TimeToLoopThroughAllTabs%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(Message)
return
; / 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
; Do an extra check in case the Open window is still open.
OpenWindowExist := WinExist("Open")
if(OpenWindowExist)
ControlSend, Edit1, {Enter}, Open
ToolTip,
}
if(ReuseTabs){ ; pull out base of URL and check if it's within the array of tabs ; -------------------------------NavigateFromBaseURLTo-------------------------------
URLBase := StrReplace(URL,"https://","") NavigateFromBaseURLTo(URL){
URLBase := StrSplit(URLBase, "/") if(!DriverStatus){ ; if not connected to selenium chrome, then re-connect
URLBase := URLBase[1] Status := CheckSeleniumDriver()
URLBase := StrReplace(URLBase, "www.","") if(Status)
} Return "Failed"
if(!HasSubstringVal(DriverURLArray, URLBase)) ; if base url is not in tab array, create new tab and push url to array CreateArrayOfTabs() ; store all open tabs to memory for later usage
{ }
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
sleep, 2000
}
; msgbox,
Message = Finding Tab
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
TabFoundSuccessfully := 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.","")
}
NumberOfTabLoops := DriverURLArray.Length() if(!HasSubstringVal(DriverURLArray, URLBase)) ; if base url is not in tab array, create new tab and push url to array
{
try, run "%ChromeFilepath%" "%URL%"
DriverURLArray.Push(URL) ; Append an item to the array
NewTabCreated := 1
sleep, 2000
}
; msgbox,
; NumberOfTabLoops := Driver.Windows.Count + 2 Message = Finding Tab
loop % NumberOfTabLoops { ; loop through tabs to find matching tab SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
try driver.SwitchToNextWindow()
; sleep, 1000 TabFoundSuccessfully :=
; msgbox, looping through tabs
try CurrentTabTitle := driver.window.title
; caused by tab being manually closed. Not sure if this is the only cause though. NumberOfTabLoops := DriverURLArray.Length()
if(CurrentTabTitle = "") {
Message = CurrentTabTitle: %CurrentTabTitle%
DevModeMsgBox(Message)
Message = CurrenttabURL: %CurrentTabURL% ; NumberOfTabLoops := Driver.Windows.Count + 2
DevModeMsgBox(Message) loop % NumberOfTabLoops { ; loop through tabs to find matching tab
try driver.SwitchToNextWindow()
; try driver.SwitchToNextWindow ; sleep, 1000
Continue ; msgbox, looping through tabs
} try CurrentTabTitle := driver.window.title
; caused by tab being manually closed. Not sure if this is the only cause though.
if(CurrentTabTitle = "") {
Message = CurrentTabTitle: %CurrentTabTitle%
DevModeMsgBox(Message)
try CurrentTabURL := driver.Url Message = CurrenttabURL: %CurrentTabURL%
DevModeMsgBox(Message)
if(InStr(CurrentTabURL, URLBase)){ ; try driver.SwitchToNextWindow
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase% Continue
TabFoundSuccessfully := 1 }
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
Break
}
}
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
; }
try CurrentTabURL := driver.Url
Return if(InStr(CurrentTabURL, URLBase)){
; msgbox, found it.`n%CurrentTabTitle% = %PageTitle%`n%CurrentTabURL% = %URLBase%
TabFoundSuccessfully := 1
; msgbox %CurrentTabTitle% = %PageTitle%
; msgbox %CurrentTabURL% = %URL%
Break
} }
; End of Function }
; -------------------------------/NavigateFromBaseURL-------------------------------
SaveDriverURL(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together if(!NewTabCreated){ ; if re-using a tab then we want to re-navigate to URL because it might be the wrong page
try LastWebsitePostURL := driver.URL 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
; }
; -------------------------------SChrome_Get------------------------------- Return
SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){ }
IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1") ; End of Function
if WinExist("ahk_exe Chrome.exe"){ ; -------------------------------/NavigateFromBaseURL-------------------------------
WinGet, pid, PID, ahk_exe chrome.exe
for item in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" pid "'"){
if RegExMatch(item.CommandLine, "i)--remote-debugging-port=\K\d+", port){
break
}
}
if (Port=""){
MsgBox, 36, ,Chrome Needs to be started in debugging mode in order for Autohotkey to connect to it.`nIs it ok to restart Chrome in debugmode to enable a connection?
IfMsgBox, Yes
{
Message = Restarting Chrome in Debug Mode
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
While(WinExist("ahk_exe chrome.exe")) { SaveDriverURL(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together
WinClose, ahk_exe chrome.exe try LastWebsitePostURL := driver.URL
} }
Process, WaitClose, chrome.exe
}
Else{
Msgbox, 4096, Error, Cannot connect to Chrome profile if it is Not running in debug mode. Script Terminating
ExitApp
; @todo: Make this error out to the script result screen
}
}
}
; ; yuriy's settings
; IniRead, ChromeFilepath, C:\Users\%A_username%\Documents\Autohotkey\Lib\ScriptSettings.ini, Selenium, %A_Computername%, %A_Space%
; ; Establish Variable with Filepath to be used throughout the script ; -------------------------------SChrome_Get-------------------------------
; if(ChromeFilepath = ""){ SChrome_Get(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")){ IP_Port_Nr := RegExReplace(IP_Port, ".*:(\d*)", "$1")
ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe if WinExist("ahk_exe Chrome.exe"){
} WinGet, pid, PID, ahk_exe chrome.exe
else if (FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")){ for item in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId='" pid "'"){
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe if RegExMatch(item.CommandLine, "i)--remote-debugging-port=\K\d+", port){
} break
}
}
if (Port=""){
MsgBox, 36, ,Chrome Needs to be started in debugging mode in order for Autohotkey to connect to it.`nIs it ok to restart Chrome in debugmode to enable a connection?
IfMsgBox, Yes
{
Message = Restarting Chrome in Debug Mode
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(ChromeFilepath = ""){ While(WinExist("ahk_exe chrome.exe")) {
Message = Failed to find chrome.exe in the usual locations. WinClose, ahk_exe chrome.exe
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
MsgBox 0x30, Error!, Unable to find Chrome.exe in the usual locations. `nScript Exiting.
ExitApp
} }
Process, WaitClose, chrome.exe
}
Else{
Msgbox, 4096, Error, Cannot connect to Chrome profile if it is Not running in debug mode. Script Terminating
ExitApp
; @todo: Make this error out to the script result screen
}
}
}
if(!winExist("ahk_exe chrome.exe")){ ; ; Establish Variable with Filepath to be used throughout the script
message = %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL% ; if(ChromeFilepath = ""){
Clipboard := Message if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")){
DevModeMsgBox(message) ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
run, %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL% }
} else if (FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")){
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
}
Driver := ComObjCreate("Selenium.ChromeDriver")
Driver.SetCapability("debuggerAddress", IP_Port)
try Driver.Start()
catch e {
ShowSeleniumErrorMsgbox() if(ChromeFilepath = ""){
Message = Failed to find chrome.exe in the usual locations.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
MsgBox 0x30, Error!, Unable to find Chrome.exe in the usual locations. `nScript Exiting.
ExitApp
}
} ; end of catch if(!winExist("ahk_exe chrome.exe")){
message = %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL%
Clipboard := Message
DevModeMsgBox(message)
run, %ChromeFilepath% --remote-debugging-port=%IP_Port_Nr% %URL%
}
; Save current chrome version to ini file Driver := ComObjCreate("Selenium.ChromeDriver")
return Driver Driver.SetCapability("debuggerAddress", IP_Port)
} try Driver.Start()
; -------------------------------/SChrome_Get------------------------------- catch e {
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
}
}
ShowSeleniumErrorMsgbox()
; -------------------------------HasVal------------------------------- } ; end of catch
; 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) ; Save current chrome version to ini file
{ return Driver
if !(IsObject(haystack)) || (haystack.Length() = 0) }
return 0 ; -------------------------------/SChrome_Get-------------------------------
for index, value in haystack
if (InStr(value, Needle)) ShowSeleniumErrorMsgbox(){
return index GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
return 0 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
; SubStr(String, StartingPos [, Length]) }
}
; InStr(value, Needle)
; -------------------------------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
}
; 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
If ( sFile = "" )
{ ; Deinit static variable
xDetails := ""
Return
}
fex := {}, _FileExt := ""
Loop, Files, % RTrim(sfile,"\*/."), DF ; -------------------------------FileXPro Get File Attributes-------------------------------
{ ;https://www.autohotkey.com/boards/viewtopic.php?t=59882
If not FileExist( sFile:=A_LoopFileLongPath )
{
Return
}
SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Local
Static xDetails
If ( p[p.length()] = "xInfo" ) ; Last parameter is xInfo If ( sFile = "" )
{ { ; Deinit static variable
p.Pop() ; Delete parameter xDetails := ""
fex.SetCapacity(11) ; Make room for Extra info Return
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 fex := {}, _FileExt := ""
{
Return
}
Loop, Files, % RTrim(sfile,"\*/."), DF
{
If not FileExist( sFile:=A_LoopFileLongPath )
{
Return
}
objShl := ComObjCreate("Shell.Application") SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv
objDir := objShl.NameSpace(_Dir)
objItm := objDir.ParseName(_FileExt)
If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable If ( p[p.length()] = "xInfo" ) ; Last parameter is xInfo
{ {
i:=-1, xDetails:={}, xDetails.SetCapacity(309) 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
}
While ( i++ < 309 ) If Not ( _FileExt ) ; Filepath not resolved
{ {
xDetails[ objDir.GetDetailsOf(0,i) ] := i Return
} }
xDetails.Delete("")
}
If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind objShl := ComObjCreate("Shell.Application")
{ objDir := objShl.NameSpace(_Dir)
Return objItm := objDir.ParseName(_FileExt)
}
i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11) If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable
{
i:=-1, xDetails:={}, xDetails.SetCapacity(309)
While ( i++ < nParams ) While ( i++ < 309 )
{ {
Prop := p[i] xDetails[ objDir.GetDetailsOf(0,i) ] := 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) xDetails.Delete("")
Return fex }
} ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind
{
Return
}
i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11)
While ( i++ < nParams )
{
Prop := p[i]
; GuiButtonIcon If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) )
;------------------------------------------------ {
GuiButtonIcon(Handle, File, Index := 1, Options := "") fex[Prop] := objItm.ExtendedProperty(Prop)
{ Continue
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 : If ( PropNum := xDetails[Prop] ) > -1
RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 : {
RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 : fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum)
RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 : Continue
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 ) fex.SetCapacity(-1)
NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height Return fex
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% ; GuiButtonIcon
return IL_Add( normal_il, File, Index ) ;------------------------------------------------
} 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 ; \GuiButtonIcon
;------------------------------------------------ ;------------------------------------------------
ToggleTestingMode(){ ToggleTestingMode(){
IniRead, TestingMode, Settings.ini, General, TestingMode, 0 IniRead, TestingMode, Settings.ini, General, TestingMode, 0
; Msgbox % "TestingMode: " TestingMode ; Msgbox % "TestingMode: " TestingMode
if(TestingMode) if(TestingMode)
IniWrite, 0, Settings.ini, General, TestingMode IniWrite, 0, Settings.ini, General, TestingMode
else, else,
IniWrite, 1, Settings.ini, General, TestingMode IniWrite, 1, Settings.ini, General, TestingMode
} }
ToggleManualSubmit(){ ToggleManualSubmit(){
IniRead, ManualSubmit, Settings.ini, General, ManualSubmit, 0 IniRead, ManualSubmit, Settings.ini, General, ManualSubmit, 0
; Msgbox % "TestingMode: " TestingMode ; Msgbox % "TestingMode: " TestingMode
if(ManualSubmit) if(ManualSubmit)
IniWrite, 0, Settings.ini, General, ManualSubmit IniWrite, 0, Settings.ini, General, ManualSubmit
else, else,
IniWrite, 1, Settings.ini, General, ManualSubmit IniWrite, 1, Settings.ini, General, ManualSubmit
} }
ToggleDevMode(){ ToggleDevMode(){
IniRead, DevMode, Settings.ini, General, DevMode, 0 IniRead, DevMode, Settings.ini, General, DevMode, 0
; Msgbox % "TestingMode: " TestingMode ; Msgbox % "TestingMode: " TestingMode
if(DevMode) if(DevMode)
IniWrite, 0, Settings.ini, General, DevMode IniWrite, 0, Settings.ini, General, DevMode
else, else,
IniWrite, 1, Settings.ini, General, DevMode IniWrite, 1, Settings.ini, General, DevMode
} }
FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones
/*\b Backspace /*\b Backspace
\f Form Feed \f Form Feed
\n New Line - done \n New Line - done

@ -33,7 +33,7 @@ Automated posting to the following social media platforms, utilizing either the
- Open Chrome and type in `about::version` into the URL bar. The very first line will tell you what Chrome version you have - Open Chrome and type in `about::version` into the URL bar. The very first line will tell you what Chrome version you have
- After downloading, extract “chromedriver_win32.zip” and move the extracted chromedriver.exe to: `C:\Program Files\SeleniumBasic\chromedriver.exe` - After downloading, extract “chromedriver_win32.zip” and move the extracted chromedriver.exe to: `C:\Program Files\SeleniumBasic\chromedriver.exe`
- NOTE: The chromedriver will need to be re-downloaded whenever Chrome updates to keep up with API changes - NOTE: The chromedriver will need to be re-downloaded whenever Chrome updates to keep up with API changes
4. [Download the latest .exe of the Poster] (https://git.zinchuk.xyz/yuriy/Freedomain-Social-Media-Poster/releases) 4. [Download the latest .exe of the Poster](https://git.zinchuk.xyz/yuriy/Freedomain-Social-Media-Poster/releases)
- When run, the poster will automatically create the folders and files it requires in the directory it's run from. - When run, the poster will automatically create the folders and files it requires in the directory it's run from.
# Settings.ini # Settings.ini
@ -57,3 +57,6 @@ TelegramBotChatID=Public Posts Bot Chat ID
Ive done my best to catch any possible errors that might pop up and write functionality to handle them. But If an error happens that i haven't written resolves for, it will pop up a message box that looks like this. Please send me a screenshot so I can write a patch for the bug. Ive done my best to catch any possible errors that might pop up and write functionality to handle them. But If an error happens that i haven't written resolves for, it will pop up a message box that looks like this. Please send me a screenshot so I can write a patch for the bug.
![Alt text](Assets/Screenshots/Error_Message_Example.png "Error Message") ![Alt text](Assets/Screenshots/Error_Message_Example.png "Error Message")
# Compiling .exe from source
- @todo
Loading…
Cancel
Save