import sys path = "/home/slin/enduro-trails/prototype/static/app.js" with open(path, 'r') as f: content = f.read() # Add restoreTerrainState and restoreTrailsState to rebuildMapOverlays old = """function rebuildMapOverlays() { // Re-apply recon circle if active if (reconMode && reconCenter) {""" new = """function rebuildMapOverlays() { // Re-apply terrain and trails after style change restoreTerrainState(); restoreTrailsState(); // Re-apply recon circle if active if (reconMode && reconCenter) {""" if old not in content: print("ERROR: marker not found") sys.exit(1) content = content.replace(old, new) with open(path, 'w') as f: f.write(content) print("OK - rebuildMapOverlays patched")