| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"><head><meta charset="utf-8"> |
| 3 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 4 | <title>codex</title> |
| 5 | <!--TOKENS--> |
| 6 | <style> |
| 7 | *{box-sizing:border-box} |
| 8 | html,body{margin:0;min-height:100%} |
| 9 | body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px; |
| 10 | line-height:1.5;-webkit-font-smoothing:antialiased} |
| 11 | #app{max-width:840px;margin:0 auto;padding:16px 16px 40px} |
| 12 | .hd{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px} |
| 13 | .hd .grow{flex:1 1 auto;min-width:0} |
| 14 | .hd h1{margin:0;font-size:18px;font-weight:650;letter-spacing:-.01em} |
| 15 | .hd .sub{font-size:11.5px;color:var(--text-2);margin-top:2px;white-space:nowrap; |
| 16 | overflow:hidden;text-overflow:ellipsis} |
| 17 | .pill{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;font-weight:650; |
| 18 | padding:4px 10px;border-radius:999px;background:var(--surface-2);color:var(--text-2); |
| 19 | border:1px solid var(--line);white-space:nowrap} |
| 20 | .pill .dot{width:7px;height:7px;border-radius:50%;background:var(--gray);flex:0 0 auto} |
| 21 | .pill.ok{color:var(--green);border-color:rgba(48,209,88,.35)} |
| 22 | .pill.ok .dot{background:var(--green);box-shadow:0 0 0 3px rgba(48,209,88,.15)} |
| 23 | .pill.warn{color:var(--orange);border-color:rgba(255,159,10,.35)} |
| 24 | .pill.warn .dot{background:var(--orange)} |
| 25 | .pill.off .dot{background:var(--gray)} |
| 26 | .card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px; |
| 27 | padding:16px;margin-bottom:12px} |
| 28 | .card h2{margin:0 0 4px;font-size:13px;font-weight:700;letter-spacing:.08em; |
| 29 | text-transform:uppercase;color:var(--text-2)} |
| 30 | .card .lead{margin:0 0 12px;font-size:12.5px;color:var(--text-2)} |
| 31 | .row{display:flex;align-items:center;gap:8px;flex-wrap:wrap} |
| 32 | .btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:7px 16px; |
| 33 | font-weight:600;font-size:13px;cursor:pointer;font-family:inherit; |
| 34 | transition:transform .12s var(--ease),opacity .12s} |
| 35 | .btn:active{transform:scale(.98)} |
| 36 | .btn:disabled{opacity:.5;cursor:default} |
| 37 | .btn.ghost{background:var(--surface-2);color:var(--text);border:1px solid var(--line)} |
| 38 | .btn.ghost:hover{background:var(--surface-hover);border-color:var(--line-2)} |
| 39 | .btn.danger{background:transparent;color:var(--red);border:1px solid rgba(255,69,58,.35)} |
| 40 | a.btn{display:inline-flex;align-items:center;gap:6px;text-decoration:none} |
| 41 | .kv{display:grid;grid-template-columns:132px minmax(0,1fr);gap:6px 12px;font-size:13px} |
| 42 | .kv .k{color:var(--text-2);font-size:12px} |
| 43 | .kv .v{font-family:var(--mono);font-size:12px;word-break:break-all} |
| 44 | .kv .v.plain{font-family:var(--font);font-size:13px} |
| 45 | .step{display:none} |
| 46 | .step.on{display:block} |
| 47 | .hint{margin:10px 0 0;font-size:12px;color:var(--text-2)} |
| 48 | .note{font-size:12.5px;margin-top:10px;display:none} |
| 49 | .note.show{display:block} |
| 50 | .note.err{color:var(--red)} |
| 51 | .note.ok{color:var(--green)} |
| 52 | .count{font-size:34px;font-weight:700;letter-spacing:-.02em;line-height:1.1} |
| 53 | .count small{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:0} |
| 54 | .bar{height:6px;border-radius:999px;background:var(--surface-2);overflow:hidden;margin-top:10px} |
| 55 | .bar .fill{display:block;height:100%;background:var(--green);border-radius:999px; |
| 56 | transition:width .3s var(--ease)} |
| 57 | .bar.warn .fill{background:var(--orange)} |
| 58 | .bar.err .fill{background:var(--red)} |
| 59 | .codebox{margin:12px 0 0;padding:16px;border-radius:12px;background:var(--code-bg); |
| 60 | border:1px solid var(--line);text-align:center} |
| 61 | .codebox .code{font-family:var(--mono);font-size:30px;font-weight:700;letter-spacing:.14em; |
| 62 | color:var(--text);margin-bottom:10px;word-break:break-all} |
| 63 | .codebox .code-empty{font-family:var(--mono);font-size:18px;color:var(--text-2); |
| 64 | letter-spacing:.08em} |
| 65 | .authurl{font-family:var(--mono);font-size:11.5px;color:var(--text-2);word-break:break-all; |
| 66 | background:var(--code-bg);border:1px solid var(--line);border-radius:10px; |
| 67 | padding:10px;margin-top:10px;max-height:120px;overflow:auto} |
| 68 | .pollbar{margin:12px 0 0;height:3px;border-radius:2px;background:var(--surface-2); |
| 69 | overflow:hidden} |
| 70 | .pollbar i{display:block;height:100%;width:0;background:var(--blue); |
| 71 | animation:pollslide 2s linear infinite} |
| 72 | @keyframes pollslide{0%{width:0}50%{width:100%}100%{width:0}} |
| 73 | .polllbl{font-size:11.5px;color:var(--text-2);margin:8px 0 0;display:flex;align-items:center;gap:6px} |
| 74 | .polllbl .spin{width:10px;height:10px;border-radius:50%;border:2px solid var(--line-2); |
| 75 | border-top-color:var(--blue);animation:spin 1s linear infinite;display:inline-block} |
| 76 | @keyframes spin{to{transform:rotate(360deg)}} |
| 77 | .acct{display:flex;align-items:center;gap:10px;padding:8px 0;border-top:1px solid var(--line); |
| 78 | font-size:13px;flex-wrap:wrap} |
| 79 | .acct:first-of-type{border-top:0} |
| 80 | .acct .nm{font-family:var(--mono);font-size:12px;flex:1 1 120px;min-width:0; |
| 81 | overflow:hidden;text-overflow:ellipsis} |
| 82 | .acct .tag{font-size:11px;color:var(--text-2)} |
| 83 | .acct .tag.ok{color:var(--green)} |
| 84 | .acct .tag.warn{color:var(--orange)} |
| 85 | .empty{padding:10px 0;color:var(--text-2);font-size:12.5px} |
| 86 | .toast{position:fixed;left:50%;bottom:18px;transform:translate(-50%,14px);opacity:0; |
| 87 | pointer-events:none;background:var(--modal-bg);border:1px solid var(--line-2); |
| 88 | color:var(--text);border-radius:999px;padding:8px 16px;font-size:12.5px; |
| 89 | box-shadow:var(--shadow-lg);transition:opacity .18s var(--ease),transform .18s var(--ease); |
| 90 | z-index:9;max-width:calc(100vw - 32px)} |
| 91 | .toast.show{opacity:1;transform:translate(-50%,0)} |
| 92 | #themeToggle{background:var(--surface-2);border:1px solid var(--line);color:var(--text); |
| 93 | border-radius:980px;padding:5px 12px;font-size:12px;font-weight:600;cursor:pointer; |
| 94 | font-family:inherit} |
| 95 | footer{display:flex;gap:10px;align-items:center;color:var(--text-2);font-size:11.5px; |
| 96 | margin-top:8px;flex-wrap:wrap} |
| 97 | @media (max-width:520px){ |
| 98 | #app{padding:12px 12px 32px} |
| 99 | .kv{grid-template-columns:1fr;gap:2px 0} |
| 100 | .kv .k{margin-top:8px} |
| 101 | .card{padding:13px;border-radius:12px} |
| 102 | .count{font-size:28px} |
| 103 | .codebox .code{font-size:22px;letter-spacing:.1em} |
| 104 | } |
| 105 | </style> |
| 106 | </head> |
| 107 | <body> |
| 108 | <div id="app"> |
| 109 | <div class="hd"> |
| 110 | <div class="grow"> |
| 111 | <h1>OpenAI Codex</h1> |
| 112 | <div class="sub" id="sub">Device code login on this node</div> |
| 113 | </div> |
| 114 | <span class="pill off" id="pill"><span class="dot"></span><span id="pillText">Checking</span></span> |
| 115 | <button id="themeToggle" class="embed-hide" type="button">Theme</button> |
| 116 | </div> |
| 117 | |
| 118 | <div class="card"> |
| 119 | <h2>Session</h2> |
| 120 | <p class="lead" id="sessionLead">Reading the local Codex credentials.</p> |
| 121 | <div class="count" id="count">-</div> |
| 122 | <div class="bar" id="bar"><span class="fill" id="fill" style="width:0%"></span></div> |
| 123 | <div class="kv" id="session" style="margin-top:14px"></div> |
| 124 | <div class="row" style="margin-top:14px"> |
| 125 | <button class="btn ghost" id="btnRefresh" type="button">Refresh Token Now</button> |
| 126 | <button class="btn ghost" id="btnStartLogin" type="button">Start Codex Login</button> |
| 127 | <button class="btn ghost" id="btnRelogin" type="button" hidden>Re-login (replace)</button> |
| 128 | <button class="btn ghost" id="btnReload" type="button">Reload</button> |
| 129 | </div> |
| 130 | <div class="note" id="sessionNote"></div> |
| 131 | </div> |
| 132 | |
| 133 | <div class="card"> |
| 134 | <h2>Device flow</h2> |
| 135 | <p class="lead">Codex signs in with a one-time user code. Copy it, open the link, approve, |
| 136 | and this panel updates itself.</p> |
| 137 | |
| 138 | <div class="step on" id="stepIdle"> |
| 139 | <div class="empty">No login in progress. Press <b>Start Codex Login</b> above to begin.</div> |
| 140 | </div> |
| 141 | |
| 142 | <div class="step" id="stepActive"> |
| 143 | <div class="codebox"> |
| 144 | <div class="code" id="userCode">--</div> |
| 145 | <div class="row" style="justify-content:center"> |
| 146 | <button class="btn" id="btnCopyOpen" type="button">Copy Code & Open OpenAI</button> |
| 147 | </div> |
| 148 | </div> |
| 149 | <div class="authurl" id="verifyUrl"></div> |
| 150 | <div class="pollbar"><i></i></div> |
| 151 | <div class="polllbl"><span class="spin"></span><span id="pollLabel">Waiting for authorization in browser...</span></div> |
| 152 | <div class="row" style="margin-top:12px"> |
| 153 | <button class="btn danger" id="btnCancel" type="button">Cancel</button> |
| 154 | </div> |
| 155 | <div class="note" id="flowNote"></div> |
| 156 | </div> |
| 157 | </div> |
| 158 | |
| 159 | <div class="card"> |
| 160 | <h2>Named accounts</h2> |
| 161 | <p class="lead">Every account file in the local accounts directory.</p> |
| 162 | <div id="accounts"><div class="empty">No named accounts.</div></div> |
| 163 | </div> |
| 164 | |
| 165 | <footer> |
| 166 | <span id="footInfo">plugin_codex_login</span> |
| 167 | · <a href="https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-codex-login">source</a> |
| 168 | </footer> |
| 169 | </div> |
| 170 | |
| 171 | <div class="toast" id="toast"></div> |
| 172 | |
| 173 | <script> |
| 174 | (function(){ |
| 175 | var q=new URLSearchParams(location.search); |
| 176 | var node=q.get('node')||''; |
| 177 | var sid=q.get('id')||''; |
| 178 | var acct=q.get('account')||''; |
| 179 | var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))|| |
| 180 | localStorage.getItem('bot_active_pwd')||''; |
| 181 | |
| 182 | /* Two call routes. Getting this wrong is the most common plugin bug: |
| 183 | * page served through the hub (bot.scorpiox.net/plugins?plugin=...&node=..) |
| 184 | * -> call the hub proxy back: /plugins?plugin=plugin_codex_login&action=.. |
| 185 | * opened directly on the node |
| 186 | * -> the plugin itself is the route: /plugin_codex_login?action=.. |
| 187 | * Calling /plugins?plugin= on the node returns the discovery list, not us. */ |
| 188 | var HUB=q.get('plugin')||''; |
| 189 | function url(action,extra){ |
| 190 | return (HUB?'/plugins?plugin='+encodeURIComponent(HUB)+'&action=':'/plugin_codex_login?action=')+ |
| 191 | encodeURIComponent(action)+ |
| 192 | (extra?('&'+extra):'')+ |
| 193 | (acct?'&account='+encodeURIComponent(acct):'')+ |
| 194 | (node?'&node='+encodeURIComponent(node):'')+ |
| 195 | (sid?'&id='+encodeURIComponent(sid):'')+ |
| 196 | (pwd?'&pwd='+encodeURIComponent(pwd):''); |
| 197 | } |
| 198 | function hdr(){ |
| 199 | var h={}; |
| 200 | if(pwd)h['X-Bot-Password']=pwd; |
| 201 | return h; |
| 202 | } |
| 203 | function api(action,extra){ |
| 204 | return fetch(url(action,extra),{headers:hdr()}).then(function(r){ |
| 205 | return r.json().catch(function(){return {ok:false,error:'bad response'};}); |
| 206 | }); |
| 207 | } |
| 208 | |
| 209 | var $=function(id){return document.getElementById(id);}; |
| 210 | function toast(msg){ |
| 211 | var t=$('toast');t.textContent=msg;t.classList.add('show'); |
| 212 | clearTimeout(t._t);t._t=setTimeout(function(){t.classList.remove('show');},2200); |
| 213 | } |
| 214 | function note(el,msg,kind){ |
| 215 | if(typeof el==='string')el=$(el); |
| 216 | if(!el)return; |
| 217 | el.textContent=msg||''; |
| 218 | el.className='note'+(msg?' show '+(kind||''):''); |
| 219 | } |
| 220 | function kv(el,rows){ |
| 221 | el.innerHTML=''; |
| 222 | rows.forEach(function(r){ |
| 223 | var a=document.createElement('div');a.className='k';a.textContent=r[0]; |
| 224 | var b=document.createElement('div');b.className='v'+(r[2]?' plain':''); |
| 225 | b.textContent=r[1];el.appendChild(a);el.appendChild(b); |
| 226 | }); |
| 227 | } |
| 228 | function fmtExpiry(sec){ |
| 229 | if(typeof sec!=='number')return '-'; |
| 230 | if(sec<=0)return 'expired'; |
| 231 | if(sec<90)return sec+'s'; |
| 232 | if(sec<5400)return Math.round(sec/60)+' min'; |
| 233 | var h=Math.floor(sec/3600); |
| 234 | if(h<48)return h+' h '+(Math.floor((sec%3600)/60))+' min'; |
| 235 | return Math.floor(h/24)+' days'; |
| 236 | } |
| 237 | function fmtClock(sec){ |
| 238 | if(typeof sec!=='number'||sec<=0)return '-'; |
| 239 | var d=Math.floor(sec/86400),h=Math.floor((sec%86400)/3600),m=Math.floor((sec%3600)/60); |
| 240 | if(d>0)return d+'d '+h+'h'; |
| 241 | if(h>0)return h+'h '+m+'m'; |
| 242 | return m+'m'; |
| 243 | } |
| 244 | function setPill(cls,text){ |
| 245 | $('pill').className='pill '+cls; |
| 246 | $('pillText').textContent=text; |
| 247 | } |
| 248 | |
| 249 | var pollTimer=null; |
| 250 | var pollMs=5000; |
| 251 | var flowActive=false; |
| 252 | var flowVerify=''; |
| 253 | var flowCode=''; |
| 254 | |
| 255 | function startPollingUI(){ |
| 256 | flowActive=true; |
| 257 | $('stepIdle').classList.remove('on'); |
| 258 | $('stepActive').classList.add('on'); |
| 259 | if(!pollTimer)pollTimer=setInterval(pollOnce,pollMs); |
| 260 | } |
| 261 | function stopPollingUI(){ |
| 262 | flowActive=false; |
| 263 | if(pollTimer){clearInterval(pollTimer);pollTimer=null;} |
| 264 | } |
| 265 | function pollOnce(){ |
| 266 | if(!flowActive)return; |
| 267 | api('poll').then(function(d){ |
| 268 | if(!d||d.ok===false){note('flowNote','Poll error: '+(d&&d.error||'unknown'),'err');return;} |
| 269 | if(d.state==='done'||d.logged_in){ |
| 270 | stopPollingUI(); |
| 271 | $('stepIdle').classList.add('on'); |
| 272 | $('stepActive').classList.remove('on'); |
| 273 | $('pollLabel').textContent='Signed in'; |
| 274 | note('flowNote','Signed in. The credential file has been written.','ok'); |
| 275 | load(); |
| 276 | }else if(d.state==='failed'){ |
| 277 | stopPollingUI(); |
| 278 | $('stepIdle').classList.add('on'); |
| 279 | $('stepActive').classList.remove('on'); |
| 280 | $('pollLabel').textContent='Login failed'; |
| 281 | note('flowNote','Login failed: '+(d.error||'unknown')+(d.detail?(' - '+d.detail):''),'err'); |
| 282 | load(); |
| 283 | }else{ |
| 284 | $('pollLabel').textContent='Waiting for authorization in browser...'; |
| 285 | if(d.interval&&d.interval>0)pollMs=Math.max(1000,d.interval*1000); |
| 286 | if(d.logged_in)load(); |
| 287 | } |
| 288 | }).catch(function(e){note('flowNote','Poll request failed: '+e,'err');}); |
| 289 | } |
| 290 | |
| 291 | function render(st){ |
| 292 | var li=!!st.logged_in, ex=!!st.expired, pend=!!st.pending; |
| 293 | if(li&&!ex)setPill('ok','Logged In'); |
| 294 | else if(li&&ex)setPill('warn','Expired'); |
| 295 | else if(pend)setPill('warn','Signing In'); |
| 296 | else setPill('off','Not Connected'); |
| 297 | |
| 298 | $('count').innerHTML=''; |
| 299 | if(li&&!ex){ |
| 300 | var s=document.createElement('span');s.textContent=fmtClock(st.expires_in_sec); |
| 301 | var sm=document.createElement('small');sm.textContent=' remaining'; |
| 302 | $('count').appendChild(s);$('count').appendChild(sm); |
| 303 | }else if(li&&ex){ |
| 304 | $('count').textContent='Token expired'; |
| 305 | }else if(pend){ |
| 306 | $('count').textContent='Device flow open'; |
| 307 | }else{ |
| 308 | $('count').textContent='No Codex session'; |
| 309 | } |
| 310 | |
| 311 | var total=st.expires_in_sec>0?st.expires_in_sec:0; |
| 312 | var pct=0; |
| 313 | if(li&&total>0){ |
| 314 | /* A one-hour token is the norm, so the bar is drawn against the window it |
| 315 | * actually has, capped at 24 h so a long-lived token still fills it. */ |
| 316 | var win=total>86400?86400:total; |
| 317 | pct=Math.max(2,Math.min(100,Math.round(100*total/win))); |
| 318 | } |
| 319 | $('fill').style.width=pct+'%'; |
| 320 | $('bar').className='bar'+(li&&ex?' err':(li&&pct<20?' warn':'')); |
| 321 | if(!li)$('bar').className='bar'; |
| 322 | |
| 323 | kv($('session'),[ |
| 324 | ['Account', st.account||'-', true], |
| 325 | ['Logged in', st.logged_in?'yes':'no', true], |
| 326 | ['Token', st.logged_in?(st.expired?'expired':'valid, '+fmtExpiry(st.expires_in_sec)):'none', true], |
| 327 | ['Refresh token', st.has_refresh?'stored':'none', true], |
| 328 | ['Last refreshed', st.last_refresh?new Date(st.last_refresh*1000).toISOString().replace('T',' ').slice(0,19):'unknown', true], |
| 329 | ['Account id', st.account_id||'-'], |
| 330 | ['Login pending', st.pending?'yes':'no', true], |
| 331 | ['Login CLI', st.cli_present?'found':'not found', true], |
| 332 | ['Profile', st.profile_exists?(st.profile||'codex'):'not created', true], |
| 333 | ['Credentials', st.credentials_path||'-'] |
| 334 | ]); |
| 335 | |
| 336 | $('btnRelogin').hidden=!li; |
| 337 | $('btnStartLogin').hidden=!!li; |
| 338 | |
| 339 | if(!li&&!pend)note('sessionNote','No Codex session on this node yet. Start a device login below.','ok'); |
| 340 | else if(li&&ex)note('sessionNote','The token has expired. Press Refresh Token Now, or sign in again.','warn'); |
| 341 | else note('sessionNote',''); |
| 342 | |
| 343 | if(st.cli_present===false) |
| 344 | note('sessionNote','SCORPIOX CODE is not on this node: the login and refresh CLIs cannot be run here.','warn'); |
| 345 | |
| 346 | var box=$('accounts'); |
| 347 | box.innerHTML=''; |
| 348 | var list=st.accounts||[]; |
| 349 | if(!list.length){ |
| 350 | var e=document.createElement('div');e.className='empty'; |
| 351 | e.textContent='No named accounts.';box.appendChild(e); |
| 352 | }else{ |
| 353 | list.forEach(function(a){ |
| 354 | var row=document.createElement('div');row.className='acct'; |
| 355 | var nm=document.createElement('div');nm.className='nm';nm.textContent=a.name; |
| 356 | var tg=document.createElement('div'); |
| 357 | tg.className='tag '+(a.logged_in&&!a.expired?'ok':(a.logged_in?'warn':'')); |
| 358 | tg.textContent=a.logged_in?(a.expired?'expired':'valid, '+fmtExpiry(a.expires_in_sec)):'empty'; |
| 359 | var bt=document.createElement('button'); |
| 360 | bt.className='btn ghost';bt.type='button';bt.textContent='Select'; |
| 361 | bt.onclick=function(){acct=a.name;$('sub').textContent='account: '+a.name;load();}; |
| 362 | row.appendChild(nm);row.appendChild(tg);row.appendChild(bt); |
| 363 | box.appendChild(row); |
| 364 | }); |
| 365 | } |
| 366 | if(!$('sub').textContent||$('sub').textContent==='Device code login on this node'){ |
| 367 | $('sub').textContent=(st.account&&st.account!=='default')?('account: '+st.account):'Device code login on this node'; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | function load(){ |
| 372 | api('status').then(function(d){ |
| 373 | if(!d||d.ok===false){setPill('off','Not Connected');note('sessionNote','Error: '+(d&&d.error||'no response'),'err');return;} |
| 374 | render(d); |
| 375 | if(d.pending&&!flowActive){ |
| 376 | /* A flow that was started elsewhere (or before a page reload) should |
| 377 | * still show its spinner; the code itself is not recoverable from the |
| 378 | * marker, so the panel says so rather than pretending. */ |
| 379 | $('userCode').textContent='--'; |
| 380 | $('verifyUrl').textContent=''; |
| 381 | $('pollLabel').textContent='A device flow is already open on this node'; |
| 382 | startPollingUI(); |
| 383 | } |
| 384 | if(!d.pending&&flowActive)stopPollingUI(); |
| 385 | }).catch(function(e){setPill('off','Not Connected');note('sessionNote','Request failed: '+e,'err');}); |
| 386 | } |
| 387 | |
| 388 | function doStart(force){ |
| 389 | note('sessionNote',''); |
| 390 | $('btnStartLogin').disabled=true; |
| 391 | api('start',force?'force=1':'').then(function(d){ |
| 392 | $('btnStartLogin').disabled=false; |
| 393 | if(!d||d.ok===false){ |
| 394 | note('sessionNote','Start failed: '+(d&&d.error||'unknown')+(d.detail?(' - '+d.detail):''),'err'); |
| 395 | return; |
| 396 | } |
| 397 | if(d.already_logged_in){ |
| 398 | note('sessionNote','This node already has Codex credentials. Use Re-login to replace them.','warn'); |
| 399 | load(); |
| 400 | return; |
| 401 | } |
| 402 | flowVerify=d.verify_url||''; |
| 403 | flowCode=d.user_code||''; |
| 404 | $('userCode').textContent=flowCode||'--'; |
| 405 | $('verifyUrl').textContent=flowVerify; |
| 406 | $('pollLabel').textContent='Waiting for authorization in browser...'; |
| 407 | pollMs=Math.max(1000,(d.interval||5)*1000); |
| 408 | note('flowNote','',''); |
| 409 | startPollingUI(); |
| 410 | load(); |
| 411 | }).catch(function(e){$('btnStartLogin').disabled=false;note('sessionNote','Start request failed: '+e,'err');}); |
| 412 | } |
| 413 | |
| 414 | $('btnStartLogin').onclick=function(){doStart(false);}; |
| 415 | $('btnRelogin').onclick=function(){doStart(true);}; |
| 416 | $('btnReload').onclick=load; |
| 417 | $('btnCancel').onclick=function(){ |
| 418 | stopPollingUI(); |
| 419 | api('cancel').then(function(d){ |
| 420 | $('stepIdle').classList.add('on'); |
| 421 | $('stepActive').classList.remove('on'); |
| 422 | note('flowNote',(d&&d.ok)?'Device flow cancelled.':'Cancel failed: '+((d&&d.error)||'unknown'), |
| 423 | (d&&d.ok)?'ok':'err'); |
| 424 | load(); |
| 425 | }).catch(function(e){note('flowNote','Cancel request failed: '+e,'err');}); |
| 426 | }; |
| 427 | $('btnRefresh').onclick=function(){ |
| 428 | note('sessionNote',''); |
| 429 | api('refresh').then(function(d){ |
| 430 | if(!d||d.ok===false){ |
| 431 | note('sessionNote','Refresh failed: '+(d&&d.error||'unknown')+(d.detail?(' - '+d.detail):''),'err'); |
| 432 | return; |
| 433 | } |
| 434 | note('sessionNote','Token refreshed. New expiry: '+fmtExpiry(d.expires_in_sec)+'.','ok'); |
| 435 | render(d); |
| 436 | }).catch(function(e){note('sessionNote','Refresh request failed: '+e,'err');}); |
| 437 | }; |
| 438 | $('btnCopyOpen').onclick=function(){ |
| 439 | var done=function(){toast('Code copied. Open the link and approve.');}; |
| 440 | if(navigator.clipboard&&navigator.clipboard.writeText){ |
| 441 | navigator.clipboard.writeText(flowCode).then(done,function(){toast('Copy failed');}); |
| 442 | }else{toast('Copy not available');} |
| 443 | if(flowVerify)window.open(flowVerify,'_blank','noopener'); |
| 444 | }; |
| 445 | |
| 446 | var tb=$('themeToggle'); |
| 447 | if(tb)tb.onclick=function(){ |
| 448 | if(window.sxApplyTheme)window.sxApplyTheme(window.sxTheme?window.sxTheme():'light'); |
| 449 | }; |
| 450 | $('footInfo').textContent='plugin_codex_login'; |
| 451 | load(); |
| 452 | })(); |
| 453 | </script> |
| 454 | </body></html> |