Upload vai-excel-injector.js
Browse files- vai-excel-injector.js +98 -0
vai-excel-injector.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* V.AI STUDIO Excel Fix Injector
|
| 3 |
+
* Tự động inject fix script vào page nếu chưa có
|
| 4 |
+
*/
|
| 5 |
+
(function() {
|
| 6 |
+
'use strict';
|
| 7 |
+
|
| 8 |
+
// Check if already loaded
|
| 9 |
+
if (window.__VAI_EXCEL_FIX_APPLIED) return;
|
| 10 |
+
window.__VAI_EXCEL_FIX_APPLIED = true;
|
| 11 |
+
|
| 12 |
+
// Inject the fix script
|
| 13 |
+
var fixScript = document.createElement('script');
|
| 14 |
+
fixScript.src = '/vai-quote-excel-order-fix-v1050.js?v=1050';
|
| 15 |
+
fixScript.async = true;
|
| 16 |
+
fixScript.onload = function() {
|
| 17 |
+
console.log('[VAI FIX] Excel multi-download script loaded');
|
| 18 |
+
};
|
| 19 |
+
fixScript.onerror = function() {
|
| 20 |
+
console.error('[VAI FIX] Failed, applying inline fix...');
|
| 21 |
+
applyInlineFix();
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
var scripts = document.querySelectorAll('script');
|
| 25 |
+
var lastScript = scripts[scripts.length - 1];
|
| 26 |
+
if (lastScript && lastScript.parentNode) {
|
| 27 |
+
lastScript.parentNode.insertBefore(fixScript, lastScript.nextSibling);
|
| 28 |
+
} else {
|
| 29 |
+
document.head.appendChild(fixScript);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// Inline fix fallback
|
| 33 |
+
function applyInlineFix() {
|
| 34 |
+
window.__VAI_BLOB_REGISTRY = window.__VAI_BLOB_REGISTRY || { blobs: [], registry: [], isUnloading: false };
|
| 35 |
+
var registry = window.__VAI_BLOB_REGISTRY;
|
| 36 |
+
|
| 37 |
+
function cleanup() {
|
| 38 |
+
registry.isUnloading = true;
|
| 39 |
+
registry.blobs.forEach(function(b) { if (!b.revoked && b.url) try { URL.revokeObjectURL(b.url); b.revoked = true; } catch(e) {} });
|
| 40 |
+
}
|
| 41 |
+
window.addEventListener('pagehide', cleanup);
|
| 42 |
+
window.addEventListener('beforeunload', cleanup);
|
| 43 |
+
|
| 44 |
+
if (!window.__VAI_REVOKE_PATCHED) {
|
| 45 |
+
var orig = URL.revokeObjectURL;
|
| 46 |
+
URL.revokeObjectURL = function(url) {
|
| 47 |
+
if (!registry.isUnloading && url && url.startsWith('blob:')) {
|
| 48 |
+
if (!registry.registry.find(function(e) { return e.url === url; })) {
|
| 49 |
+
registry.registry.push({ url: url, revoked: false });
|
| 50 |
+
}
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
return orig.apply(this, arguments);
|
| 54 |
+
};
|
| 55 |
+
window.__VAI_REVOKE_PATCHED = true;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function setBtnState(btn, exporting) {
|
| 59 |
+
if (!btn) return;
|
| 60 |
+
if (exporting) {
|
| 61 |
+
btn.disabled = true;
|
| 62 |
+
btn.dataset.vaiExporting = '1';
|
| 63 |
+
btn.dataset.vaiOrigText = btn.innerHTML;
|
| 64 |
+
btn.innerHTML = '<span style="opacity:0.7">⏳</span>';
|
| 65 |
+
} else {
|
| 66 |
+
btn.disabled = false;
|
| 67 |
+
btn.dataset.vaiExporting = '0';
|
| 68 |
+
if (btn.dataset.vaiOrigText) btn.innerHTML = btn.dataset.vaiOrigText;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (typeof window.exportDeliveryExcel !== 'function') {
|
| 73 |
+
window.exportDeliveryExcel = async function(order) {
|
| 74 |
+
var btn = document.activeElement;
|
| 75 |
+
if (btn && btn.dataset.vaiExporting === '1') return;
|
| 76 |
+
setBtnState(btn, true);
|
| 77 |
+
try {
|
| 78 |
+
if (window.VAI_FIX && window.VAI_FIX.exportDeliveryExcel) {
|
| 79 |
+
await window.VAI_FIX.exportDeliveryExcel(order);
|
| 80 |
+
}
|
| 81 |
+
} finally {
|
| 82 |
+
setTimeout(function() { setBtnState(btn, false); }, 500);
|
| 83 |
+
}
|
| 84 |
+
};
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
})();
|
| 89 |
+
|
| 90 |
+
// Auto-execute
|
| 91 |
+
if (document.readyState !== 'loading') {
|
| 92 |
+
setTimeout(function() {
|
| 93 |
+
var s = document.createElement('script');
|
| 94 |
+
s.src = '/vai-quote-excel-order-fix-v1050.js?v=1050';
|
| 95 |
+
s.async = true;
|
| 96 |
+
document.head.appendChild(s);
|
| 97 |
+
}, 100);
|
| 98 |
+
}
|