خلي الاسكربت دا يبقا سريع 
# %%
# Import necessary libraries
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random

# Function to print messages with colors
def print_message(message, color="\033[92m"):  # Green color
    print(f"{color}{message}\033[0m")

# Setup Chrome options to disable automation flags and other settings
chrome_options = Options()
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-dev-shm-usage")

# Initialize the Chrome WebDriver with the options
webdriver_service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)

# Start of the script - Show welcome message
print_message("Starting the automation script...", "\033[96m")

# Open Google login page
driver.get("https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&hl=en&service=mail&flowName=GlifWebSignIn&flowEntry=AddSession")

# Identify the username input box and enter email
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "identifierId"))).send_keys("dkowkdatoskaka@gmail.com")
driver.find_element(By.XPATH, "//span[text()='Next']").click()

# Enter password and click 'Next'
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//input[@name="Passwd"]'))).send_keys("wdsawdsa325")
driver.find_element(By.XPATH, "//span[text()='Next']").click()

# Wait for the page to load after login
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="gbwa"]/div/a')))

# Navigate to Google Docs
driver.get("https://docs.google.com/document/u/0/")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id=":1i"]/div[1]/img'))).click()

# Wait for the page to load after clicking the image
print_message("Waiting for Share dialog to load...", "\033[96m")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="docs-titlebar-share-client-button"]/div[1]')))

# Click on "Share" button
print_message("Clicking on the Share button...", "\033[96m")
driver.find_element(By.XPATH, '//*[@id="docs-titlebar-share-client-button"]/div[1]').click()

# Wait for the Share dialog to open before pressing Tab and Enter
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="docs-titlebar-share-client-button"]/div[1]')))

# Simulate pressing Tab and Enter keys after page loads
print_message("Pressing Tab and then Enter...", "\033[96m")
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.TAB)  # Press Tab
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ENTER)  # Press Enter

# Click on "Skip" button immediately
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[72]/div[2]/div/div[2]/div[1]/button/span[5]'))).click()

# Click on a random location on the screen
screen_width = driver.execute_script("return window.innerWidth;")
screen_height = driver.execute_script("return window.innerHeight;")
random_x = random.randint(0, screen_width)
random_y = random.randint(0, screen_height)

# Perform the click action at the random location
action = ActionChains(driver)
action.move_by_offset(random_x, random_y).click().perform()

# Read emails from the list.txt file
emails = []
with open('list.txt', 'r') as file:
    emails = file.readlines()

# Trim any extra spaces or newlines from emails
emails = [email.strip() for email in emails]

# Fill in the email addresses in the share dialog
for email in emails:
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id=":x5"]/div/div/div[1]/input'))).send_keys(email)
    driver.find_element(By.XPATH, '//*[@id=":x5"]/div/div/div[1]/input').send_keys(Keys.RETURN)  # Press Enter to submit email

    WebDriverWait(driver, 2)

# Click on the "Send" button (or next step in dialog)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[72]/div[2]/div/div[2]/div[1]/button/span[5]'))).click()

# Keep the browser window open for 5 minutes after all actions
print_message("All actions complete. Keeping the browser open for 5 minutes.", "\033[92m")
WebDriverWait(driver, 300)  # Wait for 5 minutes

# Close the browser after 5 minutes
print_message("Closing the browser after 5 minutes.", "\033[91m")
driver.close()