import os
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")

html = open("index_main.html", encoding="utf-8").read()

# 错误：let favs=JSON.parse(localStorage.getItem("nxf_favs"))||"[]");
# 正确：let favs=JSON.parse(localStorage.getItem("nxf_favs")||"[]");
bad = 'let favs=JSON.parse(localStorage.getItem("nxf_favs"))||"[]");'
good = 'let favs=JSON.parse(localStorage.getItem("nxf_favs")||"[]");'

if bad in html:
    html = html.replace(bad, good)
    print("已修复 favs 括号")
else:
    print("未找到错误模式")

# 同样检查 notes
bad2 = 'let notes=JSON.parse(localStorage.getItem("nxf_notes"))||"[]");'
good2 = 'let notes=JSON.parse(localStorage.getItem("nxf_notes")||"[]");'
if bad2 in html:
    html = html.replace(bad2, good2)
    print("已修复 notes 括号")

with open("index_main.html", "w", encoding="utf-8") as f:
    f.write(html)
print(f"文件已写回，大小: {os.path.getsize('index_main.html')} bytes")
