#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn  ; Enable warnings to assist with detecting common errors.
#SingleInstance, Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, ToolTip, Screen
CoordMode, Mouse, Screen
FileEncoding, UTF-8-RAW ; Needed for special symbols that are used in video descritions
if(InStr(A_ScriptName, ".ahk")){
	Menu, Tray, Icon, %A_ScriptDir%\assets\FreedomainSMP.ico
}

/*IconLocation :
if(!FileExist())
FileInstall, %A_ScriptDir%\Lib\FreedomainShare_Scheduled.ico, Dest [, Flag (1 = overwrite)]

*/

ErrorLoggingDirectory = %1%
; Add menus to the toolbar icon

Menu, tray, NoStandard ; remove standard tray

Menu, Tray, Add, Exit, KillScript
Menu, Tray, Add, Pause, PauseScript
Menu, Tray, Add, Start New Post, ReloadScript
Menu, Tray, Add, Reload wLast Post, LoadLastPost
Menu, Tray, Default, Reload wLast Post


global ScriptName
global ScriptVersion
global FullScriptName


;---Notes/Extra Info/#Includes------------------------------------------------------
ScriptName = Freedomain Social Media Poster
ScriptVersion = 2.70
FullScriptName := ScriptName . " " .  ScriptVersion

changelog = 
(
	Fixed Locals Posting
	Fixed Gettr Posting
	Fixed Flote Posting
	Fixed MeWe Posting
	Fixed Minds Posting
	Fixed Steemit Posting
	Fixed LinkedIn Image Posting
	Removed Tumblr Support
	Removed Pintrest support
	)
Changelog := StrReplace(changelog, A_Tab, "")
Changelog := StrReplace(changelog, "`n", "--")



;---ToDo---
;------------------------------------------------
; Steemit not submitting
; linkedin image posting not working


; @todo: fix post scheduling - countdown not working 

; @todo: being called from video uploader, skip over locals if video uploaed there
; @todo: add testing mode functionality similiar to video uploader
; @todo: Add option to auto restart chrome in debug mode
; @todo: Add hashtags to LinkedIn
; @todo: add icons? maybe?
; @todo: finish adding functionality for checkboxes next to title
; @todo: Make website buttons activate tab for site
; @todo: make facebook button open tab for facebook

; @todo: Errorlog not getting appended to on > 1 run (ErrorLoggingFilePath) variable is missing somehwere
; @todo: add a progress of 5/10 to show
; @todo: start new post after update if description has no text in it when update run
; @todo: tags aren't saved with templates
; @todo: Add tags support on all sites that support it - ask stef is useful
; @todo: save post tags and title to teh same file as ini file instead of two files

; Misc info
;------------------------------------------------
; Parler has a 1k char limit


;---Global Variables---
;------------------------------------------------
global Driver
global DriverStatus
global CurrentSite
global DiscordParlerWebhookURL
global DiscordErrorLoggingWebhookBotURL
global TooltipXPosition
global ShowTooltipProgress
global ErrorLoggingDirectory
global ErrorLoggingFilePath
global StatusFileFilePath
global PostTitleFilePath
global PostBodyFilePath
global ErrorLogVar
global PostTitle
global PostBody
global PostTitleAndBody
global PostTags
global ImageAttachmentFilepath
global ReuseTabs 
global WindowTitle  ; Tab title of already existing window of each site
global PauseBetweenPosts ; pause for a couple of seconds between posts so user has a chance to visually see confirmation
global PauseTimeBetweenPosts
global TimeBetweenpostsInMiliseconds
global DevMode
global ScreenshotResult
global ScriptRunTime
global URLOfLastErrorPage

; Website Post Statuses
global Discord
global SubScribeStar
global Telegram
global Minds
global Gab
global Locals
global LinkedIn
global MeWe
global Twetch
global ThinkSpot
global Flote
global PocketNet
global parler
global Gettr
global steemit
; global Pintrest
; global Tumblr

; Check if Lib folder exists and create it if not
LibFolder := A_ScriptDir . "\Lib" 
ErrorLoggingFolder := A_ScriptDir . "\Lib\ErrorLogging" 
FileCreateDir, %ErrorLoggingFolder%

; Set filepaths for different files and folders
global SettingsIniFilepath
SettingsIniFilepath := A_ScriptDir . "\Settings.ini"

global ChangelogIniFilepath
ChangelogIniFilepath := A_ScriptDir . "\Lib\FreedomScriptsChangelogINI"

global ScriptSettingsSection
ScriptSettingsSection := "SocialMediaPoster"

;---General Info---
;------------------------------------------------
IniRead, TestingMode, %SettingsIniFilepath%, General, TestingMode, 0
IniRead, DevMode, %SettingsIniFilepath%, General, DevMode, 0
IniRead, ScreenshotResult, %SettingsIniFilepath%, General, ScreenshotResult, 0
IniRead, TelegramBotToken, %SettingsIniFilepath%, SocialMediaPoster, TelegramBotToken, %A_Space%
IniRead, TelegramBotChatID, %SettingsIniFilepath%, SocialMediaPoster, TelegramBotChatID, %A_Space%
IniRead, DiscordErrorLoggingWebhookBotURL, %SettingsIniFilepath%, SocialMediaPoster, DiscordErrorLoggingWebhookBotURL, %A_Space%
IniRead, DiscordParlerWebhookURL, %SettingsIniFilepath%, SocialMediaPoster, DiscordParlerWebhookURL, %A_Space%


;---Checkbox Settings---
;------------------------------------------------
IniRead, BoldTitleWAPI, %SettingsIniFilepath%, SocialMediaPoster, BoldTitleWAPI, 1
(BoldTitleWAPI)?(BoldTitleCheckStatus := 1) : (BoldTitleCheckStatus := 0)

IniRead, NewLineBetweenTitle, %SettingsIniFilepath%, SocialMediaPoster, NewLineBetweenTitle, 1
(NewLineBetweenTitle)?(SpaceBetweenTitleBodyCheckStatus := 1) : (SpaceBetweenTitleBodyCheckStatus := 0)


IniRead, ShowTooltipProgress, %SettingsIniFilepath%, SocialMediaPoster, ShowTooltipProgress, 1
(ShowTooltipProgress)?(ShowTooltipProgressCheckStatus := 1) : (ShowTooltipProgressCheckStatus := 0)

IniRead, ReuseTabs, %SettingsIniFilepath%, SocialMediaPoster, ReuseTabs, 1
(ReuseTabs)?(ReuseTabsCheckStatus := 1) : (ReuseTabsCheckStatus := 0)

IniRead, AutoUpdateCheck, %SettingsIniFilepath%, SocialMediaPoster, AutoUpdateCheck, 1
(AutoUpdateCheck)?(AutoUpdateCheckCheckStatus := 1) : (AutoUpdateCheckCheckStatus := 0)

IniRead, SaveTagsBetweenPosts, %SettingsIniFilepath%, SocialMediaPoster, SaveTagsBetweenPosts, 1
(SaveTagsBetweenPosts)?(SaveTagsBetweenPostsCheckStatus := 1) : (SaveTagsBetweenPostsCheckStatus := 0)
if(SaveTagsBetweenPosts)
IniRead, PostTags, %SettingsIniFilepath%, SocialMediaPoster, PostTags, %A_Space%

IniRead, PauseBetweenPosts, %SettingsIniFilepath%, SocialMediaPoster, PauseBetweenPosts, 0
(PauseBetweenPosts)?(PauseBetweenPostsCheckCheckStatus := 1) : (PauseBetweenPostsCheckCheckStatus := 0)
if(PauseBetweenPosts){
	IniRead, PauseTimeBetweenPosts, %SettingsIniFilepath%, SocialMediaPoster, PauseTimeBetweenPosts, 3
	TimeBetweenpostsInMiliseconds := PauseTimeBetweenPosts * 1000
}


IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, %A_Space%

IniRead, TotalPostsPosted, %SettingsIniFilepath%, %ScriptSettingsSection%, TotalPostsPosted,0
IniRead, TotalRunTime, %SettingsIniFilepath%, %ScriptSettingsSection%, TotalRunTime, 0

;---Auto Updater Settings---
;------------------------------------------------
; Misc Auto Update settings
global FreedomainProgramUpdaterFilepath
FreedomainProgramUpdaterFilepath := A_ScriptDir . "\Freedomain Program Updater.exe"

global FreedomainProgramUpdaterURL
FreedomainProgramUpdaterURL = https://freedomainplaylists.com/wp-content/FreedomainScripts/Freedomain`%20Program`%20Updater.exe

global FreedomScriptsChangelogURL
FreedomScriptsChangelogURL = https://freedomainplaylists.com/wp-content/FreedomainScripts/FreedomScriptsChangelogINI

global UpdateURL
UpdateURL = https://freedomainplaylists.com/wp-content/FreedomainScripts/Freedomain`%20Social`%20Media`%20Poster.exe

; Save filepath of the current script to %SettingsIniFilepath% so it can be read and used by the script updater
; Append informatio to ini files for Freedomain Program Updater
ProgramExeFilepath := A_ScriptFullPath
ProgramExeFilepath := StrReplace(ProgramExeFilepath, ".ahk", ".exe")
IniWrite, %ProgramExeFilepath%, %SettingsIniFilepath%, %ScriptSettingsSection%, Filepath
IniWrite, %ScriptVersion%, %SettingsIniFilepath%, %ScriptSettingsSection%, ScriptVersion



; Download Program Updater
if(!FileExist(FreedomainProgramUpdaterFilepath)){
	; TooltipThis("Downloading Program Updater")
	; UrlDownloadToFile, %FreedomainProgramUpdaterURL%, %FreedomainProgramUpdaterFilepath%
	; ToolTip
}



;---Load Settings From Previous Post---
;------------------------------------------------
if(ErrorLoggingDirectory = "LastPost"){
	IniRead, ErrorLoggingDirectory, %SettingsIniFilepath%, %ScriptSettingsSection%, LastPost, %A_Space%
}

if(StrLen(ErrorLoggingDirectory) > 5){ ; if argument was passed in, read contents from that directory
	SkipUpdateCheckThisRun := 1

	if(InStr(ErrorLoggingDirectory, "VideoLinks.ini")){ ;PASSED IN FROM VIDEO UPLOADER

		VideoLinksFilepath = %ErrorLoggingDirectory%

		SplitPath, VideoLinksFilepath, OutFileName, VideoLinksDir, OutExtension, OutNameNoExt, OutDrive
		PostTitleFilepath := VideoLinksDir . "\title.txt" 
		FileRead, PostTitle, %PostTitleFilepath%
		; Msgbox % "PostTitle: " PostTitle

		; Read the post body from the text file adn then
		; SPlit it and remove the repeating text bit at the bottom
		PostBodyFilepath := VideoLinksDir . "\body.txt" 
		FileRead, Postbody, %PostBodyFilepath%
		SplitText = Free Documentaries:
		Postbody := StrSplit(Postbody, SplitText)
		Postbody := Postbody[1]

		; Read post tags from text file
		PostTagsFilepath := VideoLinksDir . "\keywords.txt" 

		FileRead, PostTags, %PostTagsFilepath%
		; Msgbox % "PostTags: " PostTags


		; Read thumbnail filepath from video links file
		IniRead, ImageAttachmentFilepath, %ErrorLoggingDirectory%,Misc, VideoThumbFilepath, %A_Space%

		; Read video links from video links file
		IniRead, BitChuteURL, %ErrorLoggingDirectory%,URLs, BitChuteURL, %A_Space%
		IniRead, RumbleURL, %ErrorLoggingDirectory%,URLs, RumbleURL, %A_Space%
		IniRead, StreamanityURL, %ErrorLoggingDirectory%,URLs, StreamanityURL, %A_Space%
		; IniRead, BitChuteURL, %ErrorLoggingDirectory%,URLs, BitChuteURL, %A_Space%

		if(BitChuteURL = ""){
			if(RumbleURL != "")
			VideoURL := RumbleURL
			else, 
			VideoURL := StreamanityURL
		}
		else, 
		VideoURL := BitChuteURL
		; Append bitchute url to bottom of description
		PostBody := PostBody . "`n`n" . VideoURL

/*		Msgbox % "PostTitle: " PostTitle
		Msgbox % "PostBody: " PostBody

		*/
		Discord := 0
		Telegram := 0
	}
	else, { ; otherwise passed in from a previous run.

		StatusFileFilePath := ErrorLoggingDirectory . "\" . "PostStatus.ini"
		ErrorLoggingFilePath := ErrorLoggingDirectory . "\" . "ErrorLogging.txt"
		FileRead, PostTitle, %ErrorLoggingDirectory%\PostTitle.txt
		FileRead, PostBody, %ErrorLoggingDirectory%\PostBody.txt
		IniRead, PostTags, %StatusFileFilePath%, General, PostTags, %A_Space%
		IniRead, ImageAttachmentFilepath, %StatusFileFilePath%, General, ImageAttachmentFilepath, %A_Space%

		ReadWebsiteStatuses() ; Read .ini file of post statuses for each site
	}
}


; Set checked status for each checkbox depending on each website's status
(Discord != "")?(DiscordCheckStatus := 0) : (DiscordCheckStatus := 1 )
(SubScribeStar != "")?(SubScribeStarCheckStatus := 0) : (SubScribeStarCheckStatus := 1)
(Telegram != "")?(TelegramCheckStatus := 0) : (TelegramCheckStatus := 1)
(Minds != "")?(MindsCheckStatus := 0) : (MindsCheckStatus := 1)
(Gab != "")?(GabCheckStatus := 0) : (GabCheckStatus := 1)
(MeWe != "")?(MeWeCheckStatus := 0) : (MeWeCheckStatus := 1) ; UNCHECKED ALWAYS as of 2022/04/08
(Gettr != "")?(GettrCheckStatus := 0) : (GettrCheckStatus := 1)
(Steemit != "")?(SteemitCheckStatus := 0) : (SteemitCheckStatus := 1)
(Locals != "")?(LocalsCheckStatus := 0) : (LocalsCheckStatus := 1)
(LinkedIN != "")?(LinkedINCheckStatus := 0) : (LinkedINCheckStatus := 1)
(Twetch != "")?(TwetchCheckStatus := 0) : (TwetchCheckStatus := 1)
(ThinkSpot != "")?(ThinkSpotCheckStatus := 0) : (ThinkSpotCheckStatus := 1)
(Flote != "")?(FloteCheckStatus := 0) : (FloteCheckStatus := 1)
; (Pintrest != "")?(PintrestCheckStatus := 0) : (PintrestCheckStatus := 1)
(Parler != "")?(ParlerCheckStatus := 0) : (ParlerCheckStatus := 1)
(PocketNet != "")?(PocketNetCheckStatus := 0) : (PocketNetCheckStatus := 1)
; (Tumblr != "")?(TumblrCheckStatus := 0) : (TumblrCheckStatus := 1)



if(TestingMode){ ; Easy testing for Yuriy
	DiscordCheckStatus := 0
	TelegramCheckStatus := 0
	SubScribeStarCheckStatus := 0
	MindsCheckStatus := 0
	LocalsCheckStatus := 0
	GettrCheckStatus := 0
	SteemitCheckStatus := 0
	GabCheckStatus := 0
	LinkedINCheckStatus := 0
	MeWeCheckStatus := 0
	TwetchCheckStatus := 0
	ThinkSpotCheckStatus := 0
	FloteCheckStatus := 0
	; PintrestCheckStatus := 0
	ParlerCheckStatus := 0
	PocketNetCheckStatus := 0
	; TumblrCheckStatus := 0
	; PocketNetCheckStatus := 0

}


;---GUI Variables---
;------------------------------------------------
TooltipXPosition := Round((A_ScreenWidth / 2) - (A_ScreenWidth / 10)) ; Center Tooltip on the screen and a bit to the left

GuiWidth := 950
TemplatesGroupBoxWidth := 700
MarginSpace = 10
MarginSpaceDoubled := MarginSpace * 2
EditBoxWidth := 700
EditBoxHalfWidths := EditBoxWidth / 2 - (MarginSpace * 1.7)
EditBoxThirdsWidth := EditBoxWidth / 3 - (MarginSpace * 1.5)
GroupBox_PlatformsWidth := 180
ImageSelectionButtonWidth := 100
ImageFilepathEditBoxWidth := EditBoxWidth - ImageSelectionButtonWidth - MarginSpace
SelectFileButtonWidth := 50
SelectFileButtonXPos := EditBoxWidth - SelectFileButtonWidth - MarginSpace
CharCountXPos := EditBoxWidth - 20
; FilePathEditBoxWidth := EditBoxWidth - SelectFileButtonWidth - MarginSpace

PlatformsGroupBoxXLocation := EditBoxWidth + (MarginSpace * 3)
; SettingsGroupBoxXLocation := PlatformsGroupBoxXLocation + ActionButtonWidths
SettingsGroupBoxXLocation := PlatformsGroupBoxXLocation + GroupBox_PlatformsWidth
ActionButtonWidths := 355

ActionButtonHalfWidths := (ActionButtonWidths / 2) - (MarginSpace / 2)

Gui, Margin, %MarginSpace%, %MarginSpace%
GUINormalFontSize := 15


Gui, Font, s10
; Gui, Font, s8
if(TestingMode){
	Gui, Add, Text,cRed yp+0 x%MarginSpace% ,TESTING MODE
}
if(DevMode){
	Gui, Add, Text,cRed yp+0 x+30 ,DEV MODE
}


Gui, Font, s%GUINormalFontSize%
Gui, Font, Bold
Gui, Add, Text, x%Marginspace% y+5 w%EditBoxWidth%, Post Title
Gui, Font, s8
Gui, Add, Checkbox, xp+120 yp+10 vBoldTitleWAPI Checked%BoldTitleCheckStatus% gUpdateVars,Bold Title on Discord/Telegram
Gui, Add, Checkbox, xp+220 yp+0 vNewLineBetweenTitle Checked%SpaceBetweenTitleBodyCheckStatus% gUpdateVars,Blank Line Between Title+Body
Gui, Font, Normal
Gui, Font, s%GUINormalFontSize% 
Gui, Add, Edit, x%MarginSpace% y+3 w%EditBoxWidth% vPostTitle gUpdateCharCount h75, %PostTitle%

Gui, Font, Bold
Gui, Add, Text,w%EditBoxWidth%, Post Body 
Gui, Font, Normal


Gui, Font, s%GUINormalFontSize%
Gui, Add, Edit, x%MarginSpace% y+2 w%EditBoxWidth% h150 vPostBody gUpdateCharCount, %PostBody%

; Gui, font, color, cblack


Gui, Font, s%GUINormalFontSize%
Gui, Font, Bold
Gui, Add, Text, x%marginspace% y+%MarginSpace% w%EditBoxWidth% ,Tags 

Gui, Font, s7
Gui, Font, Normal
; Gui, font, color, cRed
Gui, Add, Edit,yp-5 x%CharCountXPos% w30 vCharCount,

Gui, Font, s%GUINormalFontSize%
Gui, Font, Normal
Gui, Add, Edit, x%MarginSpace% y+10 vPostTags gUpdateVars h33 w%EditBoxWidth%, %PostTags%

Gui, Font, s%GUINormalFontSize%
Gui, Font, Bold
Gui, Add, Text,x%marginspace% w%EditBoxWidth%, Image Attachment Filepath
Gui, Font, Normal
Gui, Add, Edit, x%MarginSpace% y+2 vImageAttachmentFilepath gUpdateVars h33 w%ImageFilepathEditBoxWidth%, %ImageAttachmentFilepath%
Gui, Add, Button, gSelectFilepath w%ImageSelectionButtonWidth% x+M yp+0 h33, Select

Gui, Font, Bold
Gui, Add, GroupBox,r2.5 x%MarginSpace% y+15 Center w%TemplatesGroupBoxWidth%, Other
Gui, Font, Normal
Gui, Add, Button,xp+%Marginspace% yp+35 w%EditBoxThirdsWidth% h30 gSaveAsTemplate, Save As Template
Gui, Add, Button,x+%MarginSpace% w%EditBoxThirdsWidth% h30 gLoadTemplate, Load Template
Gui, Add, Button, x+%MarginSpace% w%EditBoxThirdsWidth% h30 gLoadLastPost, Load Last Post
if(UpdateAvailable)
Gui, Add, Button, x%MarginSpaceDoubled% y+%MarginSpace% w%EditBoxHalfWidths% h30 gUpdateScript vUpdateAvailable, Update Available - Click to Install
else,
Gui, Add, Button, x%MarginSpaceDoubled% y+%MarginSpace% w%EditBoxHalfWidths% h30 gUpdateScript vUpdateAvailable, Program is Up-to-Date


Gui, Add, Button,x+%MarginSpace% yp+0 w%EditBoxHalfWidths% h30 gCancelPost, Close Window
if(DevMode){
	Gui, Add, Button, x%MarginSpace% y+10 w%EditBoxThirdsWidth% h30 gToggleTestingMode, TestingModeToggle
	; Gui, Add, Button, x+%marginspace% w%EditBoxThirdsWidth% h30 gToggleTestingMode, TestingModeToggle
	Gui, Add, Button, x+%marginspace% w%EditBoxThirdsWidth% h30 gCompileScript, Compile
	Gui, Add, Button, x+%marginspace% w%EditBoxThirdsWidth% h30 gUploadFiles, UploadWinscp
	Gui, Add, Button, x%MarginSpace% y+10 w%EditBoxThirdsWidth% h30 gOpenErrorLog, OpenErrorLog

}


; Gui, Add, Checkbox, vTakeScreenshotsOfErrors Checked gUpdateVars, Take Screenshots of Errors
; Gui, Add, Checkbox, vTakeScreenshotsOfErrors Checked%ScreenshotsOfErrorsCheckStatus% gUpdateVars, Take Screenshots of Errors
; TakeScreenshotsOfErrors := 0

; Gui, Add, Checkbox,  vShowChangelog, Show `nChangelog (WIP)


Gui, Font, Normal
gui, Font, s5
; Miscellaneous Settings
DevModToggleButton := PlatformsGroupBoxXLocation + 130
Gui, Add, Button,  x%DevModToggleButton% y5 w50 h10 gToggleDevMode, DevMode
Gui, Add, Button,  x+5 yp+0 w50 h10 gToggleTestingMode, Testing Mode
Gui, Add, Button,  x+5 yp+0 w50 h10 gToggleManualSubmit, Manual Submit



Gui, Font, Bold
Gui, Font, s%GUINormalFontSize%
Gui, Add, GroupBox,r4 x%PlatformsGroupBoxXLocation% y%MarginSpace% w300, Settings
Gui, Font, s11
Gui, Font, Normal
Gui, Add, Checkbox, xp+10 yp+25 vReuseTabs Checked%ReuseTabsCheckStatus% gUpdateVars, Try to Re-Use Tabs
; Gui, Add, Checkbox, vNewChromeWindow Checked%AutoUpdateCheckCheckStatus% gUpdateVars, Create New Chrome Window (WIP)
Gui, Add, Checkbox,vShowTooltipProgress Checked%ShowTooltipProgressCheckStatus% gUpdateVars, Show Tooltip of Progress
Gui, Add, Checkbox, vAutoUpdateCheck Checked%AutoUpdateCheckCheckStatus% gUpdateVars, Auto Update Check
Gui, Add, Checkbox, vSaveTagsBetweenPosts Checked%SaveTagsBetweenPostsCheckStatus% gUpdateVars, Save Tags Between Posts
Gui, Add, Checkbox, vPauseBetweenPosts Checked%PauseBetweenPostsCheckCheckStatus% gUpdateVars, Pause Briefly Between Posts
; Gui, Add, Checkbox, vAutoRestartChromeDebug Checked%PauseBetweenPostsCheckCheckStatus% gUpdateVars, Auto Restart Chrome in Debug Mode
Gui, Font, s%GUINormalFontSize%





Gui, Font, Bold
Gui, Add, GroupBox,r8 x%PlatformsGroupBoxXLocation% y185 w300, Platforms
Gui, Font, Normal
Gui, Add, Checkbox, xp+10 yp+30 vDiscord Checked%DiscordCheckStatus% gUpdateVars, Discord
Gui, Add, Checkbox, y+7 vTelegram Checked%TelegramCheckStatus% gUpdateVars, Telegram
Gui, Add, Checkbox, y+7 vSubscribeStar Checked%SubScribeStarCheckStatus%gUpdateVars, SubscribeStar
Gui, Add, Checkbox, y+7 vMinds Checked%MindsCheckStatus% gUpdateVars, Minds
Gui, Add, Checkbox, y+7 vGab Checked%GabCheckStatus% gUpdateVars, Gab
Gui, Add, Checkbox, y+7 vLocals Checked%LocalsCheckStatus% gUpdateVars, Locals
Gui, Add, Checkbox, y+7 vTwetch Checked%TwetchCheckStatus% gUpdateVars, Twetch


; Second Row
; Gui, Add, Checkbox, vLinkedIn Checked%LinkedINCheckStatus% gUpdateVars, LinkedIn
Gui, Add, Checkbox, x+60 yp-185 vMeWe Checked%MeWeCheckStatus% gUpdateVars, MeWe
Gui, Add, Checkbox, y+7 vLinkedIn Checked%LinkedINCheckStatus% gUpdateVars, LinkedIn
Gui, Add, Checkbox, y+7 vThinkspot Checked%ThinkSpotCheckStatus% gUpdateVars, Thinkspot
Gui, Add, Checkbox, y+7 vFlote Checked%FloteCheckStatus% gUpdateVars, Flote
Gui, Add, Checkbox, y+7 vParler Checked%ParlerCheckStatus% gUpdateVars, Parler
Gui, Add, Checkbox, y+7 vSteemit Checked%SteemitCheckStatus% gUpdateVars, Steemit
; Gui, Add, Checkbox, y+7 vPintrest Checked%PintrestCheckStatus% gUpdateVars, Pintrest
Gui, Add, Checkbox, y+7 vPocketNet Checked%PocketNetCheckStatus% , Bastyon
; Gui, Add, Checkbox, y+7 vTumblr Checked%TumblrCheckStatus% , Tumblr
Gui, Add, Checkbox, y+7 vGettr Checked%GettrCheckStatus% gUpdateVars, Gettr


Gui, Font, Bold
gui, Font, s12
; : Gui, Add, Text, , My Text.
; Gui, Font, Color, Red
Gui, Add, Button, x%PlatformsGroupBoxXLocation% y+65 w300 h50 gPostPost, Post!

Gui, Add, Button, x%PlatformsGroupBoxXLocation% y+20 w300 h30 gSchedulePost, Schedule Post


; Gui, Font, s%GUINormalFontSize%
gui, font, s6
Gui, Add, StatusBar,, Total Posts Posted: %TotalPostsPosted% | Total Run Time: %TotalRunTime% Seconds |

Gui, Show,,%FullScriptName% ; ,w%GuiWidth%, %ScriptName% 
ControlFocus, Edit1, %FullScriptName%

;---Check for Update---
;------------------------------------------------
if(AutoUpdateCheck AND !UpdateAvailable AND !SkipUpdateCheckThisRun){ 
	CheckForUpdates()
}
Return





;---Misc GoSubs---
;------------------------------------------------
SaveAsTemplate:
TemplateDirectory = %A_ScriptDir%\Lib\Templates
if(!FileExist(TemplateDirectory)){
	FileCreateDir, %TemplateDirectory%
}

InputBox, TemplateName, Input Name, Please Input Name for the Template:
if(ErrorLevel)
Return

TemplateDirectory = %A_ScriptDir%\Lib\Templates\%TemplateName%
CreateErrorLoggingFiles(TemplateDirectory)

FileAppend, %PostTitle%, %PostTitleFilePath% ; save post content to txt file
FileAppend, %PostBody%, %PostBodyFilePath% ; save post content to txt file

IniWrite, %ImageAttachmentFilepath%, %StatusFileFilePath%, General, ImageAttachmentFilepath
IniWrite, %PostTags%, %StatusFileFilePath%, General, PostTags
Return


LoadTemplate:
Message = Loading Template
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,DiscordErrorLogging")

ErrorLoggingDirectory = %A_ScriptDir%\Lib\Templates\
FileSelectFolder, ErrorLoggingDirectory, %ErrorLoggingDirectory%
; FileSelectFolder, OutputVar [, *StartingFolder, Options, Prompt]
if(ErrorLevel){
	Tooltip
	Return

}

run, "%A_ScriptFullPath%" "%ErrorLoggingDirectory%"
ExitApp

ReloadScript:
Reload
Return

KillScript:
ExitApp
Return

PauseScript:
Pause, Toggle
Return


LoadLastPost:
; IniWrite, %ErrorLoggingDirectory%, %SettingsIniFilepath%, SocialMediaPoster, LastPost
; IniRead, ErrorLoggingDirectory, %SettingsIniFilepath%, %ScriptSettingsSection%, LastPost, %A_Space%
; Msgbox % "SettingsIniFilepath: " SettingsIniFilepath
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
; msgbox, 4096, Sorry, Sorry this doesn't do anything yet.
run, "%A_ScriptFullPath%" "LastPost"
ExitApp




UpdateScript:
UpdateScript()
Return

CancelPost:
GuiClose:
; ExitApp
Gui, Submit,
Return

OpenErrorLog:
run, %ErrorLoggingDirectory%
Return

ToggleTestingMode:
ToggleTestingMode()
run, %A_ScriptFullPath% "LastPost"
Return

ToggleManualSubmit:
ToggleManualSubmit()
run, %A_ScriptFullPath% "LastPost"
Return

ToggleDevMode:
ToggleDevMode()
run, "%A_ScriptFullPath%" "LastPost"
Return

CompileScript:
; msgbox, compiling
IniWrite, %changelog%, %ChangelogIniFilepath%, %ScriptSettingsSection%, Changelog
IniWrite, %ScriptVersion%, %ChangelogIniFilepath%, %ScriptSettingsSection%, ScriptVersion
IniWrite, %UpdateURL%, %ChangelogIniFilepath%, %ScriptSettingsSection%, UpdateURL

run, "%A_scriptdir%\Lib\Releases\Compile Scripts to EXE.ahk" SocialMediaPoster Production
; ExitApp
Return

UploadFiles:
msgbox, this button needs to be re-programmed. Search for "UploadFiles:" in main program
Return

SelectFilepath:
FileSelectFile, SelectedImageFilepath
GuiControl,, ImageAttachmentFilepath, %SelectedImageFilepath%
Return

UpdateVars: 
Gui, Submit, NoHide
Return

UpdateCharCount:
Gui, Submit, NoHide
Count := StrLen(PostBody)

/*if(Count > 256){
	GuiControl,, Twetch, 0

}
*/

GuiControl,, CharCount, %Count%
Return



TryFailedAgain:
; msgbox %ErrorLoggingDirectory%
run, %A_ScriptFullPath% "LastPost"
ExitApp
; Return

SchedulePost:
ScheduledPost := 1
Gui, Submit
Gui, Destroy

Gui, Font, Normal
Gui, Font, s20
Gui, Add, Text, Center w350 x%marginspace%,Time to Post At
Gui, Add, DateTime, x%marginspace% vScheduledTime gUpdateVars w350, hh:mm tt 
Gui, Font, s8
Gui, Add, Checkbox, vDisplayCountdownTooltip gUpdateVars checked, Display Tooltip with Countdown
Gui, Font, s20
Gui, Add, Button,gPostPost w350, Schedule Post Time
gui, show, w370
Return



PostPost:
Gui, Submit

; Msgbox % "PostTags: " PostTags

if(InStr(PostTags, "http")){
	Message = Post Tags contain "http". Please edit and remove the url and try again.
	Msgbox, 4096, Error, %Message%
	; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
	Return
}


Gui, Destroy

; 20211023061711
ScheduledTime := SubStr(ScheduledTime, 1, 12) ; pull out time date up to the minute and exclude seconds
; Msgbox % "ScheduledTime: " ScheduledTime
; clipboard := ScheduledTime
; Msgbox % "ScheduledTime: " ScheduledTime

; DevModeMsgBox("stop")

; if argument is passed to the script we want to do the following: 
; If the argument is a template post, we want to create a new ErrorLogging directory for it
; if the argument is an error logging post, we want to continue where it left off and log to the same place


; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
if(InStr(ErrorLoggingDirectory, "\Templates\") OR ErrorLoggingDirectory = "" OR InStr(ErrorLoggingDirectory, "VideoLinks.ini")){
	; msgbox, creating new error logging files
	CreateErrorLoggingFiles()

} ; 

; Msgbox % "SaveTagsBetweenPosts: "the SaveTagsBetweenPosts

; Msgbox % "TakeScreenshotsOfErrors: " TakeScreenshotsOfErrors
; Save settings to .ini file
; SaveSettingsToIniFile(SettingName)


IniWrite, %BoldTitleWAPI%, %SettingsIniFilepath%, SocialMediaPoster, BoldTitleWAPI
IniWrite, %NewLineBetweenTitle%, %SettingsIniFilepath%, SocialMediaPoster, NewLineBetweenTitle
IniWrite, %ReuseTabs%, %SettingsIniFilepath%, SocialMediaPoster, ReuseTabs
IniWrite, %ShowTooltipProgress%, %SettingsIniFilepath%, SocialMediaPoster, ShowTooltipProgress
IniWrite, %AutoUpdateCheck%, %SettingsIniFilepath%, SocialMediaPoster, AutoUpdateCheck
IniWrite, %SaveTagsBetweenPosts%, %SettingsIniFilepath%, SocialMediaPoster, SaveTagsBetweenPosts
IniWrite, %PauseBetweenPosts%, %SettingsIniFilepath%, SocialMediaPoster, PauseBetweenPosts
; IniWrite, %TakeScreenshotsOfErrors%, %SettingsIniFilepath%, SocialMediaPoster, TakeScreenshotsOfErrors
IniWrite, %ErrorLoggingDirectory%, %SettingsIniFilepath%, %ScriptSettingsSection%, LastPost



; Combines two variables together so they can be used as needed later
if(NewLineBetweenTitle)
PostTitleAndBody := PostTitle . "`n`n" . PostBody
else, 
PostTitleAndBody := PostTitle . "`n" . PostBody


if(PostBody = ""){
	PostTitleAndBody := PostTitle
}
if(PostTitle = ""){
	PostTitleAndBody := PostBody

}

; Format text to javascript
JSPostTitleAndBody := FormatTextToJSText(PostTitleAndBody)
JSPostTitle := FormatTextToJSText(PostTitle)
JSPostBody := FormatTextToJSText(PostBody)

FileAppend, %PostTitle%, %PostTitleFilePath% ; save post content to txt file
FileAppend, %PostBody%, %PostBodyFilePath% ; save post content to txt file
IniWrite, %ImageAttachmentFilepath%, %StatusFileFilePath%, General, ImageAttachmentFilepath

IniWrite, %PostTags%, %StatusFileFilePath%, General, PostTags
IniWrite, %PostTags%, %SettingsIniFilepath%, SocialMediaPoster, PostTags
IniWrite, %ShowTooltipProgress%, %SettingsIniFilepath%, SocialMediaPoster, ShowTooltipProgress

; TimeBetweenPosts := 5000 ; 5 seconds
; TimeBetweenpostsInSeconds := round(TimeBetweenPosts/1000)
; Msgbox % "TimeBetweenpostsInSeconds: " TimeBetweenpostsInSeconds


; Create a list of websites that are going to get psoted to for error logging purposes
(Discord = 1)?(PostedWebsites .= "Discord|") : ()
(Telegram = 1)?(PostedWebsites .= "Telegram|") : ()
(SubScribeStar = 1)?(PostedWebsites .= "SubScribeStar|") : ()
(Minds = 1)?(PostedWebsites .= "Minds|") : ()
(Gab = 1)?(PostedWebsites .= "Gab|") : ()
(MeWe = 1)?(PostedWebsites .= "MeWe|") : ()
(Locals = 1)?(PostedWebsites .= "Locals|") : ()
(LinkedIn = 1)?(PostedWebsites .= "LinkedIn|") : ()
(Twetch = 1)?(PostedWebsites .= "Twetch|") : ()
(ThinkSpot = 1)?(PostedWebsites .= "ThinkSpot|") : ()
(Flote = 1)?(PostedWebsites .= "Flote|") : ()
(PocketNet = 1)?(PostedWebsites .= "PocketNet|") : ()
(Gettr = 1)?(PostedWebsites .= "Gettr|") : ()
(Parler = 1)?(PostedWebsites .= "Parler|") : ()
(Steemit = 1)?(PostedWebsites .= "Steemit|") : ()
(Pintrest = 1)?(PostedWebsites .= "Pintrest|") : ()
(Tumblr = 1)?(PostedWebsites .= "Tumblr|") : ()

Message = Starting SMP with: **V%ScriptVersion%** `nTo sites: %PostedWebsites% `nWith Title: **%PostTitle%** `nWith Body:%PostBody% `nWith Tags: %PostTags%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")



if(InStr(PostBody, "www.dlive.tv") AND !InStr(PostBody, "https://www.dlive.tv")){ ; if posting Dlive link, turn it into hyperlink
	PostBody := StrReplace(PostBody, "www.dlive.tv", "https://www.dlive.tv")
}




; Msgbox % "PostTitleAndBody: " PostTitleAndBody
; 20211023060415
if(ScheduledPost){
	; CheckSeleniumDriver()
	; Menu, Tray, Icon, %A_ScriptDir%\Lib\FreedomainShare_Scheduled.ico
	Loop, {
		FormatTime, CurrentTime, YYYYMMDDHH24MISS, yyyyMMddhhmm
		; FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss 

		EnvSub, CurrentTime, ScheduledTime, Minutes
		TimeLeft := StrReplace(CurrentTime, "-", "")

		if(TimeLeft = 0)
		break

		if(DisplayCountdownTooltip){
			Message = Minutes Until SMP: %TimeLeft%
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
		}

		sleep, 15000 ; 15 seconds
	}
}



StartTime := A_TickCount



if(Discord)
Gosub, PostToDiscord
if(Telegram) 
Gosub, PostToTelegram
if(Parler)
Gosub, PostToParler
if(SubscribeStar)
Gosub, PostToSubscribeStar
if(Minds) 
Gosub, PostToMinds
if(Gab)
Gosub, PostToGab
if(LinkedIN)
Gosub, PostToLinkedIN
if(MeWe)
Gosub, PostToMeWe
if(Twetch)
Gosub, PostToTwetch
if(Thinkspot)
Gosub, PostToThinkSpot
if(Flote)
Gosub, PostToFlote
if(Locals)
Gosub, PostToLocals
/*if(Parler)
Gosub, PostToParler
if(Facebook)
Gosub, PostToFacebook
*/
if(Steemit)
Gosub, PostToSteemit
if(Pintrest)
Gosub, PostToPintrest
if(Pocketnet)
Gosub, PostToPocketNet
if(Gettr)
Gosub, PostToGettr
; if(Tumblr)
; Gosub, PostToTumblr


CurrentSite := 
Message = Social Media Posting Complete
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

ScriptRunTime := round(((A_TickCount - StartTime) / 1000), 2)


; DevModeMsgBox(URLOfLastErrorPage)

if(URLOfLastErrorPage != ""){
	Message = Activating Tab of last failed post.
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
; DevModeMsgBox("pause")
	; message = URLOfLastErrorPage: %URLOfLastErrorPage%
	; DevModeMsgBox(URLOfLastErrorPage)
	FindAndActivateTab(URLOfLastErrorPage)
}



ReadWebsiteStatuses() ; Read .ini file of post statuses for each site

; Gui,Destroy
ToolTip

WebsiteButtonWidths = 115
WebsiteStatusEditWidths = 150

StatusTextWidth := (WebsiteButtonWidths + WebsiteStatusEditWidths) * 2
StatusTextSecondRowXPos := WebsiteStatusEditWidths + WebsiteButtonWidths + (MarginSpace * 4)
ErrorSummaryLogXPos := StatusTextSecondRowXPos + WebsiteStatusEditWidths + WebsiteButtonWidths + (MarginSpace * 2)
ErrorSummaryLogSplitLineXPos := ErrorSummaryLogXPos - (MarginSpace)
ErrorLogSummaryWidth := 385
ErrorLogSummaryHeight := 480
ButtonHeights := 30




Gui, Font, s%GUINormalFontSize%
Gui, Font, Bold
Gui, Add, Text,w%StatusTextWidth% y%MarginSpace% Center, Status


Gui, Add, Button,x%MarginSpace% y40 w%WebsiteButtonWidths% Center h%ButtonHeights%, Discord
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%,  %Discord%


Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% Center h%ButtonHeights%, Telegram
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Telegram%

gui, font, s8
Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% Center h%ButtonHeights%, SubScribeStar
Gui, Font, s%GUINormalFontSize%
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %SubscribeStar%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Minds
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Minds%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Gab
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Gab%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Locals
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Locals%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Gettr
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Gettr%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths%Center h%ButtonHeights%, Twetch
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Twetch%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, LinkedIn
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %LinkedIn%

Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, MeWe
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %MeWe%


Gui, Font, s9
Gui, Add, Button, x%MarginSpace% y+20 w165 h50 gCancelPost, Close
Gui, Add, Button, x+%Marginspace% w215 h50 gSendErrorLoggingThroughTelegram, Telegram Detailed Errorlog
Gui, Add, Button, x+%Marginspace% h50 w165 gTryFailedAgain, Try Failed Again


Gui, Font, s%GUINormalFontSize%

gui, font, s8
Gui, Add, Button,x%StatusTextSecondRowXPos% y40 w%WebsiteButtonWidths%Center h%ButtonHeights%, ThinkSpot
Gui, Font, s%GUINormalFontSize%
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %ThinkSpot%

Gui, Font, s%GUINormalFontSize%

Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Flote
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Flote%

Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% gActivateParlerTab Center, Parler
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Parler%

Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Steemit
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Steemit%

; Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Pintrest
; Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Pintrest%

Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Bastyon
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %PocketNet%

; Gui, Add, Button,x%StatusTextSecondRowXPos% y+%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, Tumblr
; Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %Tumblr%

Gui, Font, s8
Gui, Add, Button, x%StatusTextSecondRowXPos% y+40 w270 h40 Center gCopyPostToClipboard, Copy Post To Clipboard `nFor Easy Pasting to Other Sites
Gui, Add, Button, x%StatusTextSecondRowXPos% y+%MarginSpace% w270 h40 Center gCopyImageFilepathToClipboard, Copy Image Filepath To Clipboard


/*Gui, Add, Button,x%MarginSpace% w%WebsiteButtonWidths% h%ButtonHeights% Center, PocketNet
Gui, Add, Edit, x+5 w%WebsiteStatusEditWidths% h%ButtonHeights%, %PocketNet%

*/
Gui, Font, s%GUINormalFontSize%
Gui, Font, Bold
; gui, add, text, x%ErrorSummaryLogSplitLineXPos% y20 h200 0x11 ; 0x11 is a "line"  ; refer to here: https://autohotkey.com/board/topic/50910-draw-line-gui/
Gui, Add, Text, x%ErrorSummaryLogXPos% y%MarginSpace% w%ErrorLogSummaryWidth% Center, Error Log Summary

Gui, Font, Normal
Gui, Font, s10
Gui, Add, Edit, x%ErrorSummaryLogXPos% y+%MarginSpace% w%ErrorLogSummaryWidth% h%ErrorLogSummaryHeight%, %ErrorLogVar%
Gui, Font, s%GUINormalFontSize%

gui, font, s6
Gui, Add, StatusBar,, Total Posts Posted: %TotalPostsPosted% | Run Time: %ScriptRunTime% Seconds

Gui, Show,, %FullScriptName% - Post Results


SaveCurrentChromeVersionToIniFile()
AddToTotalRunTime()

Return

ActivateParlerTab:
DevModeMsgBox("activating")
DevModeMsgBox(ParlerTabURL)
FindAndActivateTab(ParlerTabURL)

Return


SendErrorLoggingThroughTelegram:
Message = Uploading Errorlog to FDRBotTesting Telegram Server.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

; ErrorLoggingFilePath := VideoFolderDir . "\" . "ErrorLogging.txt"
; Msgbox % "ErrorLoggingFilePath: " ErrorLoggingFilePath

; Credentials to FDRBotTesting Channel
ELTelegramBotToken=1422687468:AAEzdzkck5PhgOG687cEn1cChp5cJFodjVM
ELTelegramBotChatID=-1001460795978

; DevModeMsgBox(ErrorLoggingFilePath)

Status := SendTelegramFile(ELTelegramBotToken, ELTelegramBotChatID, ErrorLoggingFilePath, caption := "" )
if(InStr(Status, "error_code")){
	Message = Telegram Post Failed due to an API Issue. Error was saved to ErrorLogging file. Please send it to Yuriy.
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")

	; SaveOrPostProgress(Message:=Status,PostType:=",ErrorLoggingTextFile")
	Message = Telegram Error: %Status%
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")

	; msgbox, 4096, Error!, %Message%
	ToolTip
	Return
}
ToolTip
Message = Errorlog was successfully uploaded to the FDRBotTesting Telegram Server.`nThank You!
msgbox, 4096, Success!, %Message%

; Clipboard := ErrorLoggingFilePath
; Message = %ErrorLoggingFilePath% `n`nwas copied to the clipboard for easy attachment
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; msgbox, 4096, Filepath Copied to Clipboard, %ErrorLoggingFilePath%`n`nwas copied to the clipboard for easy attachment.
Return 





CopyErrorLoggingFilepath:
; Msgbox % "ErrorLoggingFilePath: " ErrorLoggingFilePath
Clipboard := ErrorLoggingFilePath
msgbox,,Copied to Clipboard, The Filepath for the errorlogging file was copied to your clipboard:`n`n%ErrorLoggingFilePath%
Return

SaveDriverTitle(){
	Message := "Driver.Title: " .  driver.title
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}


CopyPostToClipboard:
clipboard := PostTitleAndBody
Message = Post Title and Body Copied to Clipboard
; ToolTip, Post Title and Body Copied to Clipboard, 850, 0
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
sleep, 2000
Tooltip
Return

CopyImageFilepathToClipboard:
clipboard := ImageAttachmentFilepath
Message = Image Filepath Copied to Clipboard
; ToolTip, Post Title and Body Copied to Clipboard, 850, 0
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
sleep, 2000
Tooltip
Return


OpenScreenshotsFolder:
run, %ErrorLoggingDirectory%
Return


PostScreenshotsToUploadStatus:
SaveOrPostProgress(Message:="Uploading screenshots of Errors:",PostType:=",ErrorLoggingTextFile,DiscordParler")


Loop, %NumOfScreenshots% {
	Filepath := ScreenshotFilepaths[A_index]	; find value from position in array
	UploadImageToDiscord(DiscordParlerWebhookURL,, Filepath)

}

Tooltip
Return


;---------------Facebook----------------------------------
PostToFacebook:
CurrentSite := "Facebook"

Message = Navigating to Post Creation Page
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

Status := NavigateFromBaseURLTo("https://www.facebook.com/")
if(Status){
	Message = Failed to Navigate to Feed Page
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}

sleep, 2000
js = document.querySelector("div[class='m9osqain a5q79mjw gy2v8mqq jm1wdb64 k4urcfbm qv66sw1b'] span[class='a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7']").click()

; js = document.querySelector('a[aria-label$="Timeline"] + div > div:nth-child(1)').click()
try driver.executeScript(js)

IniWrite, Incomplete, %StatusFileFilePath%, Status, Facebook
try Clipboard := PostTitleAndBody
SaveDriverURLOFErrorPage()

Return







; try html := driver.pagesource ; save page's entire HTML to a variable
; Clipboard := html
; Msgbox % "html: " html

; Pull out greeting message
/*GreetingMessage := StrSplit(HTML, "What's on your mind,")
GreetingMessage := GreetingMessage[2]
GreetingMessage := StrSplit(GreetingMessage, "</span>")
GreetingMessage := GreetingMessage[1]
GreetingMessage := "What's on your mind," . GreetingMessage
*/
; Msgbox % "GreetingMessage: " GreetingMessage

; //span[normalize-space()="What's on your mind, Yuriy?"]
; 

Message = Inputting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

; Msgbox % "Status: " Status
if(ImageAttachmentFilepath = "" AND Status){ ; upload a temporary file and then remove it and input psot
	Message = Inputting post using temporary image attachment workaround
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	Xpath = //div[@aria-label='Create a post']//div//input[@type='file']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=TemporaryImageFilepath)
	if(Status){
		Message = Post Failed: Check Login Status
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}
	; driver.FindElementByXPath(Xpath).SendKeys(TemporaryImageFilepath)

	sleep, 2000
	; remove attachment
	Xpath = //div[@aria-label='Remove post attachment']
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=3000)
	if(Status){
		Message = Upload Failed: Failed to remove temporary image.
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	; driver.FindElementByXPath(Xpath).click()


	Xpath = //span[normalize-space()="What's on your mind, Stefan?"]
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
	if(Status){
		Message = Failed to click with Relative Xpath
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

		; click on "what's on your mind text box"
		Xpath = //div[@aria-label='Create a post']//div[1]//div[1]//div[1]//span[1]
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to click "What's on your mind" box to input post with relative and direct xpath
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
			Return
		}
	}
	
}
if(ImageAttachmentFilepath != "") { ; otherwise send image straight to upload input box. The post box will open up automatically
	Message = Attaching Image
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	Xpath = //div[@aria-label='Create a post']//div//input[@type='file']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
	if(Status){
		Message = Post Failed: Check Login Status
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}
/*	; Attach image button
	Xpath = //div[@aria-label='Photo/Video']//div//div//div//div//div//i[@data-visualcompletion='css-img']
	Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
	if(Status){
		Message = Failed to click "Attach Image" button
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	; Input filepath of image/video
	Status := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
	if(Status)
	{
		Message = Upload Failed: Unable to Find "Open File" window to input Video filepath into
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	*/

	Message = Waiting 5 Seconds For Thumbnail Preview to Load
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
	; Wait for thumbnail to load
	sleep, 5000

}

Message = Posting Exited Early for Testing
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return

; Xpath = //div[@data-block='true']//div
Xpath = //div[@data-block='true']//div
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){
	Message = Failed to input Text Post message with Relative and direct Xpath
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}



IniWrite, Input - NOT Submitted, %StatusFileFilePath%, Status, Facebook
Message = Post Button Click Skipped. Please Double Check and Submit Post Manually
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
SaveDriverURLOFErrorPage()
Return



Message = Submitting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


; Click Post Button
xpath = //div[@aria-label='Post']//div//div//div//span[contains(text(),'Post')]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
	Message = Failed to click "Post" button
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

IniWrite, Successful, %StatusFileFilePath%, Status, Facebook

AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()
; ; sleep, %TimeBetweenPosts%
DevModeMsgBox("done!")

Return
;---------------/Facebook----------------------------------



; -------------------------------Parler-------------------------------
PostToParler:
CurrentSite := "Parler"

Message = Navigating to Post Creation Page
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


Status := NavigateFromBaseURLTo("https://parler.com")
if(Status){
	Message = Failed to Navigate to Feed Page
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}


; Check login status by checking the header of the page for "Feed" text
js = return document.querySelector(".header__contain").innerText
try status := driver.executeScript(js)
if(!InStr(status, "Feed")){
	; SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
	SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	; ParlerTabURL := 
	try ParlerTabURL := driver.URL
	SaveDriverURLOFErrorPage()
	Return
}


/*try CurrentTabURL := driver.Url
; Msgbox % "CurrentTabURL: " CurrentTabURL
if(InStr(CurrentTabURL, "/login")){
	SaveOrPostProgress(Message:="Cookies Expired. Trying to Log back in",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
	Xpath = //div[@class='form__contain']//button[@class='button'][normalize-space()='Log In']
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
	if(Status){
		SaveOrPostProgress(Message:="Failed to click login button",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
	}
	sleep, 1000
}

*/

; Message = Trying to click on "Parley.." to start new post
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip")

; sleep, 5000 ; sleep 2 seconds for page to fully load in case it's being slow

; js = document.getElementsByClassName('input-trigger')[0].click()
; try driver.executeScript(JS)			;Execute Javascript


 /*   ; if failed to click into box then error out
    if(Status){ 
    	Message = Post Failed: Page didn't load properly
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	SaveDriverURLOFErrorPage()
    	Return
    }

    */
    ; Msgbox % "Status: " Status

    Message = Inputting Post
    SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

/*    ; click into popup box
    xpath = //div[@placeholder='Parley...']
    Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=3,SleepLength:=1000)
    if(Status){
    	Message = Failed to click into Parler Post Box. Check Login Status
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	SaveDriverURLOFErrorPage()
    	Return
    }
    */

    ; Input post contents
    Xpath = //textarea[@placeholder='Write something...']
    Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
    if(Status){
    	Message = Failed to input post contents
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	SaveDriverURLOFErrorPage()
    	Return
    }



    ; Do a double check that post got input

    ; js = return document.querySelector("textarea[placeholder='Write something...']").textContent;
    ; try ParlerTextStatus := driver.executeScript(js) ;navigate using javascript 

    Xpath = //textarea[@placeholder='Write something...']
    try ParlerTextStatus := driver.findelementbyxpath(Xpath).Attribute("value") ;XPath: ID=site-title & span tag


    if(StrLen(ParlerTextStatus) < 5){
    	Message = Failed to input post contents. Post that got input: %ParlerTextStatus%
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	SaveDriverURLOFErrorPage()
    	Return
    }

    ; driver.FindElementByXPath(Xpath).SendKeys("heyyyy")



 /*   ; Input Post content pop up
    Xpath = //div[@id='create-parley-wysiwyg']
    Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
    if(Status){
    	Message = Failed to input Post Message with relative Xpath
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

    	; Input post with JS
    	JsToExecute = document.querySelector("#create-parley-wysiwyg").innerText = '%JSPostTitleAndBody%'
    	try Status := driver.executeScript(JsToExecute)
    	; Check if text got input
    	JsToExecute = return document.querySelector("#create-parley-wysiwyg").innerText
    	try Status := driver.executeScript(JsToExecute)
    	if(Status = ""){
    		Message = Failed to Input with JS as well
    		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

    		Xpath = /html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[2]/div[1]/div[1]/form[1]/div[1]/div[2]/div[1]
    		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
    		if(Status){
    			try CurrentTab := driver.url
    			Message = Failed to input Post: `nCurrent Tab URL: %CurrentTab%
    			; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
    			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    			SaveDriverURLOFErrorPage()
    			Return
    		}

    	}
    }
    */


    if(ImageAttachmentFilepath != ""){
    	Message = Attaching Image
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

    	Xpath = //input[@type='file']
    	try driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)
    	catch e {
    		Message = Failed to Attach Image
    		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    		SaveDriverURLOFErrorPage()
    		Return
    	}
    	Message = Waiting 5 seconds for image to upload
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
    	sleep, 5000
    }
    else, {
    	SaveOrPostProgress(Message:="Waiting 2 seconds for Everything to Finish Loading",PostType:="Tooltip,ErrorLoggingTextFile")
    	sleep, 2000
    }

    ; SaveOrPostProgress(Message:="Waiting 2 seconds for Everything to Finish Loading",PostType:="Tooltip,ErrorLoggingTextFile")
    ; sleep, 2000


    ; sleep, 5000
    Xpath = //button[normalize-space()='Parley']
    Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
    if(Status){
    	Message = Failed to Submit Post (#4064)
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	SaveDriverURLOFErrorPage()
    	Return
    }

/*    Message = Waiting 5 seconds to double check that the post got submitted
    SaveOrPostProgress(Message:=Message,PostType:="Tooltip, ErrorLoggingTextFile")
    sleep, 5000

    ; check the text contents of the input box to make sure that the post got submitted
    JsToExecute = return document.querySelector("div[id='create-parley-wysiwyg'] div").textContent;
    try Status := driver.executeScript(JsToExecute)
    if(Status != ""){
    	Xpath = //button[@id='submit-button'] ; click the submit button again
    	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)

	; Message = Post got input but did not submit properly and still present after 5 seconds`nPost Content: %Status%
	; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")

	
}

*/
; DevModeMsgBox(Status)

  /*  js = document.getElementById('submit-button').click();
    status := JS_TryToExecute(js,2,2000)

    */

/*    sleep, 3000
    jscheck = return document.getElementsByClassName('emoji-wysiwyg-editor')[0].textContent;
    try Status := driver.executeScript(jsCheck)
    if(Status != ""){
    	Message = Failed to Submit Post (#2523)
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	Return
    }
    */

    ; Msgbox % "Status: " Status
    IniWrite, Successful, %StatusFileFilePath%, Status, Parler

    AddToTotalPostsPostedCount()

    

    PauseBetweenPosts()
    ; TakeScreenshotOfPage()
    DevModeMsgBox("done!")

    Return
    ; -------------------------------/Parler-------------------------------






    ; ----------------------r---------Discord-------------------------------
    PostToDiscord:
    CurrentSite := "Discord"

    ; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile")
    Message = Posting Through API
    SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

    if(DiscordParlerWebhookURL = ""){
    	Message = Webhook Link not found. Please set "DiscordParlerWebhookURL" in %SettingsIniFilepath%.
    	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
    	Return
    }


    if(BoldTitleWAPI){
    	if(NewLineBetweenTitle)
    	Message = **%PostTitle%**`n`n%PostBody%
    	else, 
    	Message = **%PostTitle%**`n%PostBody%
    }
    else, { ; NOT bold title
    	if(NewLineBetweenTitle)
    	Message = %PostTitle%`n`n%PostBody%
    	else, 
    	Message = %PostTitle%`n%PostBody%
    }


/*
    if(PostTitle != "")
    Message = **%PostTitle%**`n%PostBody%
    else,
    Message = %PostBody%

    */
    if(ImageAttachmentFilepath != ""){
    	SingleQuotationMark = "
    	; remove any single quotes from filepath
    	ImageAttachmentFilepath := StrReplace(ImageAttachmentFilepath, SingleQuotationMark, "")

    	if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
    		loop % StrLen(Message) {

    			if(A_index < 1900)
    			Continue

    			SplitCharNumber := A_index
    			; IndexMinusOne := A_index - 1

    			SplitLocationText := SubStr(Message, SplitCharNumber, 1)
    			if(SplitLocationText = " "){
    				Break
    				; Msgbox % "SplitLocation: " SplitLocation
    			}
    		}



    		DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
    		SplitCharNumber := SplitCharNumber + 1
    		DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
    		; Msgbox % "DiscordMessagePartOne: " DiscordMessagePartOne
    		; Msgbox % "DiscordMessagePartTwo: " DiscordMessagePartTwo

    		Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
    		Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
    		Status := UploadImageToDiscord(DiscordParlerWebhookURL, "", ImageAttachmentFilepath)

    		; Msgbox % "StatusOne: " StatusOne
    		; Msgbox % "StatusTwo: " StatusTwo

/*		if(!InStr(StatusOne, "id")){ ; if error for each of the messages, post its
			parsed := JSON.Load(StatusOne)
			StatusOneFailure := parsed.content[1]

			parsed := JSON.Load(StatusTwo)
			StatusTwoFailure := parsed.content[1]

			Message = Partial Failure for the following reason: %StatusOneFailure% OR %StatusTwoFailure%
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		}
		*/
		} ; end of strlen > 1999
		else, {
			Status := UploadImageToDiscord(DiscordParlerWebhookURL, Message, ImageAttachmentFilepath)
			SaveOrPostProgress(Message:="Status",PostType:="ErrorLoggingTextFile")

			if(!InStr(Status, "id")){
				parsed := JSON.Load(Status)
				Error := parsed.content[1]
				; Msgbox % "error: " error
				Message = Discord Post Failed due to API Issue. Error was saved to errorlog; please forward to Yuriy
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				Return
			}
		}
	}
	else {
		if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
			loop % StrLen(Message) {

				if(A_index < 1900)
				Continue

				SplitCharNumber := A_index

				SplitLocationText := SubStr(Message, SplitCharNumber, 1)
				if(SplitLocationText = " "){
					Break
				}
			}

			DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
			SplitCharNumber := SplitCharNumber + 1
			DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)

			Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
			Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
		}
		else,
		SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordParler")
	}

	IniWrite, Successful, %StatusFileFilePath%, Status, Discord
	AddToTotalPostsPostedCount()
	Return
	; -------------------------------/Discord-------------------------------

	; -------------------------------SubScribeStar-------------------------------
	PostToSubscribeStar:
	CurrentSite := "SubScribeStar"


	IniRead, SubscribeStarProfileURL, %SettingsIniFilepath%, SocialMediaPoster, SubscribeStarProfileURL, %A_Space%
	if(SubscribeStarProfileURL = ""){
		Message = SubscribeStarProfileURL is blank. Please update Settings.ini
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")


	Status := NavigateFromBaseURLTo(SubscribeStarProfileURL)
	if(Status){
		Message = Failed to Navigate to SubScribeStar Page
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
	}

	Message = Checking Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
	; Xpath = //div[@class='top_bar-login']
	Xpath = //div[@class='top_bar-login']
	; MsgBox,,Xpath Value,% driver.findelementbyxpath(Xpath).Attribute("value") ;XPath: ID=site-title & span tag
	Try LoginStatus := driver.findelementbyxpath(Xpath).Attribute("innerText") ; Grabb innertext
	if(InStr(LoginStatus, "Log In")){ ; need to log in
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
		sleep, 5000
		Xpath = //button[@type='submit']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
	}

	Message = Inputting Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	; Click on "Start your post by clicking here"
	Xpath = //div[contains(text(),'Create Post')]
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
	if(Status){
		Message = Failed to Click "Create Post" button with relative xpath
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

		Xpath = //div[@class='new_post']//div[@class='new_post-create_button']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to click "Create Post" button with Contains(Text) xpath and relative Xpath - Trying wtih ID
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
			; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")

			Status := Selenium_LoopToClickID(IDName:="cover_upload",NumOfLoops:=5,SleepLength:=1000)
			if(Status){
				Message = Post Failed: Check Login Status
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				; TakeScreenshotOfPage()
				SaveDriverURLOFErrorPage()
				Return
			}
		}
	}

	; sleep, 5000
	; msgbox

	; Clear any previous content from the post box
	Message = Clearing if any text exists from an unposted post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //trix-editor[@role='textbox']
	Status := Selenium_LoopToClearXpath(Xpath,NumOfLoops:=5,SleepLength:=1000)
	if(Status){
	}
	; try driver.FindElementByXPath(Xpath).clear()   ;Clears content from an element and sets


	; Input Text into pop-up edit box
	SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //trix-editor[@role='textbox']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
	if(Status){
		Message = Failed to Input Post using Direct Xpath. Trying with Relative
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
		; TakeScreenshotOfPage()
		; msgbox, 1

		Xpath = /html/body/div/div[3]/div[2]/div[2]/div/div[1]/form/div[2]/div[1]/trix-editor
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
		if(Status){
			Message = Failed to Input Post using Relative Xpath. Trying with Javascript
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

			
			SubscribeStarJSDescription := FormatTextToJSText(PostTitleAndBody) 
			js = document.querySelector("trix-editor[role='textbox']").value = "%SubscribeStarJSDescription%";
			try driver.executeScript(js)    ;Executes a Javascript on the webpage, mostly used for buttons.
			catch e {
				Message = Failed to Input Post Contents (E#8281)
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				; TakeScreenshotOfPage()
				SaveDriverURLOFErrorPage()
				Return
			}
			; msgbox, 3
		}


	}

	; Attach an image if a filepath was provided
	if(ImageAttachmentFilepath != ""){
		SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

		; this works for both images and videos
		Xpath = //input[@multiple='multiple']
		driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)


/*		Xpath = //span[@class='trix-button-group trix-upload-buttons']//button[2]
		Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
		if(Status){
			Message = Failed to click on Picture Upload button
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		}
		
		InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
		if(InputStatus = "Failed")
		{
			Message = Upload Failed:`nUnable to Find "Open File" window to input filepath into
			SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
			Return
		}
		*/

		SaveOrPostProgress(Message:="Waiting 5 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")
		sleep, 5000
	}


	; Click the post Button
	SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //button[contains(text(),'Post')]
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
	if(Status){
		Message = Failed to Submit Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

	IniWrite, Successful, %StatusFileFilePath%, Status, SubScribeStar
	AddToTotalPostsPostedCount()

	
	
	PauseBetweenPosts()
	; TakeScreenshotOfPage()
	DevModeMsgBox("done!")

	Return
	; -------------------------------/SubScribeStar-------------------------------

	; -------------------------------Telegram-------------------------------
	; API documentation
	; https://core.telegram.org/bots/api#sendmessage
	PostToTelegram:
	CurrentSite := "Telegram"

	; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile")
	Message = Posting Through API
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	if(TelegramBotToken = "" Or TelegramBotChatID =""){
		Message = TelegramBotToken or TelegramBotChatID is missing from %SettingsIniFilepath%. `nPlease input them and rerun the script.
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		; Msgbox, 4096, Error!, TelegramBotToken or TelegramBotChatID is missing from %SettingsIniFilepath%. `nPlease input them and rerun the script.
		Return
	}


	LineBreakChar = `%0A ; Used for API
	

	TelegramTitle := ASCIISTRReplace(PostTitle)
	TelegramBody := ASCIISTRReplace(PostBody)


/*	TelegramTitle := PostTitle
	TelegramBody := PostBody

	*/

	; Msgbox % "TelegramBody: " TelegramBody

	if(PostBody = ""){
		if(BoldTitleWAPI)
		Message := "*" . TelegramTitle . "*"
		else, 
		Message := TelegramTitle
	}
	else, { ; if postbody is not blank
		; MsgBox, we in post body
		if(BoldTitleWAPI){
			if(NewLineBetweenTitle)
			Message := "*" . TelegramTitle . "*" . "`n`n" . TelegramBody
			else, 
			Message := "*" . TelegramTitle . "*" . "`n" . TelegramBody
		}
		else, { ; NOT Bold Title
			if(NewLineBetweenTitle)
			Message := TelegramTitle . "`n`n" . TelegramBody
			else, 
			Message := TelegramTitle . "`n" . TelegramBody

		}
	}

	; Msgbox % "Message: " Message
	; REMOVE
	; Message := PostTitle . "`n" . PostBody

	; Msgbox % "TelegramTitle: " TelegramTitle
	; Msgbox % "TelegramBody: " TelegramBody

	; Msgbox % "Message: " Message


	if(ImageAttachmentFilepath != "" AND StrLen(Message) > 1020){ ; utilize function that converts image to MIME/multi form 
		; Telegram API character limit of 4096 for a basic message.
		; @todo: add functionality to split messages longer than 4096 characters
		; msgbox, 2

		if(BoldTitleWAPI)
		TelegramTitle := "*" . TelegramTitle . "*"
		else, 
		TelegramTitle := TelegramTitle

		Status := SendTelegramPhoto(TelegramBotToken, TelegramBotChatID, ImageAttachmentFilepath, caption := TelegramTitle )       ; you could add more options; compare the Telegram API docs
		Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := TelegramBody )
	}
	else if(ImageAttachmentFilepath != "" AND StrLen(Message) <= 1020){
		Status := SendTelegramPhoto(TelegramBotToken, TelegramBotChatID, ImageAttachmentFilepath, caption := Message )       ; you could add more options; compare the Telegram API docs

	}
	else, 
	{ ; send just the text
		; Msgbox % "Message: " Message
		Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := Message )
	}

	if(Status){
		Message = Upload Failed due to API issue. Telegram API Returned Value:`n %Status%
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	; SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordParler")
	IniWrite, Successful, %StatusFileFilePath%, Status, Telegram
	AddToTotalPostsPostedCount()

	Return
	; -------------------------------/Telegram-------------------------------




	; -------------------------------LinkedIn-------------------------------
	PostToLinkedIN:
	CurrentSite := "LinkedIn"

	if(StrLen(PostTitleAndBody) > 1300){
		Message = Post longer than LinkedIn's 1300 character limit. Posting Skipped.
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		IniWrite, Skipped - Too Long, %StatusFileFilePath%, Status, LinkedIn
		Return
	}


	URLAttempt := NavigateFromBaseURLTo("https://www.linkedin.com/login")
	if(URLAttempt = "Failed")
	Return

	Message = Checking Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	sleep, 1000
	try CurrentTabURL := driver.Url
	if(InStr(CurrentTabURL, "login")){
		Message = Login Cookies Expired. Please Re-Login
		; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}


	Message = Clicking "Start a Post" button
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	loop, 3 {
		Xpath = //button[normalize-space()='Start a post'] ; start a post button
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(!Status)
		Break
		; Msgbox % "Status: " Status
		if(Status AND A_index = 1){
			try CurrentURL := driver.url
			Message = Failed to click on "Start a post" button`nChecking Login Status`nCurrent URL: %CurrentURL%
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
			try html := driver.pagesource ; save page's entire HTML to a variable
			if(InStr(HTML, "Sign In") AND InStr(HTML, "Forgot password")){
				Xpath = //button[normalize-space()='Sign in']
				Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
				driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
				sleep, 2000
				driver.Get("https://www.linkedin.com/feed/")	;Open selected URL
				; driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
				continue
			}
			else, ; otherwise check and toggle the chat popup on the side
			{
				Message = Checking if Chat Sidebar is in the way
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
				try html := driver.pagesource ; save page's entire HTML to a variable
				if(InStr(HTML,"You are on the messaging overlay. Press enter to minimize it.")){ ; if sidebar is open
					Xpath = //body//div//aside//button[2] ; click to minimize it
					try driver.FindElementByXPath(Xpath).click()
					Message = Chat sidebar was minimized
					SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
					Continue ; continue to next loop
				}
			}
		}
		; DevModeMsgBox("test")
		; Check if linked in post popup appeared
		Xpath = //div[@aria-label='Text editor for creating content']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to click into Create Post popup to input post
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
		}
	}

	if(Status){
		Message = Post Failed: Please Check Login Status
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	if(ImageAttachmentFilepath != ""){
		; Click the upload image button
		SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

		; click attach image button
		Xpath = //li-icon[@type='image']//*[name()='svg']
		Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
		if(Status){
			Message = Failed to click "Attach Image" button with Selenium
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

			Xpath = //input[@id='image-sharing-detour-container__file-input']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
			if(Status){
				Message = Failed to Attach photo with both attempts.
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

			if(WinExist("Open")) ; if open image popup still exists, close it
			WinClose, Open
			; Return
		}
		else, {
			Status := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
			if(Status)
			{
				Message = Failed to input filepath into "Open File" window.
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}
		}
		; sleep, 10000

		Xpath = //span[normalize-space()='Done'] ; click done button
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
		if(Status){
			Message = Failed to click "Done" button on image upload
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		SaveOrPostProgress(Message:="Waiting 5 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")
		sleep, 5000

	}

	Message = Inputting Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	; Input Post text contents
	loop, 3 {
		Xpath = //div[@aria-label='Text editor for creating content']  ; Input text of post 
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
		if(Status){
			Message = Failed to input post content
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		}

		; Double check that post got input
		Jscheck = return document.querySelector("div[aria-label='Text editor for creating content']").innerText
		try Status := driver.executeScript(Jscheck)
		; DevModeMsgBox(Status)
		if(StrLen(Status) > 5)
		Break

		if(A_index = 3){
			Message = Post Failed: Failed to input Post for some reason
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}
		; Continue
	}

/*	if(!Status){ ; if BLANK 
		Message = Post Failed: Failed to input Post for some reason
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}
	*/
	; sleep, 2000

	if(InStr(PostTitleAndBody, "http") OR InStr(PostTitleAndBody, "www")){
		Message = Waiting 10 seconds for Preview to Get Fetched
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
		sleep, 10000 
	}
	else, {
		sleep, 2000
	}


	SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")


	Xpath = //span[normalize-space()='Post'] ; Click the final "post" button
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
	if(Status){
		Jscheck = return document.querySelector("div[aria-label='Text editor for creating content']").textContent ; Grabb innertext
		try TextContent := driver.executeScript(Jscheck)

		Message = Failed to Submit Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")

		Message = Failed to Submit Post: Text Content that got input: %TextContent%
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

/*	; Keep trying to click the home button until able to and then move on to next site because sometimes it takes a while for a post to upload
	Xpath = //span[normalize-space()='Home']
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=30,SleepLength:=1000)

	*/

	IniWrite, Successful, %StatusFileFilePath%, Status, LinkedIn
	AddToTotalPostsPostedCount()

	DevModeMsgBox("done!")
	
	PauseBetweenPosts()
	; TakeScreenshotOfPage()
	DevModeMsgBox("done!")

	Return
	; -------------------------------/LinkedIn-------------------------------


	; -------------------------------Minds-------------------------------
	PostToMinds:
	CurrentSite := "Minds"


	SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
	; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	URLAttempt := NavigateFromBaseURLTo("https://www.minds.com/newsfeed/subscriptions")
	if(URLAttempt = "Failed")
	Return

	sleep, 1000

	try CurrentTabURL := driver.Url
	; Msgbox % "CurrentTabURL: " CurrentTabURL
	if(InStr(CurrentTabURL, "login")){
		Message = Login Cookies Expired. Trying to Re-Login
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
		sleep, 2000
		Xpath = //div[contains(text(),'Login')]
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
	}

	Message = Clicking into Speak your mind.. Box
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	loop, 3 { 
		if(A_index = 3){
			SaveOrPostProgress(Message:="Failed to click into -speak your mind..- input box.",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}


		; Click the Big Compose Box at the top of the page
		Xpath = //div[@class='m-composer__triggerOverlay']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
		; Status := Selenium_LoopToClickXpath(Xpath,5,1000)
		if(Status){
			SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		; check that popup appears by checking for "Create Blog" button in popup
		js = return document.querySelector("div[class='m-composer__base'] div[class='m-composerTitleBar__createBlogTrigger ng-star-inserted']").innerText
		try status := driver.executeScript(js)
		if(InStr(Status, "Create Blog")){
			break
		}
		else, {
			continue
		}

		; Msgbox % "status: " status



	}

	; Attach Image
	if(ImageAttachmentFilepath != ""){
		; Click the upload image button
		SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")


		Xpath = //input[@type='file']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
		if(Status){
			Message = Failed to attach image (E#1203)
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		SaveOrPostProgress(Message:="Waiting 2 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")

		sleep, 2000


		SaveOrPostProgress(Message:="Inputting Post Content`nMight take 5-15 seconds to get input",PostType:="Tooltip,ErrorLoggingTextFile")

		; Click the plus button to make the title box show up
		Xpath = //div[@class='m-composer__base m-composer__base--withPreview']//i[@class='material-icons ng-star-inserted'][normalize-space()='add_circle_outline']
		try driver.FindElementByXPath(Xpath).click()
		catch e { ; if failed to plus button, then input the post body and text into the same box
			; msgbox, failed to click Plus
			; goto, InputMindsPostCombined
		} 
		
		; if plus button was clicked successfully, input title and body individually
		; Input title
		; Msgbox % "PostTitle: " PostTitle
		Xpath = //textarea[@placeholder='Title']
		; driver.FindElementByXPath(Xpath).SendKeys("heleeoeoe")

		; CLick into title box
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) 

		; Input text itno title box
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitle)
		if(Status){ ; if failed to input title then skip to inputting both combined
			; msgbox, failed to input title
			Message = Failed to input Title
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
			
			MindsTitleStatus := "Failed"
			; Return

			; goto, InputMindsPostCombined
		}

		; msgbox, title input?
		; Input body
		if(MindsTitleStatus)
		MindsPost := PostTitleAndBody
		else, MindsPost := PostBody

		; Msgbox % "PostBody: " PostBody
		Xpath = //textarea[@id='minds-m-composer__textarea--1003']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=MindsPost)
		if(Status){
			; msgbox, failed to input body
			Message = Failed to post with Xpath, trying with ID
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
			Status := Selenium_LoopToSendValueToID("minds-m-composer__textarea--1003",5,1000,MindsPost)
			if(Status){
				Message = Failed to input Post Content into Page
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}
		}
		} else, { ; otherwise, input just text
			SaveOrPostProgress(Message:="Inputting Text Post",PostType:="Tooltip,ErrorLoggingTextFile")
			; DevModeMsgBox("Inputting Text Post")
			Xpath = //textarea[@id='minds-m-composer__textarea--1003']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)

			DevModeMsgBox("done")
			if(Status){
				Message = Failed to post with Xpath, trying with ID
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
				Status := Selenium_LoopToSendValueToID("minds-m-composer__textarea--1003",5,1000,PostTitleAndBody)
				if(Status){
					Message = Failed to input Post Content into Page
					SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
					SaveDriverURLOFErrorPage()
					Return
				}
			}


			if(InStr(PostBody,"http"))
			{
				Message = Sleeping 5 seconds for preview to load
				SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile")
				sleep, 5000
			}

		}

		; sleep, 2000
		SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")


		loop, 3 {
			if(A_index = 3){
				SaveOrPostProgress(Message:="Failed to submit post",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

			; click submit button
			js = document.querySelector("button[class='m-button m-button--blue m-button--small m-button--dropdown'] span[class='ng-star-inserted']").click();
			try status := driver.executeScript(js)
			catch e {
				Msgbox % "status: " status

			}

			SaveOrPostProgress(Message:="Waiting 5 seconds to confirm post got submitted",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
			sleep, 5000

			; check that popup appears by checking for "Create Blog" button in popup
			js = return document.querySelector("div[class='m-composer__base'] div[class='m-composerTitleBar__createBlogTrigger ng-star-inserted']").innerText
			try status := driver.executeScript(js)
			if(InStr(Status, "Create Blog")){
				continue
			}
			else, {
				break
			}


		}


/*		if(!TestingMode){
			SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")

			Xpath = Xpath = (//span[@class='ng-star-inserted'][normalize-space()='Post'])[2]
			Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=5000)
			sleep, 1000
			Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=5000)
			if(Status){
				Message = Failed to Submit Post
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}
			}

			*/

			; Click the post button


			IniWrite, Successful, %StatusFileFilePath%, Status, Minds
			AddToTotalPostsPostedCount()



			PauseBetweenPosts()
			; TakeScreenshotOfPage()
			DevModeMsgBox("done!")

			Return
			; -------------------------------/Minds-------------------------------

			; -------------------------------Locals-------------------------------
			PostToLocals:
			CurrentSite := "Locals"

			; @todo: Add auto-login to locals
			SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")

			IniRead, LocalsURL, %SettingsIniFilepath%, %ScriptSettingsSection%, LocalsURL
			Message = LocalsURL from Ini File: %LocalsURL%
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

			; LocalsURL := StrReplace(Localsurl, "/share/post", "")
			; LocalsURL := Localsurl . "/login"
			; Message = Localsurl: %LocalsURL%
			; SaveOrPostProgress(Message:=Message,PostType:=",DiscordErrorLogging")

			Status := NavigateFromBaseURLTo(LocalsURL)
			if(Status = "Failed")
			Return

			sleep, 1000

			Message = Checking Login Status

			try CurrentTabURL := driver.Url
			if(InStr(CurrentTabURL, "/login") OR InStr(CurrentTabURL, "/register")){
				Message = Login Cookies Expired. Please Re-Login
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

			; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
			; Xpath = //textarea[@id='body']
			; Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=2000)
			; if(Status){
				; 	Message = Trying to Log Back In
				; 	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

				; 	LocalsLoginURL := LocalsURL . "/login"
				; 	try driver.Get(LocalsLoginURL)	;Open selected URL
				; 	try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding

				; 	sleep, 3000
				; 	js = document.getElementsByName('submit')[0].click();
				; 	try driver.executeScript(js)
				; 	; DevModeMsgBox(js)
				; 	; clipboard := js

				; 	try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
				; 	sleep, 5000
				; 	; try driver.Get(LocalsURL)	;Open selected URL
				; 	; try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding

				; 	Xpath = //textarea[@id='body']
				; 	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
				; 	{
					; 		Message = Post Failed: Check Login Status
					; 		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
					; 		Return
					; 	}

/*			Message = Post Failed: Check Login Status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return

			Message = Page did not load after 30 seconds. Force stopping refresh and trying to continue
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

			send, {Escape} ; Temporary workaround, as Page seems to endlessly load for Stef

			Xpath = //textarea[@id='body']
			Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
			if(Status){
				SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				; TakeScreenshotOfPage()

				Return
			}
			*/

			; }


			Message = Inputting Post Content
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


			Xpath = //*[@id="body"]
			try driver.FindElementByXPath(Xpath).click()
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
			if(Status){
				Message = Failed to input Title
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

			; sleep, 1000

/*			Xpath = //textarea[@id='body']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostBody)
			if(Status){
				Message = Failed to Input Post Body
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}
			*/


			if(ImageAttachmentFilepath != ""){
				; Click the upload image button
				SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")


				Xpath = //input[@multiple='multiple']
				Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
				if(Status){
					Message = Failed to Upload Image
					SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
					SaveDriverURLOFErrorPage()
					Return
				}
				; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)
				; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)


				SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")

				sleep, 10000
			}
			Message = Submitting Post
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")




/*	; Click the final "post" button
	SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
	Status := Selenium_LoopToClickName(ElementName:="submitPost",NumOfLoops:=5,SleepLength:=1000)
	if(Status){
		Message = Failed to Submit Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}
	
	*/

	; msgbox

	; @todo: add error check into here to check the current page url and after page url
	; Click Publish post
	js = document.getElementsByName('submitPost')[0].click();  ; Send content through javascript (Great for getting around emoji chrome limitaitons)
	try driver.executeScript(js)

	Message = Double checking that post got submitted
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
	sleep, 5000


	try CurrentTabURL := driver.Url
	if(InStr(CurrentTabURL, "share/post")) { ; post failed to submit if it's still on the create new post page
	Message = Error: Post Failed to Submit. Please check tab for reason.
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return

}

/*	; Double check that post got submitted
	js = return document.querySelector("#body").value
	Status := driver.executeScript(js)
	if(Status != ""){
		Message = Error: Post Failed to Submit for some reason
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

	*/

	IniWrite, Successful, %StatusFileFilePath%, Status, Locals
	AddToTotalPostsPostedCount()

	
	
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
	PauseBetweenPosts()
	; TakeScreenshotOfPage()
	DevModeMsgBox("done!")


	Return
	; -------------------------------/Locals-------------------------------


	; -------------------------------Gab-------------------------------
	PostToGab:
	CurrentSite := "Gab"


	SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	GabPostURL = https://gab.com/compose
	URLAttempt := NavigateFromBaseURLTo(GabPostURL)
	if(URLAttempt = "Failed")
	Return

	sleep, 1000
	Message = Checking Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


	try CurrentTabURL := driver.Url
	if(!InStr(CurrentTabURL, "/compose")){
		Message = Login Cookies Expired. Trying to Re-Login
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		; navigate to login page
		url = https://gab.com/auth/sign_in
		try driver.Get(url)	;Open selected URL
		try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
		sleep, 1500 ; sleep long enough for password manager to input password
		Xpath = //button[normalize-space()='Log in']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			SaveOrPostProgress(Message:="Failed to Login. Please Login Manually",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}
		; navigate to post input page
		URLAttempt := NavigateFromBaseURLTo(GabPostURL)
		if(URLAttempt = "Failed")
		Return
		driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
	}


	; Message = Inputting Post
	; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //body/div[@id='gabsocial']/div/div/div/div/div/div[2]/a[1]
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=500)
	if(!Status){ ; if successfully clicked on login button, we are logged out
		Message = Login Cookies Expired. Trying to Re-Login
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
		Xpath = //button[normalize-space()='Log in']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		sleep, 2000
		URLAttempt := NavigateFromBaseURLTo("https://gab.com/compose")

	}


	Message = Inputting Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	if(ImageAttachmentFilepath != ""){
		; Click the upload image button
		SaveOrPostProgress(Message:="Attaching Image First",PostType:="Tooltip,ErrorLoggingTextFile")

		Xpath = //input[@type='file']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
		if(Status){
			Message = Failed to attach Image
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")

		sleep, 10000
	}

	Xpath = //div[@data-block='true']//div
	Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostTitleAndBody)
	if(Status){
		SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}


	; Click the final "post" button
	SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //*[@id="gabsocial"]/div/div[2]/div[2]/main/div/div[3]/div/div
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
	if(Status){
		Message = Failed to Submit Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

	IniWrite, Successful, %StatusFileFilePath%, Status, Gab
	AddToTotalPostsPostedCount()

	
	
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
	PauseBetweenPosts()
	; TakeScreenshotOfPage()
	DevModeMsgBox("done!")

	Return
	; -------------------------------/Gab-------------------------------


	; -------------------------------PocketNet-------------------------------
	; -------------------------------Bastyon-------------------------------
	PostToPocketNet:
	CurrentSite := "Bastyon"


	SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	URLAttempt := NavigateFromBaseURLTo("https://bastyon.com/index")
	if(URLAttempt = "Failed")
	Return

	; Loop a bunch of times for page to load
	SaveOrPostProgress(Message:="Waiting for Page to Load Fully",PostType:="Tooltip,ErrorLoggingTextFile")
	loop, 12 {

		; click into input box
		js = document.querySelector(".emojionearea-editor.pastable").click()
		try driver.executeScript(js)

		Xpath = //div[@class='emojionearea-editor pastable']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=5000)
		if(!Status)
		break

		Xpath = //b[normalize-space()='Sign in']
		try Status := driver.findelementbyxpath(Xpath).Attribute("textContent") ;XPath: ID=site-title & span tag
		if(InStr(Status, "Sign in")){
			break
		}

		; Msgbox % "Status: " Status
	}
	if(Status){ ; if failed to click into entry box
		Message = Post Failed: Check Login Status
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}




	Message = Clearing Previous Post Content
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	js = document.querySelector("div[title='Clear post'] i[class='fas fa-times-circle']").click()
	try driver.executeScript(js)

	sleep, 1000

	js = document.querySelector(".btn1.medium").click()
	try driver.executeScript(js)

	sleep, 1000

	; msgbox

	; input post text content
	Message = Inputting Post Content
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	JsToExecute = document.getElementsByClassName('emojionearea-editor pastable')[0].innerText = '%JSPostTitleAndBody%'
	Status := JS_TryToExecute(JsToExecute)
	if(Status){
		Message = Post Failed: Check Login Status
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

	JsToExecute = return document.getElementsByClassName('emojionearea-editor pastable')[0].textContent;
	try Status := driver.executeScript(JsToExecute)
	if(Status = ""){
		Message = Post Failed: Check Login Status
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}
	; Message = Post that got input: %Status%
	; SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
	; DevModeMsgBox(Message)
	; msgbox % "textContent: " . textContent



	; Doesn't work for some reason
	; JsToExecute = return document.querySelector("div.txt div.emojionearea.message div.emojionearea-editor.pastable").innerText
	; Status := JS_TryToExecute(JsToExecute)
	; if(Status){
		; 	Message = Check Login Status: Failed to Input Post
		; 	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		; 	Return
		; }


		sleep, 2000

		if(ImageAttachmentFilepath != ""){
			; Message = Attaching Image
			; SaveOrPostProgress(Message:=Message,PostType:="Tooltip")

			; Click the "Image" button
			SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")
/*			Xpath = //div[@title='Add Images to Post']
			Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
			if(Status){
				Message = Failed to Click "Attach Image" Button
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}
			*/



			; sleep, 5000

			Xpath = //input[@type='file']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=3,SleepLength:=5000,StringTextContent:=ImageAttachmentFilepath)
			if(Status){
				Message = Failed to Attach Image
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}


			SaveOrPostProgress(Message:="Waiting 10 Seconds For Image to Upload",PostType:="Tooltip,ErrorLoggingTextFile")

			sleep, 10000


		}

		; Input Tags
		Xpath = //div[@class='search fastSearchShow']//input[@id='text']
		TagsArray := StrSplit(PostTags, ",")
		TagsArrayLength := TagsArray.Length()   ; Save total number of items in the array
		loop, %TagsArrayLength% {
			Tag := TagsArray[A_Index]
			Tag := StrReplace(Tag, " ", "")
			DevModeMsgBox(Tag)
			; Tag = %Tag%
			Xpath = //input[@placeholder='Categories and tags']
			driver.FindElementByXPath(Xpath).SendKeys(Tag)
			driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.ENTER)

			; driver.findElementsByClass("sminput").item[2].click()

			; JsToExecute = document.querySelector("#text[placeholder='Add Categories/Tags']").value = "#%Tag%"
			; Status := JS_TryToExecute(JsToExecute)
			; 
			; driver.SendKeys(driver.Keys.SPACE)
			; 
			; JsToExecute = return document.querySelector("#text[placeholder='Add Categories/Tags']").value
			; Status := JS_TryToExecute(JsToExecute)

			if(A_index = 5)
			Break


			/*Tag := TagsArray[A_Index]
			Tag := StrReplace(Tag, " ", "")
			; Tag = %Tag%
			Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=Tag)
			try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.Space)

			*/
			; if(A_index = 8) ; Steemit only allows 8 tags
			; Break
		}
		; msgbox

/*	Xpath = //div[@class='emojionearea-editor pastable']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=3,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
	if(Status){
		SaveOrPostProgress(Message:="Failed to Input Post",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return

		; Send, 
	}
	*/


	; Msgbox,4096,Pause!!,asdf

	SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")

	; CLick the post button
	Xpath = //button[normalize-space()='Post']
	loop, 3 {
		try driver.FindElementByXPath(Xpath).click()
		sleep, 1500
	}
	; Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
	; sleep, 2000
	; Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
/*	if(Status){
		Message = Failed to Submit Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}
	*/
	Message = Waiting 5 seconds to double check that post got submitted
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
	sleep, 5000
	; try PossiblyError := driver.findElementsByClass("paddingmobilewrapper").item[1].Attribute("innerText") ; Grabb innertext

	; CHeck if input box still contains text
	JsToExecute = return document.getElementsByClassName('emojionearea-editor pastable')[0].textContent;
	try Status := driver.executeScript(JsToExecute)
	if(Status){
		; sleep, 2000
		try Jscheck = return document.querySelector(".paddingmobilewrapper").textContent ; Grabb innertext
		PossiblyError := driver.executeScript(Jscheck)
		PossiblyError := StrReplace(PossiblyError, "`n", "") ; remove extra stuff from text
		PossiblyError := StrReplace(PossiblyError, "  ", "") ; remove extra stuff from text
		PossiblyError := StrReplace(PossiblyError, A_Tab, "") ; remove extra stuff from text

		; Msgbox % "PossiblyError: " PossiblyError
		Message = Failed To Submit Post: Error was: %PossiblyError%
		; DevModeMsgBox(PossiblyError)
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}



	; sleep, 2000 
	; Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
/*	if(Status){
		Message = Failed to Submit Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	*/


	IniWrite, Successful, %StatusFileFilePath%, Status, PocketNet
	AddToTotalPostsPostedCount()

	
	
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
	PauseBetweenPosts()
	; TakeScreenshotOfPage()
	DevModeMsgBox("done!")

	Return
	; -------------------------------/Bastyon-------------------------------



	;-----------------------Steemit-------------------------
	PostToSteemit:
	CurrentSite := "Steemit"



	SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	URLAttempt := NavigateFromBaseURLTo("https://steemit.com/submit.html")
	if(URLAttempt = "Failed")
	Return



	Message = Checking for Content from Previous Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	; Click CLear Button
	Xpath = //button[normalize-space()='Clear']
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
	if(Status){
		Message = Trying to log back in
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
		Xpath = //a[normalize-space()='Login']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Upload Failed: Check Login Status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}
		sleep, 2000
		; otherwise button was clicked and we need to submit the saved credentials
		Xpath = //button[normalize-space()='Login']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=20,SleepLength:=100)
		; DevModeMsgBox(Status)
		if(Status){
			Message = Upload Failed: Check Login Status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}
		else, 
		{
			sleep, 3000
			Xpath = //button[normalize-space()='Clear']
			Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
			if(Status){
				Message = Upload Failed: Check Login Status
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}
		}

	}
	else, {
		sleep, 500
		try, driver.switchToalert().accept() ; if text exists Steemit will pop up menu asking for confirmation for clearing
	}




/*		if(Status){
			Message = Post Failed, Please check login status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			Return
		}
		; Click "Accept" popup that asks if you're sure you want to clear post
		try, driver.switchToalert().accept()

		*/
		


		Message = Inputting Post Content
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


		; Input title
		Xpath = //input[@placeholder='Title']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitle)
		if(Status){
			Message = Post Failed: Check Login Status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}


		Xpath = //textarea[@placeholder='Write your story...']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostBody)
		if(Status){
			Message = Failed to input Post Body
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}



		if(ImageAttachmentFilepath != ""){
			Message = Attaching Thumbnail
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			Xpath = //input[@type='file']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
			if(Status){
				Message = Failed to attach Image
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

/*
			Xpath = //a[normalize-space()='selecting them']
			Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
			if(Status){
				Message = Failed to click on "Attach Image" button
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				Return
			}

			InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
			if(InputStatus = "Failed")
			{
				Message = Upload Failed:`nUnable to Find "Open File" window to input filepath into
				SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
				Return
			}

			*/
			Message = Waiting 5 seconds for thumbnail to be generated
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			sleep, 5000
		}


		message = Inputting Tags
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		; Input Post Tags
		Xpath = //input[@placeholder='#tag']
		TagsArray := StrSplit(PostTags, ",")
		TagsArrayLength := TagsArray.Length()   ; Save total number of items in the array
		loop, %TagsArrayLength%{
			Tag := TagsArray[A_Index]
			Tag := StrReplace(Tag, " ", "")
			Tag = #%Tag%
			Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=Tag)
			try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.Space)

			if(A_index = 8) ; Steemit only allows 8 tags
			Break
		}


		Message = Submitting Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


		; Click Submit Button
		Xpath = //button[@type='submit']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to submit Post
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		IniWrite, Successful, %StatusFileFilePath%, Status, Steemit
		AddToTotalPostsPostedCount()

		
		
		PauseBetweenPosts()
		; TakeScreenshotOfPage()
		DevModeMsgBox("done!")

		Return
		;-----------------------/Steemit-------------------------

		;---Tumblr---
		;------------------------------------------------
		PostToTumblr:
		; Return
		CurrentSite := "Tumblr"
		; msgbox

		SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		URLAttempt := NavigateFromBaseURLTo("https://www.tumblr.com/new/text")
		if(URLAttempt = "Failed")
		Return

		sleep, 1000
		SaveOrPostProgress(Message:="Checking Login Status",PostType:="Tooltip,ErrorLoggingTextFile")

		try CurrentTabURL := driver.Url
		if(InStr(CurrentTabURL, "/login")){
			Message = Login Cookies Expired. Trying to Re-Login
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
			; sleep, 2000
			Xpath = //span[normalize-space()='Log in']
			Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
			if(Status){
				SaveOrPostProgress(Message:="Failed to Login. Please Login Manually",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

			driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
		}


		Message = Inputting Post Content
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


		; Input title
		Xpath = //textarea[@placeholder='Title']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitle)
		if(Status){
			Message = Post Failed: Check Login Status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		; Input Body of Post
		Xpath = //p[@aria-label='Empty block; start writing or type forward slash to choose a block']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostBody)
		if(Status){
			Message = Failed to input Post Body
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}



		if(ImageAttachmentFilepath != ""){
			Message = Attaching Thumbnail
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			Xpath = //input[@role='button']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
			if(Status){
				Message = Failed to attach Image
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				SaveDriverURLOFErrorPage()
				Return
			}

			Message = Waiting 5 seconds for thumbnail to be generated
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			sleep, 5000
		}


		message = Inputting Tags
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		; Input Post Tags
		TumblrTags := StrReplace(PostTags, " ", "")
		TumblrTags := TumblrTags . ","
		; Msgbox % "TumblrTags: " TumblrTags
		Xpath = //textarea[@placeholder='#add tags']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=TumblrTags)


		Message = Submitting Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		; msgbox

		; Click Submit Button
		Xpath = //span[normalize-space()='Post now']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to submit Post
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		IniWrite, Successful, %StatusFileFilePath%, Status, Tumblr
		AddToTotalPostsPostedCount()

		

		
		PauseBetweenPosts()
		; TakeScreenshotOfPage()
		Return
		;---\Tumblr---
		;------------------------------------------------



		;----------------Pintrest--------------------------------
		PostToPintrest:
		CurrentSite := "Pintrest"


		PintrestPostBodyArray := StrSplit(PostBody, "https")
		PintrestPostBody := PintrestPostBodyArray[1]

		PintrestURL := PintrestPostBodyArray[2]
		PintrestURL := StrSplit(PintrestURL, " ")
		PintrestURL := PintrestURL[1]


		if(PintrestURL != "")
		PintrestURL := "https" . PintrestURL

		; Msgbox % "PintrestURL: " PintrestURL


		; Msgbox % "PintrestPostTitleAndBody: " PintrestPostTitleAndBody
		; Msgbox % "PintrestURL: " PintrestURL
		; pintrest has a 500 character limit
		if(StrLen(PintrestPostBody) > 499){
			Message = Post longer than Pintrest's 500 character limit. Posting Skipped.
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			IniWrite, Skipped - Too Long, %StatusFileFilePath%, Status, Pintrest
			Return
		}

		if(ImageAttachmentFilepath = ""){
			Message = Post Skipped, No Image attached
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			IniWrite, Skipped - No Image, %StatusFileFilePath%, Status, Pintrest
			Return
		}

		SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		URLAttempt := NavigateFromBaseURLTo("https://www.pinterest.com/pin-builder/")
		if(URLAttempt = "Failed")
		Return



		Message = Inputting Post Content
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


		; Input title
		Xpath = //textarea[@placeholder='Add your title']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitle)
		if(Status){
			Message = Post Failed: Check Login Status
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}


		Xpath = //div[@role='combobox']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PintrestPostBody)
		if(Status){
			Message = Failed to input Post Body
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}



		if(ImageAttachmentFilepath != ""){
			Message = Attaching Thumbnail
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

			; Attach Thumbnail
			Xpath = //input[@type='file']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
		}

		Xpath = //textarea[@placeholder='Add a destination link']
		Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PintrestURL)
		if(Status){
			Message = Failed to Input Destination URL
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		; msgbox
		Message = Submitting Post
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
/*
OnMessage(0x44, "OnMsgBoxConfirmPost")
MsgBox 0x40040, Confirmation, Please Double Check Post Was Input and Submit It.`n`nThen click OK on this msgbox to move on to the next site.
OnMessage(0x44, "")

*/


; Click Submit Button
Xpath = //button[@data-test-id='board-dropdown-save-button']
try Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=1000)driver.FindElementByXPath(Xpath).click()
if(Status){
	Message = Failed to Submit Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

IniWrite, Successful, %StatusFileFilePath%, Status, Pintrest
AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()
DevModeMsgBox("done!")

Return

; -------------------------------/Pintrest-------------------------------


;---Gettr---
;------------------------------------------------
PostToGettr:
CurrentSite := "Gettr"

SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

URLAttempt := NavigateFromBaseURLTo("https://gettr.com/")
if(URLAttempt = "Failed")
Return

Message = Checking Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

sleep, 1000

; if string in tab url, then we are logged out
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, "/onboarding"))
{
	Message = Login Cookies Expired. Please Re-Login
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

; click input area
; Xpath =//button[contains(text(),'Post')]
; Xpath = ///div[@id='textarea-post']
Xpath = //*[contains(text(),'What's new?')]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
DevModeMsgBox("pause")

; Input image
if(ImageAttachmentFilepath != ""){

	; Attach image
	Xpath = //input[@type='file']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
	if(Status){
		Message = Failed to Attach Image
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

	Message = Waiting for image to upload
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
	sleep, 3000


}


; click input area
Xpath = //*[@id="textarea-post"]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)

; disable spellcheck on input field using javascript so text doesn't get garbled
js = document.getElementById('textarea-post').setAttribute("spellcheck", "false");
driver.executeScript(js)    ;Executes a Javascript on the webpage, mostly used for buttons.

; DevModeMsgBox(JSPostTitleAndBody)
; JsToExecute = document.querySelector("#textarea-post").text = "%JSPostTitleAndBody%";
; JsToExecute = document.getElementById('textarea-post')[0].text = "%JSPostTitleAndBody%";
/*
; JsToExecute = document.getElementsByClassName('emojionearea-editor pastable')[0].innerText = '%JSPostTitleAndBody%'
Status := JS_TryToExecute(JsToExecute)
if(Status){
	Message = Post Failed: Check Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

*/


/*; Xpath = //*[@id="textarea-post"]
Msgbox % "PostTitleAndBody: " PostTitleAndBody
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostTitleAndBody)
if(Status){
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}
*/




StrLengthOfPost := StrLen(PostTitleAndBody)

SaveOrPostProgress(Message:="Inputting post very slow way to avoid issues with gettr's buggy text post-processing",PostType:="Tooltip,ErrorLoggingTextFile")

Loop % StrLengthOfPost{
	; IndexPlusOne := A_index + 1

	Current_Char := SubStr(PostTitleAndBody, A_index, 1)
	; SubStr(String, StartingPos [, Length])
	; MsgBox % Current_Char
	; Gettr_Index_Of_Line_Post := GettrPostArray[A_index]
	; DevModeMsgBox(Gettr_Index_Of_Line_Post)

	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=100,StringTextContent:=Current_Char)
	if(Status){
		Message = Failed to Input Text
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}
	; sleep, 10
	; try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.Right)
}
sleep, 500
; SaveOrPostProgress(Message:="Waiting 2 seconds before submitting",PostType:="Tooltip,ErrorLoggingTextFile")
; sleep, 2000


SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 2000

; Click post button
Xpath = //span[normalize-space()='Post']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	Message = Failed to Submit Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}


IniWrite, Successful, %StatusFileFilePath%, Status, gettr
AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()

DevModeMsgBox("done!")

Return


;---/Gettr---


; -------------------------------MeWe-------------------------------
PostToMeWe:
CurrentSite := "MeWe"



SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

URLAttempt := NavigateFromBaseURLTo("https://www.mewe.com/myworld")
if(URLAttempt = "Failed")
Return

; Click out of try MeWe Premium popup if it appears
SaveOrPostProgress(Message:="Checking for Popups and closing them",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //button[normalize-space()='Skip Trial']
try driver.FindElementByXPath(Xpath).click()

sleep, 1000

; Click on Tell your contacts what's happening button
SaveOrPostProgress(Message:="Clicking into Tell your Contacts.. Box",PostType:="Tooltip,ErrorLoggingTextFile")

Xpath = //div[@class='postbox-placeholder_text']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

; DevModeMsgBox("popup activated?")


; click into popup box to make sure it's activated
/*xpath = //div[@class='ql-editor ql-blank']//div
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
DevModeMsgBox(Status)
*/
; DevModeMsgBox("inputting post now after clickng")

; input post title and body with javascript
JsToExecute = document.querySelector(".ql-editor").innerText = '%JSPostTitleAndBody%';
try Status := driver.executeScript(JsToExecute)


; check that the input box contains text
JsToExecute = return document.querySelector(".ql-editor").innerText
try Status := driver.executeScript(JsToExecute)
if(StrLen(Status) < 5){
	Message = Failed to input post into popup box
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}


/*
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostTitleAndBody)
if(Status){
	Message = Failed to input text into page.
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}
*/

; DevModeMsgBox("input worked?")


if(ImageAttachmentFilepath != ""){
	; Click "Image" button
	SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //input[@id='fake-upload-photo']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
/*
	; Xpath = /html/body/div[2]/div/div[1]/div[2]/div[1]/div/div[2]/div/div[4]/div[1]/button[1]
	Xpath = //button[@data-tooltip='Photo']
	Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
	if(Status){
		Message = Failed to click "Attach Photo" button
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
	if(InputStatus = "Failed")
	{
		Message = Upload Failed:`nUnable to Find "Open File" window to input filepath into
		SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
		Return
	}
	*/
	SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")

	sleep, 10000
}


; Click the "Post" button
SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = (//button[normalize-space()='Post'])[1]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
if(Status){
	Message = Failed to Submit Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

IniWrite, Successful, %StatusFileFilePath%, Status, MeWe
AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()
DevModeMsgBox("done!")


Return
; -------------------------------/MeWe-------------------------------

; -------------------------------Twetch-------------------------------
TwetchAttemptNumber := 1
PostToTwetch:
CurrentSite := "Twetch"

; if(StrLen(PostTitleAndBody) > 256){
	; 	Message = Post Skipped as it's longer than 256 Characters
	; 	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
	; 	IniWrite, Skipped - Too Long, %StatusFileFilePath%, Status, Twetch
	; 	Return
	; }


	SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	URLAttempt := NavigateFromBaseURLTo("https://twetch.com/")
	if(URLAttempt = "Failed")
	Return

	sleep, 1000

	Message = Checking Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	try CurrentTabURL := driver.Url
	if(InStr(CurrentTabURL, "/welcome")){
		Message = Login Cookies Expired. Trying to Re-Login
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

		sleep, 2000 ; 2 seconds for password to get loaded in by chrome

		Xpath = //button[@type='submit'][normalize-space()='Sign in']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			SaveOrPostProgress(Message:="Failed to Login. Please Login Manually",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			SaveDriverURLOFErrorPage()
			Return
		}

		Message = Waiting for Page to finish loading
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
		sleep, 2000
		driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
	}



	; SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
	; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	; URLAttempt := NavigateFromBaseURLTo("https://twetch.com/")
	; if(URLAttempt = "Failed")
	; Return

	; Message =


	; Click on "Create Post"
	SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")

/*Xpath = //textarea[@id='downshift-post-editor-default-input']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}
*/

; Click into text input box at top of page
Xpath = //p[@data-slate-node='element']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)



; Input Post contents
Xpath = //div[@role='textbox']
status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=5000,SendKeysContent:=PostTitleAndBody)
if(Status){
	Message =  Failed to Input Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	; TakeScreenshotOfPage()
	SaveDriverURLOFErrorPage()
	Return
}

; DevModeMsgBox("input?")

if(ImageAttachmentFilepath != ""){
	; Click "Image" button
	SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //input[@id='rich-file-input']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
	if(Status){
		Message = Failed to Attach Image
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}

	SaveOrPostProgress(Message:="Waiting 5 Seconds for Image to Upload ",PostType:="Tooltip,ErrorLoggingTextFile")
	sleep, 5000
}



; Click on "Post" button
sleep, 2000

SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")

Xpath = //button[normalize-space()='Post $0.02']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=4,SleepLength:=1000)
if(Status){
	Message = Failed to click on Submit Post Button
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

sleep, 1000 

Xpath = //p[normalize-space()='Insufficient wallet balance']
try, FundsStatus := driver.findelementbyxpath(Xpath).Attribute("innerText") ; Grabb innertext
if(FundsStatus){
	Message = Insufficient wallet balance to post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	IniWrite, Insufficient wallet balance to post, %StatusFileFilePath%, Status, Twetch
	Return
}


IniWrite, Successful, %StatusFileFilePath%, Status, Twetch
AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()
DevModeMsgBox("done!")


Return
; -------------------------------/Twetch-------------------------------


; -------------------------------Flote-------------------------------
PostToFlote:
CurrentSite := "Flote"


SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


URLAttempt := NavigateFromBaseURLTo("https://flote.app/")
if(URLAttempt = "Failed")
Return


SaveOrPostProgress(Message:="Inputting Text",PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 1000


; Click button to select text input box
Xpath = //input[@placeholder='Share whatever flotes your boat..']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
if(Status){
	; if error, then try clicking on "Login" button at the top right
	Message = Unable to Click "Write New Post" Button. Trying to Re-Login
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

	Xpath = //div[@class='nav-action-button blue-link half-padding-left half-padding-right white-space-no-wrap'] ; Log in button
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
	if(Status){ ; if failed to click login button
		SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		SaveDriverURLOFErrorPage()
		Return
	}
	else, { ; if login button was clicked successfully. try logging in
		sleep, 2000
		Xpath = //button[@class='submit-button ng-star-inserted']
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){ ; if failed to click login button, give error and quit
			SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			Return
		}
		Xpath = //div[@class='new-text-area'] ; start new post button
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
	}
}

sleep, 1000
; Wait for animation
; sleep, 5000

; Click into Title Inputbox
Xpath = //input[@placeholder='Title']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
	Message = Failed to click into title inputbox, Please check login status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

Message = Inputting Title
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; Input Title 
Xpath = //input[@placeholder='Title']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitle)

; Input Body
Message = Inputting Body
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //div[@class='ql-editor']//p
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostBody)

; DevModeMsgBox("testing")

if(ImageAttachmentFilepath != ""){
	; Click "Image" button
	SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

	; Click Attach image button
	Xpath = //*[@id="fileinput"]
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
	if(Status){
		Message = Failed to Attach Image
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
		Return
	}

	Message = Waiting for Image to Finish Uploading
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

	sleep, 5000
}

; DevModeMsgBox("test")

; Message = Waiting 5 seconds for website to catch up
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; sleep, 5000

Message = Submitting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

; button changes depending on if image is attached or not
if(ImageAttachmentFilepath) 
Xpath = //span[normalize-space()='Upload & Post']
else, 
Xpath = //span[normalize-space()='Post']


Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	SaveOrPostProgress(Message:="Failed to Click Submit Button. Please submit manually",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
}



IniWrite, Failed to Submit, %StatusFileFilePath%, Status, Flote
AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()
DevModeMsgBox("done!")


Return
; -------------------------------/Flote-------------------------------



; -------------------------------ThinkSpot-------------------------------
PostToThinkSpot:
CurrentSite := "Thinkspot"

if(PostTags = ""){
	Message = Skipped: No Post Tags
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
	IniWrite, Skipped: No Post Tags, %StatusFileFilePath%, Status, Thinkspot
	Return
}

SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")


URLAttempt := NavigateFromBaseURLTo("https://www.thinkspot.com/create/post")
if(URLAttempt = "Failed")
Return


Message = Checking Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

sleep, 1000
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, "/sign_in")){
	Message = Login Cookies Expired. Trying to Re-Login
	; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
	; SaveDriverURLOFErrorPage()
	; Return
	Xpath = //input[@name='commit']
	Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=1000)
	if(!Status){
		Message = Logged in Successfully
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

		Status := NavigateFromBaseURLTo("https://www.thinkspot.com/create/post")
		(Status)?(Return):()
		sleep, 2000
	}

}



/*
Xpath = //a[@href='/create/post']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	Message = Failed to Click "Create Post" button
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}

*/

; CLick into the title box of the new post window
Xpath = //div[@id='editorjs']//div[@class='ql-editor ql-blank']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	Message = Failed to Click Into Titlebox: Check Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}

sleep, 500

; Input the Post Title
SaveOrPostProgress(Message:="Inputting Post Title",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //input[@id='title']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostTitle)
if(Status){
	Message = Failed to Input Post Title: Check Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}

; Input post body
if(ImageAttachmentFilepath != "")
PostBody := PostBody . "`n"
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //div[@id='editorjs']//p
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostBody)
if(Status){
	Message = Failed to Input Post Body: Check Login Status
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}


; Input Post Tags
Xpath = //span[@role='textbox']
TagsArray := StrSplit(PostTags, ",")
TagsArrayLength := TagsArray.Length()   ; Save total number of items in the array
loop, %TagsArrayLength%{
	Tag := TagsArray[A_Index]

	Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=Tag)
	try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.ENTER)
}



if(ImageAttachmentFilepath != ""){
	; Click "Image" button
	SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

	; Insert image by sending it directly. 
	; elements aren't loaded until the attach image button is pressed though, so defeats the purpose
/*Xpath = //input[@class='ql-image']
try driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)

*/

Xpath = //button[@class='ql-image']
Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
if(Status){
	Message = Failed to click "Attach Image" button
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")

	Xpath = //input[@class='ql-image']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
	if(Status){
		Message = Failed to Attach Image (E#7611)
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}
}
else, {
	InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
	if(InputStatus = "Failed")
	{
		sleep, 2000
		Xpath = //i[@class='material-icons-outlined'][normalize-space()='image'] ; give it a second try :fingerscrossed:
		Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)

		InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
		if(InputStatus)
		{	; Try sending directly to element
			Xpath = //input[@class='ql-image']
			Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
			if(Status){
				Message = Failed to Attach Image (E#7612)
				SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
				Return
			}
		}
	}
	
}

SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")

sleep, 10000
}

; Click the Post button
SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //button[normalize-space()='Post']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	Message = Failed to Submit Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}


IniWrite, Successful, %StatusFileFilePath%, Status, Thinkspot
AddToTotalPostsPostedCount()



PauseBetweenPosts()
; TakeScreenshotOfPage()

; dismiss the pop up that appears for some reason
; try driver.switchToalert().accept()
DevModeMsgBox("done!")

Return
; -------------------------------/ThinkSpot-------------------------------




; -------------------------------Functions-------------------------------
#Include %A_ScriptDir%\Lib\SharedFunctions.ahk
#Include %A_ScriptDir%\Lib\Json.ahk
; #Include %A_scriptdir%\Lib\RunCMD.ahk


PauseBetweenPosts(){
	; TimeBetweenpostsInMiliseconds := PauseTimeBetweenPosts*1000
	Message = Waiting %PauseTimeBetweenPosts% seconds before Moving on To Next Site
	TooltipThis(Message)
	; Msgbox % "Message: " Message
	; Msgbox % "PauseTimeBetweenPosts: " PauseTimeBetweenPosts
	sleep, %TimeBetweenpostsInMiliseconds%
}


ReadWebsiteStatuses(){
	; Read status of each website and save them to variables to be used in GUI
	IniRead, Gettr, %StatusFileFilePath%, Status, Gettr, %A_Space%
	IniRead, Parler, %StatusFileFilePath%, Status, Parler, %A_Space%
	IniRead, Steemit, %StatusFileFilePath%, Status, Steemit, %A_Space%
	IniRead, Discord, %StatusFileFilePath%, Status, Discord, %A_Space%
	IniRead, SubScribeStar, %StatusFileFilePath%, Status, SubScribeStar, %A_Space%
	IniRead, Telegram, %StatusFileFilePath%, Status, Telegram, %A_Space%
	IniRead, Minds, %StatusFileFilePath%, Status, Minds, %A_Space%
	IniRead, Gab, %StatusFileFilePath%, Status, Gab, %A_Space%
	IniRead, Locals, %StatusFileFilePath%, Status, Locals, %A_Space%
	IniRead, LinkedIn, %StatusFileFilePath%, Status, LinkedIn, %A_Space%
	IniRead, MeWe, %StatusFileFilePath%, Status, MeWe, %A_Space%
	IniRead, Twetch, %StatusFileFilePath%, Status, Twetch, %A_Space%
	IniRead, ThinkSpot, %StatusFileFilePath%, Status, ThinkSpot, %A_Space%
	IniRead, Flote, %StatusFileFilePath%, Status, Flote, %A_Space%
	IniRead, PocketNet, %StatusFileFilePath%, Status, PocketNet, %A_Space%
	; IniRead, Pintrest, %StatusFileFilePath%, Status, Pintrest, %A_Space%
	; IniRead, Tumblr, %StatusFileFilePath%, Status, Tumblr, %A_Space%
}

; -------------------------------CreateErrorLoggingFiles-------------------------------
CreateErrorLoggingFiles(Path := ""){
	FormatTime, TodayDate, YYYYMMDDHH24MISS, yyyyMMdd_hhmmss

	ErrorLoggingDirectory := Path

	if(Path = ""){
		ErrorLoggingDirectory := A_ScriptDir . "\Lib\ErrorLogging"
		; If directory for error logging doesn't exist, create it
		if(!FileExist(ErrorLoggingDirectory))
		FileCreateDir, %ErrorLoggingDirectory%

		ErrorLoggingDirectory := ErrorLoggingDirectory . "\" . TodayDate . "_FSMP"
	}
	; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
	FileCreateDir, %ErrorLoggingDirectory%

	; Create variables with filepaths that content will be saved to.
	ErrorLoggingFilePath := ErrorLoggingDirectory . "\" . "ErrorLogging.txt"
	StatusFileFilePath := ErrorLoggingDirectory . "\" . "PostStatus.ini"
	PostTitleFilePath := ErrorLoggingDirectory . "\" . "PostTitle.txt"
	PostBodyFilePath := ErrorLoggingDirectory . "\" . "PostBody.txt"

	; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
	Return
}
; -------------------------------/CreateErrorLoggingFiles-------------------------------

AddToTotalPostsPostedCount(){
	IniRead, TotalPostsPosted, %SettingsIniFilepath%, SocialMediaPoster, TotalPostsPosted, 0
	TotalPostsPosted += 1
	IniWrite, %TotalPostsPosted%, %SettingsIniFilepath%, SocialMediaPoster, TotalPostsPosted
}

AddToTotalRunTime(){
	IniRead, TotalRunTime, %SettingsIniFilepath%, SocialMediaPoster, TotalRunTime, 0
	TotalRunTime := Round(TotalRunTime + ScriptRunTime),2
	; TotalRunTime += ScriptRunTime
	IniWrite, %TotalRunTime%, %SettingsIniFilepath%, SocialMediaPoster, TotalRunTime

}

OnMsgBoxConfirmPost() {
	DetectHiddenWindows, On
	Process, Exist
	If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
		WinMove,, 0
	}
}



