Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- fix_btn.py +37 -0
fix_btn.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cat <<EOF > fix_btn.py
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
js_path = "script.js"
|
| 5 |
+
if os.path.exists(js_path):
|
| 6 |
+
with open(js_path, "r", encoding="utf-8") as f:
|
| 7 |
+
content = f.read()
|
| 8 |
+
|
| 9 |
+
injection = """
|
| 10 |
+
// --- Shensist Matrix 强力自愈注入 ---
|
| 11 |
+
const originalFetch = window.fetch;
|
| 12 |
+
window.fetch = async (...args) => {
|
| 13 |
+
try {
|
| 14 |
+
const response = await originalFetch(...args);
|
| 15 |
+
return response;
|
| 16 |
+
} catch (e) {
|
| 17 |
+
if (args[0].includes('7860') || e.message.includes('Failed to fetch')) {
|
| 18 |
+
console.warn("检测到后端离线,启用预设演播逻辑...");
|
| 19 |
+
return {
|
| 20 |
+
ok: true,
|
| 21 |
+
json: async () => ({
|
| 22 |
+
text: "【铁蝰蛇】: 维度屏障尚未完全开启,正在进行本地逻辑同步。\\n【九尾狐】: 灵愿循环已就绪,主理人,请指示下一场演播。"
|
| 23 |
+
})
|
| 24 |
+
};
|
| 25 |
+
}
|
| 26 |
+
throw e;
|
| 27 |
+
}
|
| 28 |
+
};
|
| 29 |
+
// ------------------------------------
|
| 30 |
+
"""
|
| 31 |
+
if "Shensist Matrix 强力自愈注入" not in content:
|
| 32 |
+
with open(js_path, "w", encoding="utf-8") as f:
|
| 33 |
+
f.write(injection + content)
|
| 34 |
+
print("✅ 脚本已注入灵魂容错机制。")
|
| 35 |
+
else:
|
| 36 |
+
print("ℹ️ 容错机制已存在。")
|
| 37 |
+
EOF
|