bep40 commited on
Commit
1ac45dd
·
verified ·
1 Parent(s): 7767bf9

Upload auto-excel-fix-loader.js

Browse files
Files changed (1) hide show
  1. auto-excel-fix-loader.js +29 -14
auto-excel-fix-loader.js CHANGED
@@ -1,17 +1,21 @@
1
  /**
2
  * V.AI STUDIO - Auto Excel Fix Loader v2.0
3
  * Tự động tải fix script nếu chưa có, inject vào cuối body
 
 
4
  */
5
  (function() {
6
  'use strict';
7
 
8
- // Kiểm tra xem file fix đã tồn tại chưa
9
- var fixFile = 'vai-quote-excel-order-fix-v1050.js';
 
10
 
11
  // Kiểm tra script đã load chưa
12
  function checkFixLoaded() {
13
- return typeof window.VAI_FIX !== 'undefined' ||
14
- document.querySelector('script[src*="vai-quote-excel-order-fix"]');
 
15
  }
16
 
17
  // Inject script tag
@@ -24,31 +28,42 @@
24
  var script = document.createElement('script');
25
  script.src = '/' + fixFile + '?v=' + Date.now();
26
  script.onload = function() {
27
- console.log('[Auto Loader] Excel fix script loaded successfully');
28
  };
29
  script.onerror = function() {
30
- console.warn('[Auto Loader] Failed to load fix script, using inline fallback');
31
- applyInlineFix();
 
 
 
 
 
32
  };
33
 
34
  document.head.appendChild(script);
35
  }
36
 
37
- // Inline fix fallback
38
  function applyInlineFix() {
39
- // Patch URL.revokeObjectURL
40
  var originalRevoke = URL.revokeObjectURL;
41
  URL.revokeObjectURL = function(url) {
42
- if (url && url.startsWith('blob:')) {
43
- setTimeout(function() {
44
- try { originalRevoke.call(URL, url); } catch(e) {}
45
- }, 300000);
 
 
 
 
 
 
 
46
  return;
47
  }
48
  return originalRevoke.apply(this, arguments);
49
  };
50
 
51
- console.log('[Auto Loader] Inline fix applied');
52
  }
53
 
54
  // Chờ DOM ready
 
1
  /**
2
  * V.AI STUDIO - Auto Excel Fix Loader v2.0
3
  * Tự động tải fix script nếu chưa có, inject vào cuối body
4
+ *
5
+ * CẬP NHẬT: Hỗ trợ cả fix v2.0 - multi-download hoàn hảo
6
  */
7
  (function() {
8
  'use strict';
9
 
10
+ // Kiểm tra xem file fix đã tồn tại chưa - ưu tiên v2
11
+ var fixFile = 'vai-excel-fix-v2.js';
12
+ var fixFileLegacy = 'vai-quote-excel-order-fix-v1050.js';
13
 
14
  // Kiểm tra script đã load chưa
15
  function checkFixLoaded() {
16
+ return (typeof window.VAI_EXCEL_FIX !== 'undefined') ||
17
+ (typeof window.VAI_FIX !== 'undefined') ||
18
+ document.querySelector('script[src*="vai-excel-fix"]');
19
  }
20
 
21
  // Inject script tag
 
28
  var script = document.createElement('script');
29
  script.src = '/' + fixFile + '?v=' + Date.now();
30
  script.onload = function() {
31
+ console.log('[Auto Loader] Excel fix v2 loaded successfully - multi-download enabled');
32
  };
33
  script.onerror = function() {
34
+ console.warn('[Auto Loader] v2 failed, trying legacy fix');
35
+ var legacy = document.createElement('script');
36
+ legacy.src = '/' + fixFileLegacy + '?v=' + Date.now();
37
+ legacy.onload = function() {
38
+ console.log('[Auto Loader] Legacy fix loaded');
39
+ };
40
+ document.head.appendChild(legacy);
41
  };
42
 
43
  document.head.appendChild(script);
44
  }
45
 
46
+ // Inline fix fallback (backup)
47
  function applyInlineFix() {
 
48
  var originalRevoke = URL.revokeObjectURL;
49
  URL.revokeObjectURL = function(url) {
50
+ if (!url || typeof url !== 'string') return originalRevoke.apply(this, arguments);
51
+ if (url.startsWith('blob:')) {
52
+ // Register but don't revoke immediately - blob persists until unload
53
+ window.__VAI_BLOB_REGISTRY = window.__VAI_BLOB_REGISTRY || { blobs: [], isUnloading: false };
54
+ window.__VAI_BLOB_REGISTRY.blobs.push({ url: url, revoked: false });
55
+ window.addEventListener('beforeunload', function() {
56
+ window.__VAI_BLOB_REGISTRY.isUnloading = true;
57
+ window.__VAI_BLOB_REGISTRY.blobs.forEach(function(b) {
58
+ if (!b.revoked) try { URL.revokeObjectURL(b.url); b.revoked = true; } catch(e) {}
59
+ });
60
+ });
61
  return;
62
  }
63
  return originalRevoke.apply(this, arguments);
64
  };
65
 
66
+ console.log('[Auto Loader] Inline fallback applied');
67
  }
68
 
69
  // Chờ DOM ready