import os templates_to_update = [ 'src/main/resources/templates/dao-tao-detail.html', 'src/main/resources/templates/posts/full-width.html', 'src/main/resources/templates/posts/livestream.html', 'src/main/resources/templates/posts/sidebar.html', 'src/main/resources/templates/posts/standard.html' ] switch_script = """ """ for filepath in templates_to_update: if not os.path.exists(filepath): continue with open(filepath, 'r', encoding='utf-8') as f: content = f.read() if "document.addEventListener('click', function(e) {" not in content: content = content.replace("", switch_script + "") with open(filepath, 'w', encoding='utf-8') as f: f.write(content) print(f"Added script to {filepath}") else: print(f"Script already in {filepath}")