const fs = require('fs');
const iconv = require('iconv-lite');

let corrupted = fs.readFileSync('d:/برنامج مخازن/index.html');
let str = corrupted.toString('utf8');

// The file was read by PowerShell using win1256, so the UTF-8 bytes are actually win1256 encoded characters!
let buf1256 = iconv.encode(str, 'win1256');

// buf1256 now contains the raw bytes of the original UTF-8 file!
// Let's verify by checking the string
let recovered = buf1256.toString('utf8');

// There are a few characters at the very beginning `??` because of BOM maybe.
if (recovered.startsWith('??')) {
    recovered = recovered.substring(2);
}

// Bust cache again just to be sure
const version = Date.now().toString();
recovered = recovered.replace(/v=\d+/g, 'v=' + version);

fs.writeFileSync('d:/برنامج مخازن/index.html', recovered, 'utf8');
console.log('Successfully recovered index.html!');
