import re def insert_divider(file_path): with open(file_path, 'r', encoding='utf-8') as f: html = f.read() # We look for the logo img and the span title, and insert a divider between them. # Pattern to match: # بيان # بيان # Let's match the closing bracket of the img tag (or its whitespace), followed by the span tag pattern = r'(]+>)\s*(بيان)' # The divider to insert: divider = '\n
\n ' # Replace new_html, count = re.subn(pattern, r'\1' + divider + r'\2', html) if count > 0: with open(file_path, 'w', encoding='utf-8') as f: f.write(new_html) print(f"Updated {file_path}") else: print(f"No match found in {file_path}") insert_divider('extension/popup.html') insert_divider('extension/sidepanel/sidepanel.html')