import sys file_path = sys.argv[1] with open(file_path, 'r') as f: lines = f.readlines() new_lines = [] in_extra_links = False extra_links_replaced = False # We will replace the entire ExtraLinks function extra_links_code = """ function ExtraLinks() { const {_} = useLingui() const t = useTheme() const kawaii = useKawaiiMode() const navigation = useNavigation() return ( navigation.navigate('TermsOfService')}> Terms of Service navigation.navigate('PrivacyPolicy')}> Privacy Policy {kawaii && ( Logo by{' '} @sawaratsuki.bsky.social )} ) } """ for line in lines: if 'function ExtraLinks() {' in line: in_extra_links = True new_lines.append(extra_links_code) continue if in_extra_links: if line.strip() == '}': in_extra_links = False # Don't append the closing brace because extra_links_code includes it? # Wait, extra_links_code includes the whole function. # So we skip everything until LAST closing brace of function. # Simple heuristic: indentation. continue new_lines.append(line) with open(file_path, 'w') as f: f.write(''.join(new_lines))