const fs = require('fs');
let html = fs.readFileSync('index.html', 'utf8');

// replace script tags at the bottom to have charset="utf-8"
html = html.replace('<script src="db.js?v=202606030939"></script>', '<script src="db.js?v=202606030939" charset="utf-8"></script>');
html = html.replace('<script src="app_final.js?v=202606030939" defer></script>', '<script src="app_final.js?v=202606030939" charset="utf-8" defer></script>');
html = html.replace('<script src="vouchers_returns.js?v=202606030939" defer></script>', '<script src="vouchers_returns.js?v=202606030939" charset="utf-8" defer></script>');
html = html.replace('<script src="sales_purchases_module.js?v=202606030939" defer></script>', '<script src="sales_purchases_module.js?v=202606030939" charset="utf-8" defer></script>');
html = html.replace('<script src="subcontracts.js?v=new" defer></script>', '<script src="subcontracts.js?v=new" charset="utf-8" defer></script>');

fs.writeFileSync('index.html', html, 'utf8');
console.log('Added charset="utf-8" safely');
