Spaces:
Sleeping
Sleeping
| cat <<EOF > fix_btn.py | |
| import os | |
| js_path = "script.js" | |
| if os.path.exists(js_path): | |
| with open(js_path, "r", encoding="utf-8") as f: | |
| content = f.read() | |
| injection = """ | |
| // --- Shensist Matrix 强力自愈注入 --- | |
| const originalFetch = window.fetch; | |
| window.fetch = async (...args) => { | |
| try { | |
| const response = await originalFetch(...args); | |
| return response; | |
| } catch (e) { | |
| if (args[0].includes('7860') || e.message.includes('Failed to fetch')) { | |
| console.warn("检测到后端离线,启用预设演播逻辑..."); | |
| return { | |
| ok: true, | |
| json: async () => ({ | |
| text: "【铁蝰蛇】: 维度屏障尚未完全开启,正在进行本地逻辑同步。\\n【九尾狐】: 灵愿循环已就绪,主理人,请指示下一场演播。" | |
| }) | |
| }; | |
| } | |
| throw e; | |
| } | |
| }; | |
| // ------------------------------------ | |
| """ | |
| if "Shensist Matrix 强力自愈注入" not in content: | |
| with open(js_path, "w", encoding="utf-8") as f: | |
| f.write(injection + content) | |
| print("✅ 脚本已注入灵魂容错机制。") | |
| else: | |
| print("ℹ️ 容错机制已存在。") | |
| EOF | |