ac / beta_frontend.py
mendeld's picture
Upload 15 files
e46ad0b verified
Raw History Blame Contribute Delete
1.17 kB
"""Add the AC Beta controls to the existing stable fixed-height chat shell."""
from pathlib import Path
HERE=Path(__file__).parent
def enhance_frontend(page: str, *, is_admin: bool) -> str:
page=page.replace('</style>', '<style></style>\n</style>',1) if False else page
css=(HERE/'beta_ui.css').read_text(encoding='utf-8')
js=(HERE/'beta_ui.js').read_text(encoding='utf-8')
page=page.replace('</head>', '<style>'+css+'</style></head>',1)
page=page.replace('</body>', '<script>'+js+'</script></body>',1)
# Separate Head Admin browser archives from public/guest archives on the
# same origin. This must happen before any page script executes.
if is_admin:
css_google=(HERE/'google_dashboard_ui.css').read_text(encoding='utf-8')
js_google=(HERE/'google_dashboard_ui.js').read_text(encoding='utf-8')
page=page.replace('</head>', '<style>'+css_google+'</style></head>',1)
page=page.replace('</body>', '<script>'+js_google+'</script></body>',1)
for key in ('ac_archive','ac_current_history','ac_current_chat_id'):
page=page.replace(key, key.replace('ac_', 'ac_admin_', 1))
return page