CVNSS commited on
Commit
65a720c
·
verified ·
1 Parent(s): 99e382a

Upload hf-fix.js

Browse files
Files changed (1) hide show
  1. hf-fix.js +36 -0
hf-fix.js ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // hf-fix.js (ROOT)
2
+ // Chặn lỗi "No response from server" bằng cách ép provinces dùng file local provinces.json
3
+
4
+ (() => {
5
+ const LOG = "[C2M-FIX]";
6
+ const nativeFetch = window.fetch.bind(window);
7
+
8
+ const isProvincesUrl = (u) => {
9
+ try {
10
+ const url = new URL(u, location.href);
11
+ const p = url.pathname || "";
12
+ return (
13
+ p.endsWith("/provinces") ||
14
+ p.endsWith("/api/provinces") ||
15
+ p.includes("/provinces?")
16
+ );
17
+ } catch {
18
+ const s = String(u || "");
19
+ return s.includes("provinces");
20
+ }
21
+ };
22
+
23
+ window.fetch = function patchedFetch(input, init) {
24
+ const url = typeof input === "string" ? input : (input && input.url) || "";
25
+
26
+ // Ép mọi call provinces về local file
27
+ if (isProvincesUrl(url)) {
28
+ console.info(`${LOG} redirect provinces -> ./provinces.json`);
29
+ return nativeFetch("./provinces.json", { cache: "no-store" });
30
+ }
31
+
32
+ return nativeFetch(input, init);
33
+ };
34
+
35
+ console.info(`${LOG} installed (root, no folders).`);
36
+ })();