|
|
|
|
|
|
|
|
|
|
|
(() => {
|
|
|
const LOG = "[C2M-FIX]";
|
|
|
const nativeFetch = window.fetch.bind(window);
|
|
|
|
|
|
const isProvincesUrl = (u) => {
|
|
|
try {
|
|
|
const url = new URL(u, location.href);
|
|
|
const p = url.pathname || "";
|
|
|
return (
|
|
|
p.endsWith("/provinces") ||
|
|
|
p.endsWith("/api/provinces") ||
|
|
|
p.includes("/provinces?")
|
|
|
);
|
|
|
} catch {
|
|
|
const s = String(u || "");
|
|
|
return s.includes("provinces");
|
|
|
}
|
|
|
};
|
|
|
|
|
|
window.fetch = function patchedFetch(input, init) {
|
|
|
const url = typeof input === "string" ? input : (input && input.url) || "";
|
|
|
|
|
|
|
|
|
if (isProvincesUrl(url)) {
|
|
|
console.info(`${LOG} redirect provinces -> ./provinces.json`);
|
|
|
return nativeFetch("./provinces.json", { cache: "no-store" });
|
|
|
}
|
|
|
|
|
|
return nativeFetch(input, init);
|
|
|
};
|
|
|
|
|
|
console.info(`${LOG} installed (root, no folders).`);
|
|
|
})();
|
|
|
|