import os
import glob

html_files = glob.glob('*.html')
missing_main_js = []

for h in html_files:
    with open(h, 'r', encoding='utf-8') as f:
        content = f.read()
    if 'js/main.js' not in content:
        missing_main_js.append(h)
        # Inject before </body>
        if '</body>' in content:
            content = content.replace('</body>', '    <script src="js/main.js"></script>\n</body>')
            with open(h, 'w', encoding='utf-8') as f:
                f.write(content)
            print(f"Injected js/main.js into {h}")

print(f"Processed {len(html_files)} files. Previously missing: {len(missing_main_js)}")
