const fs = require('fs');
const path = require('path');
const dir = 'e:/my new site';
const files = fs.readdirSync(dir).filter(f => f.endsWith('.html')).map(f => path.join(dir, f));

files.forEach(file => {
    let content = fs.readFileSync(file, 'utf8');
    
    // Remove all <footer>...</footer>
    content = content.replace(/<footer[\s\S]*?<\/footer>/g, '');
    
    // Remove old backToTop button if present
    content = content.replace(/<button[^>]*id="backToTop"[^>]*>[\s\S]*?<\/button>/g, '');
    
    // Check if script is already injected
    if (!content.includes('assets/js/footer.js')) {
        content = content.replace(/<\/body>/, '<script src="assets/js/footer.js"></script>\n</body>');
    }
    
    fs.writeFileSync(file, content, 'utf8');
    console.log('Patched ' + file);
});
