import re # 1. CSS Injection css_to_add = """ /* Light Theme Variables */ [data-theme="light"] { --bayan-bg: #f9fafb; --bayan-surface: #ffffff; --bayan-surface-hover: #f3f4f6; --bayan-surface-active: #e5e7eb; --bayan-border: #e5e7eb; --bayan-border-light: #d1d5db; --bayan-text: #111827; --bayan-text-secondary: #4b5563; --bayan-text-muted: #9ca3af; --bayan-success: #16a34a; --bayan-warning: #d97706; } /* Theme Toggle Button Styles */ .theme-toggle-animated { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: none; border-radius: 50%; background: var(--bayan-surface-hover); color: var(--bayan-text-secondary); cursor: pointer; transition: background 0.3s ease, transform 0.3s ease, color 0.3s ease; position: relative; overflow: hidden; margin-right: 8px; } .theme-toggle-animated:hover { background: var(--bayan-primary); color: #fff; transform: rotate(15deg); } .theme-toggle-animated svg { transition: transform 0.4s ease, opacity 0.3s ease; position: absolute; } [data-theme="dark"] .theme-icon-sun { transform: rotate(90deg) scale(0); opacity: 0; } [data-theme="dark"] .theme-icon-moon { transform: rotate(0) scale(1); opacity: 1; } [data-theme="light"] .theme-icon-moon { transform: rotate(-90deg) scale(0); opacity: 0; } [data-theme="light"] .theme-icon-sun { transform: rotate(0) scale(1); opacity: 1; } """ def append_to_file(filepath, content): with open(filepath, 'a', encoding='utf-8') as f: f.write('\n' + content + '\n') append_to_file('extension/popup.css', css_to_add) append_to_file('extension/sidepanel/sidepanel.css', css_to_add) # 2. HTML Injection btn_html = """ """ def insert_html_button(filepath, pattern): with open(filepath, 'r', encoding='utf-8') as f: html = f.read() # We want to put the button next to the status indicator. # The pattern will match the
(or sp-) and inject the button right before it new_html = re.sub(pattern, btn_html + r'\1', html) with open(filepath, 'w', encoding='utf-8') as f: f.write(new_html) insert_html_button('extension/popup.html', r'(
{ const toggleBtn = document.getElementById('ext-theme-toggle'); // Load theme from storage chrome.storage.local.get(['theme'], (result) => { const currentTheme = result.theme || 'dark'; // default to dark document.documentElement.setAttribute('data-theme', currentTheme); }); if (toggleBtn) { toggleBtn.addEventListener('click', () => { let theme = document.documentElement.getAttribute('data-theme') || 'dark'; let targetTheme = theme === 'dark' ? 'light' : 'dark'; document.documentElement.setAttribute('data-theme', targetTheme); chrome.storage.local.set({ theme: targetTheme }); }); } }); """ append_to_file('extension/popup.js', js_to_add) append_to_file('extension/sidepanel/sidepanel.js', js_to_add) print("Theme toggle added successfully.")