81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
import json
|
|
import os
|
|
import platform
|
|
import sqlite3
|
|
|
|
"""
|
|
WARNING:
|
|
1. Functions from this script assume that no account is registered on Chrome, otherwise the default file path needs to be changed.
|
|
2. The functions are not tested on Windows and Mac, but they should work.
|
|
"""
|
|
|
|
|
|
# todo: move to getter module
|
|
|
|
def get_default_search_engine():
|
|
if platform.system() == 'Windows':
|
|
preference_file_path = os.path.join(os.getenv('LOCALAPPDATA'),
|
|
'Google\\Chrome\\User Data\\Default\\Preferences')
|
|
elif platform.system() == 'Darwin':
|
|
preference_file_path = os.path.join(os.getenv('HOME'),
|
|
'Library/Application Support/Google/Chrome/Default/Preferences')
|
|
else:
|
|
preference_file_path = os.path.join(os.getenv('HOME'), '.config/google-chrome/Default/Preferences')
|
|
|
|
try:
|
|
with open(preference_file_path, 'r', encoding='utf-8') as file:
|
|
data = json.load(file)
|
|
|
|
# The path within the JSON data to the default search engine might vary
|
|
search_engine = data.get('default_search_provider_data', {}).get('template_url_data', {}).get('short_name',
|
|
'Google')
|
|
return search_engine
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
return "Google"
|
|
|
|
|
|
def get_cookie_data():
|
|
if platform.system() == 'Windows':
|
|
chrome_cookie_file_path = os.path.join(os.getenv('LOCALAPPDATA'), 'Google\\Chrome\\User Data\\Default\\Cookies')
|
|
elif platform.system() == 'Darwin':
|
|
chrome_cookie_file_path = os.path.join(os.getenv('HOME'),
|
|
'Library/Application Support/Google/Chrome/Default/Cookies')
|
|
else:
|
|
chrome_cookie_file_path = os.path.join(os.getenv('HOME'), '.config/google-chrome/Default/Cookies')
|
|
|
|
try:
|
|
conn = sqlite3.connect(chrome_cookie_file_path)
|
|
cursor = conn.cursor()
|
|
|
|
# Query to check for OpenAI cookies
|
|
cursor.execute("SELECT * FROM cookies")
|
|
cookies = cursor.fetchall()
|
|
|
|
return cookies
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
return None
|
|
|
|
|
|
def get_bookmarks():
|
|
if platform.system() == 'Windows':
|
|
preference_file_path = os.path.join(os.getenv('LOCALAPPDATA'),
|
|
'Google\\Chrome\\User Data\\Default\\Bookmarks')
|
|
elif platform.system() == 'Darwin':
|
|
preference_file_path = os.path.join(os.getenv('HOME'),
|
|
'Library/Application Support/Google/Chrome/Default/Bookmarks')
|
|
else:
|
|
preference_file_path = os.path.join(os.getenv('HOME'), '.config/google-chrome/Default/Bookmarks')
|
|
|
|
try:
|
|
with open(preference_file_path, 'r', encoding='utf-8') as file:
|
|
data = json.load(file)
|
|
|
|
bookmarks = data.get('roots', {})
|
|
return bookmarks
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
return None
|