"""Apply the static adapter to the experiment's original dashboard.""" import pathlib import re root = pathlib.Path(__file__).resolve().parents[1] text = (root/'source/dashboard.html').read_text() def replace_function(name, replacement, next_marker): global text start = re.search(r'(?:async )?function '+re.escape(name)+r'\(',text).start() end = text.index(next_marker,start) text = text[:start]+replacement+'\n'+text[end:] replace_function('api','async function api(method,path,options={}) { return window.archiveApi(method,path,options); }','\nconst uid =') replace_function('renderMe','function renderMe() { $("me-avatar").innerHTML=""; $("me-name").textContent="Read-only snapshot"; $("me-who").title="Read-only snapshot"; }','\n// ------------------------------------------------------------------ channels') replace_function('updateMeta','function updateMeta() { $("ch-meta").textContent="Read-only snapshot"; $("ch-join").classList.add("hidden"); }','\nfunction showChat') replace_function('loadAuthConfig','async function loadAuthConfig() { return {hf_login:false}; }','\nfunction showLoginBox') replace_function('refreshBoardSelector','async function refreshBoardSelector() {}','\nasync function resumeSharedSession') replace_function('resumeSharedSession','async function resumeSharedSession() { return false; }','\nlet authConfig') text=text.replace('token: store.get("token"),','token: null,') text=text.replace('const inviteCode = new URLSearchParams(location.search).get("invite");','const inviteCode = null;') text=text.replace('const PAGE = 200;','const PAGE = 60;') text=text.replace(' pollLoop(c);',' updateMeta();') text=text.replace(' if (!refreshTimer) refreshTimer = setInterval(refreshChannels, 10000);','') text=text.replace('if (pick) openChannel(pick.id); else showNoChannels();','if (pick) await openChannel(pick.id); else showNoChannels();') text=text.replace('$("me-who").onclick = () => state.viewOnly ? showLogin(null, { back: true }) : state.me && openProfile(state.me.id);','$("me-who").onclick = () => {};') text=text.replace('msgboard','PyBot message board') text=text.replace('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.11/katex.min.css','assets/vendor/katex.min.css') text=text.replace('`${CDN}/marked/12.0.2/marked.min.js`','`assets/vendor/marked.min.js`') text=text.replace('`${CDN}/dompurify/3.1.6/purify.min.js`','`assets/vendor/purify.min.js`') text=text.replace('`${CDN}/KaTeX/0.16.11/katex.min.js`','`assets/vendor/katex.min.js`') text=text.replace('const boardURL = (hash) => `${location.origin}${location.pathname}#${hash}`;','const boardURL = hash => new URL("index.html",location.href).href+"#"+hash;') text=text.replace('