V.AISTUDIO / vai-excel-fix-simple.js
bep40's picture
Upload vai-excel-fix-simple.js
72eeaf4 verified
Raw
History Blame
1.32 kB
/**
* V.AI STUDIO - Excel Download Fix v1047
*
* FIX: Giữ blob URL sống đến khi unload để download thành công nhiều lần
*/
(function() {
'use strict';
// Lưu blob URLs
var blobUrls = [];
// Override URL.revokeObjectURL - hoãn revoke rất lâu
var originalRevoke = URL.revokeObjectURL;
URL.revokeObjectURL = function(url) {
if (url && url.startsWith('blob:')) {
// Chỉ đăng ký, không revoke ngay
var exists = blobUrls.find(function(e) { return e.url === url; });
if (!exists) {
blobUrls.push({ url: url, revoked: false });
}
return; // KHÔNG revoke - để download hoàn thành
}
return originalRevoke.call(this, url);
};
// Cleanup khi unload
window.addEventListener('pagehide', function() {
blobUrls.forEach(function(entry) {
if (!entry.revoked) {
try { originalRevoke.call(URL, entry.url); } catch (e) {}
entry.revoked = true;
}
});
});
// Patch window.URL.revokeObjectURL để hoàn toàn bỏ qua
if (!URL._vaiPatched) {
URL._vaiPatched = true;
console.log('[Excel Fix v1047] Loaded - multi-download support enabled');
}
})();