Add hub iframe embed shell with tab fragment API.
Replace full-page soft nav with a persistent shell and /api/embed/page loads so tab switches in the hub iframe avoid document.write flicker. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Build embed_page_fragment.html from gate index.html."""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
src_lines = (ROOT / "crypto_monitor_gate" / "templates" / "index.html").read_text(
|
||||
encoding="utf-8"
|
||||
).splitlines()
|
||||
|
||||
# 1-based line numbers from index.html
|
||||
macro_body = src_lines[243:262] # {% macro %} … {% endmacro %}
|
||||
grid_inner = src_lines[328:736] # inside .grid (exclude outer wrapper)
|
||||
stats_block = src_lines[738:772]
|
||||
|
||||
out_lines = [
|
||||
"{# Hub iframe tab fragment — shared via embed_templates #}",
|
||||
*macro_body,
|
||||
'<div class="grid">',
|
||||
*grid_inner,
|
||||
"</div>",
|
||||
*stats_block,
|
||||
]
|
||||
|
||||
out_dir = ROOT / "embed_templates"
|
||||
out_dir.mkdir(exist_ok=True)
|
||||
text = "\n".join(out_lines) + "\n"
|
||||
text = text.replace(
|
||||
"{% include 'order_monitor_rule_tips_gate.html' %}",
|
||||
"{% include order_rule_tips_tpl %}",
|
||||
)
|
||||
(out_dir / "embed_page_fragment.html").write_text(text, encoding="utf-8")
|
||||
print("wrote", out_dir / "embed_page_fragment.html", "lines", len(out_lines))
|
||||
@@ -0,0 +1,49 @@
|
||||
"""One-off: extract instance_page.css / instance_page_boot.js from gate index.html."""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
src = ROOT / "crypto_monitor_gate" / "templates" / "index.html"
|
||||
text = src.read_text(encoding="utf-8")
|
||||
|
||||
m = re.search(r"<style>(.*?)</style>", text, re.S)
|
||||
if m:
|
||||
(ROOT / "static" / "instance_page.css").write_text(m.group(1).strip() + "\n", encoding="utf-8")
|
||||
|
||||
marker = '<script src="/static/manual_order_rr_preview.js?v=3"></script>'
|
||||
if marker in text:
|
||||
part = text.split(marker, 1)[1]
|
||||
m2 = re.search(r"<script>(.*?)</script>\s*</body>", part, re.S)
|
||||
if m2:
|
||||
boot = m2.group(1).strip()
|
||||
boot = boot.replace(
|
||||
"setInterval(refreshAccountSnapshot, {{ balance_refresh_seconds * 1000 }});",
|
||||
"setInterval(refreshAccountSnapshot, Number(document.body.dataset.balanceRefreshMs || 30000));",
|
||||
)
|
||||
boot = boot.replace(
|
||||
"setInterval(refreshPriceSnapshotConditional, {{ price_refresh_seconds * 1000 }});",
|
||||
"setInterval(refreshPriceSnapshotConditional, Number(document.body.dataset.priceRefreshMs || 5000));",
|
||||
)
|
||||
(ROOT / "static" / "instance_page_boot.js").write_text(boot + "\n", encoding="utf-8")
|
||||
|
||||
part2 = text.split(marker, 1)[1]
|
||||
m3 = re.search(r"<script>(.*?)</script>\s*</body>", part2, re.S)
|
||||
if m3:
|
||||
boot_tpl = m3.group(1).strip()
|
||||
boot_tpl = boot_tpl.replace(
|
||||
"setInterval(refreshAccountSnapshot, {{ balance_refresh_seconds * 1000 }});",
|
||||
"setInterval(refreshAccountSnapshot, Number(document.body.dataset.balanceRefreshMs || 30000));",
|
||||
)
|
||||
boot_tpl = boot_tpl.replace(
|
||||
"setInterval(refreshPriceSnapshotConditional, {{ price_refresh_seconds * 1000 }});",
|
||||
"setInterval(refreshPriceSnapshotConditional, Number(document.body.dataset.priceRefreshMs || 5000));",
|
||||
)
|
||||
embed_dir = ROOT / "embed_templates"
|
||||
embed_dir.mkdir(exist_ok=True)
|
||||
(embed_dir / "embed_boot_scripts.html").write_text(
|
||||
"<script>\n" + boot_tpl + "\n</script>\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
print("done")
|
||||
Reference in New Issue
Block a user