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

// Replace db.js with db_server.js  
const oldDb = 'src="db.js?v=1780588256193"';
const newDb = 'src="db_server.js?v=' + now + '"';
if (html.includes(oldDb)) {
  html = html.replace(oldDb, newDb);
  console.log('Replaced db.js with db_server.js');
} else {
  // Try without version
  const oldDb2 = 'src="db.js"';
  if (html.includes(oldDb2)) {
    html = html.replace(oldDb2, newDb);
    console.log('Replaced db.js (no version) with db_server.js');
  } else {
    console.log('WARNING: db.js reference not found');
    // Show what db script looks like
    const idx = html.indexOf('db.js');
    if (idx > -1) console.log('Found db.js at:', html.substring(idx - 10, idx + 50));
  }
}

fs.writeFileSync('index.html', html);
console.log('Done. Version: ' + now);
