diff --git a/bin/muse-chat-api.py b/bin/muse-chat-api.py index cd7f49e..b4c71a2 100755 --- a/bin/muse-chat-api.py +++ b/bin/muse-chat-api.py @@ -207,22 +207,20 @@ def cmd_sidechat_use(ws, chat_id): print(f"Navigated to: {result}") def cmd_sidechat_main(ws): - """Navigate back to main chat by clicking the Main chat button.""" + """Navigate back to main chat by pressing the chat button.""" + # The chat button (not the sidebar search) properly refocuses Main Chat. # Do NOT navigate to https://muse.ai/ (landing page) - it restores the - # last-viewed chat which may be a side chat. Click Main chat instead. - # Uses fuzzy matching like cmd_sidechat_use (substring + shortest first). + # last-viewed chat which may be a side chat. js = ( "(async()=>{" - "const ob=[...document.querySelectorAll('button')].find(" - "b=>b.textContent.includes('Open chat and side chats'));" - "if(ob)ob.click();" - "await new Promise(r=>setTimeout(r,2000));" - "const els=[...document.querySelectorAll('*')];" - "const cands=els.filter(e=>e.textContent&&e.textContent.includes('Main chat'));" - "cands.sort((a,b)=>a.textContent.length-b.textContent.length);" - "const el=cands[0];" - "if(!el)return 'NOTFOUND';" - "el.click();" + # Find the chat button - it refocuses Main Chat when pressed + "const btns=[...document.querySelectorAll('button')];" + "const chatBtn=btns.find(b=>" + "b.textContent.includes('Open chat and side chats')||" + "b.getAttribute('aria-label')&&b.getAttribute('aria-label').toLowerCase().includes('chat')" + ");" + "if(!chatBtn)return 'NOBUTTON';" + "chatBtn.click();" "await new Promise(r=>setTimeout(r,4000));" "return window.location.href;" "})()"