| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_CCLOGIN_UI_HTML_H |
| 3 | #define SX_CCLOGIN_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>claude</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0;min-height:100%}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;\n" |
| 15 | " line-height:1.5;-webkit-font-smoothing:antialiased}\n" |
| 16 | "#app{max-width:840px;margin:0 auto;padding:16px 16px 40px}\n" |
| 17 | ".hd{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px}\n" |
| 18 | ".hd .grow{flex:1 1 auto;min-width:0}\n" |
| 19 | ".hd h1{margin:0;font-size:18px;font-weight:650;letter-spacing:-.01em}\n" |
| 20 | ".hd .sub{font-size:11.5px;color:var(--text-2);margin-top:2px;white-space:nowrap;\n" |
| 21 | " overflow:hidden;text-overflow:ellipsis}\n" |
| 22 | ".pill{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;font-weight:650;\n" |
| 23 | " padding:4px 10px;border-radius:999px;background:var(--surface-2);color:var(--text-2);\n" |
| 24 | " border:1px solid var(--line);white-space:nowrap}\n" |
| 25 | ".pill .dot{width:7px;height:7px;border-radius:50%;background:var(--gray);flex:0 0 auto}\n" |
| 26 | ".pill.ok{color:var(--green);border-color:rgba(48,209,88,.35)}\n" |
| 27 | ".pill.ok .dot{background:var(--green);box-shadow:0 0 0 3px rgba(48,209,88,.15)}\n" |
| 28 | ".pill.warn{color:var(--orange);border-color:rgba(255,159,10,.35)}\n" |
| 29 | ".pill.warn .dot{background:var(--orange)}\n" |
| 30 | ".pill.off .dot{background:var(--gray)}\n" |
| 31 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;\n" |
| 32 | " padding:16px;margin-bottom:12px}\n" |
| 33 | ".card h2{margin:0 0 4px;font-size:13px;font-weight:700;letter-spacing:.08em;\n" |
| 34 | " text-transform:uppercase;color:var(--text-2)}\n" |
| 35 | ".card .lead{margin:0 0 12px;font-size:12.5px;color:var(--text-2)}\n" |
| 36 | ".row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}\n" |
| 37 | ".btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:7px 16px;\n" |
| 38 | " font-weight:600;font-size:13px;cursor:pointer;font-family:inherit;\n" |
| 39 | " transition:transform .12s var(--ease),opacity .12s}\n" |
| 40 | ".btn:active{transform:scale(.98)}\n" |
| 41 | ".btn:disabled{opacity:.5;cursor:default}\n" |
| 42 | ".btn.ghost{background:var(--surface-2);color:var(--text);border:1px solid var(--line)}\n" |
| 43 | ".btn.ghost:hover{background:var(--surface-hover);border-color:var(--line-2)}\n" |
| 44 | ".btn.danger{background:transparent;color:var(--red);border:1px solid rgba(255,69,58,.35)}\n" |
| 45 | "a.btn{display:inline-flex;align-items:center;gap:6px;text-decoration:none}\n" |
| 46 | ".kv{display:grid;grid-template-columns:132px minmax(0,1fr);gap:6px 12px;font-size:13px}\n" |
| 47 | ".kv .k{color:var(--text-2);font-size:12px}\n" |
| 48 | ".kv .v{font-family:var(--mono);font-size:12px;word-break:break-all}\n" |
| 49 | ".kv .v.plain{font-family:var(--font);font-size:13px}\n" |
| 50 | ".step{display:none}\n" |
| 51 | ".step.on{display:block}\n" |
| 52 | ".hint{margin:10px 0 0;font-size:12px;color:var(--text-2)}\n" |
| 53 | ".note{font-size:12.5px;margin-top:10px;display:none}\n" |
| 54 | ".note.show{display:block}\n" |
| 55 | ".note.err{color:var(--red)}\n" |
| 56 | ".note.ok{color:var(--green)}\n" |
| 57 | ".authurl{font-family:var(--mono);font-size:11.5px;color:var(--text-2);word-break:break-all;\n" |
| 58 | " background:var(--code-bg);border:1px solid var(--line);border-radius:10px;\n" |
| 59 | " padding:10px;margin-top:10px;max-height:120px;overflow:auto}\n" |
| 60 | "textarea{width:100%;margin-top:10px;min-height:74px;resize:vertical;background:var(--input-bg);\n" |
| 61 | " color:var(--text);border:1px solid var(--line);border-radius:10px;padding:10px;\n" |
| 62 | " font-family:var(--mono);font-size:12px;outline:none}\n" |
| 63 | "textarea:focus{border-color:var(--blue)}\n" |
| 64 | ".count{font-size:34px;font-weight:700;letter-spacing:-.02em;line-height:1.1}\n" |
| 65 | ".count small{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:0}\n" |
| 66 | ".bar{height:6px;border-radius:999px;background:var(--surface-2);overflow:hidden;margin-top:10px}\n" |
| 67 | ".bar .fill{display:block;height:100%;background:var(--green);border-radius:999px;\n" |
| 68 | " transition:width .3s var(--ease)}\n" |
| 69 | ".bar.warn .fill{background:var(--orange)}\n" |
| 70 | ".bar.err .fill{background:var(--red)}\n" |
| 71 | ".spin{width:12px;height:12px;border-radius:50%;border:2px solid rgba(255,255,255,.35);\n" |
| 72 | " border-top-color:#fff;display:none;animation:sp .7s linear infinite}\n" |
| 73 | ".btn.loading .spin{display:inline-block}\n" |
| 74 | "@keyframes sp{to{transform:rotate(360deg)}}\n" |
| 75 | ".acct{display:flex;align-items:center;gap:10px;padding:8px 0;border-top:1px solid var(--line);\n" |
| 76 | " font-size:13px;flex-wrap:wrap}\n" |
| 77 | ".acct:first-of-type{border-top:0}\n" |
| 78 | ".acct .nm{font-family:var(--mono);font-size:12px;flex:1 1 120px;min-width:0;\n" |
| 79 | " overflow:hidden;text-overflow:ellipsis}\n" |
| 80 | ".acct .tag{font-size:11px;color:var(--text-2)}\n" |
| 81 | ".acct .tag.ok{color:var(--green)}\n" |
| 82 | ".acct .tag.warn{color:var(--orange)}\n" |
| 83 | ".empty{padding:10px 0;color:var(--text-2);font-size:12.5px}\n" |
| 84 | ".toast{position:fixed;left:50%;bottom:18px;transform:translate(-50%,14px);opacity:0;\n" |
| 85 | " pointer-events:none;background:var(--modal-bg);border:1px solid var(--line-2);\n" |
| 86 | " color:var(--text);border-radius:999px;padding:8px 16px;font-size:12.5px;\n" |
| 87 | " box-shadow:var(--shadow-lg);transition:opacity .18s var(--ease),transform .18s var(--ease);\n" |
| 88 | " z-index:9;max-width:calc(100vw - 32px)}\n" |
| 89 | ".toast.show{opacity:1;transform:translate(-50%,0)}\n" |
| 90 | "#themeToggle{background:var(--surface-2);border:1px solid var(--line);color:var(--text);\n" |
| 91 | " border-radius:980px;padding:5px 12px;font-size:12px;font-weight:600;cursor:pointer;\n" |
| 92 | " font-family:inherit}\n" |
| 93 | "@media (max-width:520px){\n" |
| 94 | " #app{padding:12px 12px 32px}\n" |
| 95 | " .kv{grid-template-columns:1fr;gap:2px 0}\n" |
| 96 | " .kv .k{margin-top:8px}\n" |
| 97 | " .card{padding:13px;border-radius:12px}\n" |
| 98 | " .count{font-size:28px}\n" |
| 99 | "}\n" |
| 100 | "</style>\n" |
| 101 | "</head>\n" |
| 102 | "<body>\n" |
| 103 | "<div id=\"app\">\n" |
| 104 | " <div class=\"hd\">\n" |
| 105 | " <div class=\"grow\">\n" |
| 106 | " <h1>Claude Code</h1>\n" |
| 107 | " <div class=\"sub\" id=\"sub\">OAuth PKCE login on this node</div>\n" |
| 108 | " </div>\n" |
| 109 | " <span class=\"pill off\" id=\"pill\"><span class=\"dot\"></span><span id=\"pillText\">Checking</span></span>\n" |
| 110 | " <button id=\"themeToggle\" class=\"embed-hide\" type=\"button\">Theme</button>\n" |
| 111 | " </div>\n" |
| 112 | "\n" |
| 113 | " <div class=\"card\">\n" |
| 114 | " <h2>Session</h2>\n" |
| 115 | " <p class=\"lead\" id=\"sessionLead\">Reading the local Claude Code credentials.</p>\n" |
| 116 | " <div class=\"count\" id=\"count\">-</div>\n" |
| 117 | " <div class=\"bar\" id=\"bar\"><span class=\"fill\" id=\"fill\" style=\"width:0%\"></span></div>\n" |
| 118 | " <div class=\"kv\" id=\"session\" style=\"margin-top:14px\"></div>\n" |
| 119 | " <div class=\"row\" style=\"margin-top:14px\">\n" |
| 120 | " <button class=\"btn ghost\" id=\"btnRefresh\" type=\"button\"><span class=\"spin\"></span>Refresh Token Now</button>\n" |
| 121 | " <button class=\"btn ghost\" id=\"btnReload\" type=\"button\">Reload</button>\n" |
| 122 | " </div>\n" |
| 123 | " <div class=\"note\" id=\"refreshNote\"></div>\n" |
| 124 | " </div>\n" |
| 125 | "\n" |
| 126 | " <div class=\"card\">\n" |
| 127 | " <h2>OAuth login</h2>\n" |
| 128 | " <p class=\"lead\">Sign in with Claude. Nothing leaves this node: the login CLI performs the\n" |
| 129 | " exchange and writes the credential file here.</p>\n" |
| 130 | "\n" |
| 131 | " <div class=\"step on\" id=\"step1\">\n" |
| 132 | " <div class=\"row\">\n" |
| 133 | " <button class=\"btn\" id=\"btnStart\" type=\"button\">Start Claude Login</button>\n" |
| 134 | " <button class=\"btn ghost\" id=\"btnRelogin\" type=\"button\">Re-login (replace)</button>\n" |
| 135 | " </div>\n" |
| 136 | " <p class=\"hint\">This generates a PKCE challenge and an authorization link. No token is\n" |
| 137 | " created until you paste the code back.</p>\n" |
| 138 | " </div>\n" |
| 139 | "\n" |
| 140 | " <div class=\"step\" id=\"step2\">\n" |
| 141 | " <div class=\"row\">\n" |
| 142 | " <a class=\"btn\" id=\"linkOpen\" href=\"#\" target=\"_blank\" rel=\"noopener noreferrer\">Open Claude.ai</a>\n" |
| 143 | " <button class=\"btn ghost\" id=\"btnCopy\" type=\"button\">Copy link</button>\n" |
| 144 | " <button class=\"btn ghost\" id=\"btnCancel\" type=\"button\">Cancel</button>\n" |
| 145 | " </div>\n" |
| 146 | " <div class=\"authurl\" id=\"authUrl\"></div>\n" |
| 147 | " <p class=\"hint\" id=\"flowHint\">After approving, Claude shows an authorization code. Paste the\n" |
| 148 | " whole redirect address or just the <span style=\"font-family:var(--mono)\">code=</span> value below.</p>\n" |
| 149 | " <textarea id=\"codeInput\" spellcheck=\"false\" autocomplete=\"off\"\n" |
| 150 | " placeholder=\"Paste the authorization code or the full redirect URL\"></textarea>\n" |
| 151 | " <div class=\"row\" style=\"margin-top:10px\">\n" |
| 152 | " <button class=\"btn\" id=\"btnFinish\" type=\"button\">Submit Code</button>\n" |
| 153 | " </div>\n" |
| 154 | " <div class=\"note\" id=\"loginNote\"></div>\n" |
| 155 | " </div>\n" |
| 156 | " </div>\n" |
| 157 | "\n" |
| 158 | " <div class=\"card\">\n" |
| 159 | " <h2>Named accounts</h2>\n" |
| 160 | " <p class=\"lead\">Every account file in the local accounts directory.</p>\n" |
| 161 | " <div id=\"accounts\"><div class=\"empty\">No named accounts.</div></div>\n" |
| 162 | " </div>\n" |
| 163 | "</div>\n" |
| 164 | "\n" |
| 165 | "<div class=\"toast\" id=\"toast\"></div>\n" |
| 166 | "\n" |
| 167 | "<script>\n" |
| 168 | "var q=new URLSearchParams(location.search);\n" |
| 169 | "var node=q.get('node')||'';\n" |
| 170 | "var sid=q.get('id')||'';\n" |
| 171 | "var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||\n" |
| 172 | " localStorage.getItem('bot_active_pwd')||'';\n" |
| 173 | "\n" |
| 174 | "/* Two call routes. Getting this wrong is the most common plugin bug:\n" |
| 175 | " * page served through the hub (bot.scorpiox.net/plugins?plugin=...&node=..)\n" |
| 176 | " * -> call the hub proxy back: /plugins?plugin=plugin_claudecode_login&action=..\n" |
| 177 | " * opened directly on the node\n" |
| 178 | " * -> the plugin itself is the route: /plugin_claudecode_login?action=..\n" |
| 179 | " * Calling /plugins?plugin= on the node returns the discovery list, not us. */\n" |
| 180 | "var HUB=q.get('plugin')||'';\n" |
| 181 | "function url(action,extra){\n" |
| 182 | " return (HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_claudecode_login')+\n" |
| 183 | " '?action='+encodeURIComponent(action)+\n" |
| 184 | " (extra?('&'+extra):'')+\n" |
| 185 | " (node?'&node='+encodeURIComponent(node):'')+\n" |
| 186 | " (sid?'&id='+encodeURIComponent(sid):'')+\n" |
| 187 | " (pwd?'&pwd='+encodeURIComponent(pwd):'');\n" |
| 188 | "}\n" |
| 189 | "function hdr(){\n" |
| 190 | " var h={};\n" |
| 191 | " if(pwd)h['X-Bot-Password']=pwd;\n" |
| 192 | " return h;\n" |
| 193 | "}\n" |
| 194 | "function api(action,extra){\n" |
| 195 | " return fetch(url(action,extra),{headers:hdr()}).then(function(r){\n" |
| 196 | " return r.json().catch(function(){return {ok:false,error:'bad response'};});\n" |
| 197 | " });\n" |
| 198 | "}\n" |
| 199 | "\n" |
| 200 | "var $=function(id){return document.getElementById(id);};\n" |
| 201 | "function toast(msg){\n" |
| 202 | " var t=$('toast');t.textContent=msg;t.classList.add('show');\n" |
| 203 | " clearTimeout(t._t);t._t=setTimeout(function(){t.classList.remove('show');},2200);\n" |
| 204 | "}\n" |
| 205 | "function note(el,msg,kind){\n" |
| 206 | " el.textContent=msg||'';\n" |
| 207 | " el.className='note'+(msg?' show '+(kind||''):'');\n" |
| 208 | "}\n" |
| 209 | "function kv(el,rows){\n" |
| 210 | " el.innerHTML='';\n" |
| 211 | " rows.forEach(function(r){\n" |
| 212 | " var a=document.createElement('div');a.className='k';a.textContent=r[0];\n" |
| 213 | " var b=document.createElement('div');b.className='v'+(r[2]?' plain':'');\n" |
| 214 | " b.textContent=r[1];el.appendChild(a);el.appendChild(b);\n" |
| 215 | " });\n" |
| 216 | "}\n" |
| 217 | "function fmtExpiry(sec){\n" |
| 218 | " if(typeof sec!=='number')return '-';\n" |
| 219 | " if(sec<=0)return 'expired';\n" |
| 220 | " if(sec<90)return sec+'s';\n" |
| 221 | " if(sec<5400)return Math.round(sec/60)+' min';\n" |
| 222 | " if(sec<172800)return Math.round(sec/3600)+' h';\n" |
| 223 | " if(sec<63072000)return Math.round(sec/86400)+' d';\n" |
| 224 | " return Math.round(sec/31536000)+' yr';\n" |
| 225 | "}\n" |
| 226 | "function countdown(sec){\n" |
| 227 | " if(typeof sec!=='number'||sec<=0)return ['-',''];\n" |
| 228 | " var d=Math.floor(sec/86400),h=Math.floor((sec%86400)/3600),\n" |
| 229 | " m=Math.floor((sec%3600)/60),s=sec%60,u='second';\n" |
| 230 | " var v,d2;\n" |
| 231 | " if(d>0){v=d;u='day';d2=[h+'h',m+'m'].join(' ');}\n" |
| 232 | " else if(h>0){v=h;u='hour';d2=[m+'m'].join(' ');}\n" |
| 233 | " else if(m>0){v=m;u='minute';d2=[s+'s'].join(' ');}\n" |
| 234 | " else {v=s;d2='';}\n" |
| 235 | " return [v+' <small>'+(v===1?u:u+'s')+(d2?' · '+d2:'')+'</small>',''];\n" |
| 236 | "}\n" |
| 237 | "function setPill(st){\n" |
| 238 | " var p=$('pill'),t=$('pillText');\n" |
| 239 | " if(st.logged_in&&st.expired){p.className='pill warn';t.textContent='Expired';}\n" |
| 240 | " else if(st.logged_in){p.className='pill ok';t.textContent='Logged In';}\n" |
| 241 | " else if(st.pending){p.className='pill warn';t.textContent='Signing in';}\n" |
| 242 | " else {p.className='pill off';t.textContent='Not Connected';}\n" |
| 243 | "}\n" |
| 244 | "/* Full token lifetime is 8 h for a Claude Code session; the bar is a share of\n" |
| 245 | " * the remaining time, so it is a coarse but honest \"how much is left\" read.\n" |
| 246 | " * A countdown of 0 with a refresh token present is the normal steady state. */\n" |
| 247 | "var LIFETIME=8*3600;\n" |
| 248 | "function render(st){\n" |
| 249 | " setPill(st);\n" |
| 250 | " $('sub').textContent=st.account?st.account:'OAuth PKCE login on this node';\n" |
| 251 | "\n" |
| 252 | " if(st.logged_in){\n" |
| 253 | " $('sessionLead').textContent=st.expired\n" |
| 254 | " ? 'The session is present but its access token has expired. Use Refresh Token Now.'\n" |
| 255 | " : 'This node holds a Claude Code session.';\n" |
| 256 | " }else{\n" |
| 257 | " $('sessionLead').textContent='No Claude Code session on this node yet. Start a login below.';\n" |
| 258 | " }\n" |
| 259 | "\n" |
| 260 | " var c=countdown(st.expires_in_sec);\n" |
| 261 | " $('count').innerHTML=st.logged_in?c[0]:'not connected';\n" |
| 262 | " var pct=0;\n" |
| 263 | " if(st.logged_in&&st.expires_in_sec>0){\n" |
| 264 | " pct=Math.max(2,Math.min(100,Math.round(st.expires_in_sec/LIFETIME*100)));\n" |
| 265 | " }\n" |
| 266 | " $('fill').style.width=pct+'%';\n" |
| 267 | " $('bar').className='bar'+(st.expired?' err':(pct<20?' warn':''));\n" |
| 268 | " if(!st.logged_in)$('bar').className='bar';\n" |
| 269 | "\n" |
| 270 | " kv($('session'),[\n" |
| 271 | " ['Account', st.account||'-', true],\n" |
| 272 | " ['Logged in', st.logged_in?'yes':'no', true],\n" |
| 273 | " ['Refresh token', st.has_refresh?'stored':'none', true],\n" |
| 274 | " ['Token expires', st.logged_in?fmtExpiry(st.expires_in_sec):'-', true],\n" |
| 275 | " ['Subscription', st.subscription||'-', true],\n" |
| 276 | " ['Login pending', st.pending?'yes':'no', true],\n" |
| 277 | " ['Login CLI', st.cli_present?'found':'not found', true],\n" |
| 278 | " ['Profile', st.profile_exists?(st.profile||'claude_code'):'not created', true],\n" |
| 279 | " ['Credentials', st.credentials_path||'-']\n" |
| 280 | " ]);\n" |
| 281 | "\n" |
| 282 | " var box=$('accounts');\n" |
| 283 | " box.innerHTML='';\n" |
| 284 | " var list=st.accounts||[];\n" |
| 285 | " if(!list.length){\n" |
| 286 | " var e=document.createElement('div');e.className='empty';\n" |
| 287 | " e.textContent='No named accounts.';box.appendChild(e);\n" |
| 288 | " }else{\n" |
| 289 | " list.forEach(function(a){\n" |
| 290 | " var row=document.createElement('div');row.className='acct';\n" |
| 291 | " var nm=document.createElement('div');nm.className='nm';nm.textContent=a.name;\n" |
| 292 | " var tg=document.createElement('div');\n" |
| 293 | " tg.className='tag '+(a.logged_in?(a.expired?'warn':'ok'):'');\n" |
| 294 | " tg.textContent=a.logged_in?(a.expired?'expired':'valid'):'no token';\n" |
| 295 | " row.appendChild(nm);row.appendChild(tg);box.appendChild(row);\n" |
| 296 | " });\n" |
| 297 | " }\n" |
| 298 | "\n" |
| 299 | " if(st.pending){$('step1').classList.remove('on');$('step2').classList.add('on');}\n" |
| 300 | "}\n" |
| 301 | "function load(){\n" |
| 302 | " return api('status').then(function(d){\n" |
| 303 | " if(d&&d.ok)render(d);\n" |
| 304 | " else toast((d&&d.error)||'status failed');\n" |
| 305 | " }).catch(function(e){toast('Status failed: '+e.message);});\n" |
| 306 | "}\n" |
| 307 | "\n" |
| 308 | "var authUrl='';\n" |
| 309 | "function start(force){\n" |
| 310 | " var b=force?$('btnRelogin'):$('btnStart');\n" |
| 311 | " b.disabled=true;b.textContent='Starting...';\n" |
| 312 | " api('start',force?'force=1':'').then(function(d){\n" |
| 313 | " b.disabled=false;b.textContent=force?'Re-login (replace)':'Start Claude Login';\n" |
| 314 | " if(!d||!d.ok){toast((d&&(d.detail||d.error))||'start failed');return;}\n" |
| 315 | " authUrl=d.auth_url||'';\n" |
| 316 | " $('authUrl').textContent=authUrl;\n" |
| 317 | " $('linkOpen').setAttribute('href',authUrl);\n" |
| 318 | " if(d.hint)$('flowHint').textContent=d.hint;\n" |
| 319 | " $('step1').classList.remove('on');\n" |
| 320 | " $('step2').classList.add('on');\n" |
| 321 | " $('codeInput').focus();\n" |
| 322 | " }).catch(function(e){\n" |
| 323 | " b.disabled=false;b.textContent=force?'Re-login (replace)':'Start Claude Login';\n" |
| 324 | " toast('Start failed: '+e.message);\n" |
| 325 | " });\n" |
| 326 | "}\n" |
| 327 | "\n" |
| 328 | "function finish(){\n" |
| 329 | " var raw=$('codeInput').value.trim();\n" |
| 330 | " if(!raw){note($('loginNote'),'Paste the code or the redirect address first.','err');return;}\n" |
| 331 | " var b=$('btnFinish');\n" |
| 332 | " b.disabled=true;b.textContent='Exchanging...';\n" |
| 333 | " note($('loginNote'),'Exchanging the code for a token.');\n" |
| 334 | " api('finish','code='+encodeURIComponent(raw)).then(function(d){\n" |
| 335 | " b.disabled=false;b.textContent='Submit Code';\n" |
| 336 | " if(!d||!d.ok){\n" |
| 337 | " note($('loginNote'),(d&&(d.detail||d.error))||'exchange failed','err');\n" |
| 338 | " return;\n" |
| 339 | " }\n" |
| 340 | " note($('loginNote'),'');\n" |
| 341 | " $('step2').classList.remove('on');\n" |
| 342 | " $('step1').classList.add('on');\n" |
| 343 | " $('codeInput').value='';\n" |
| 344 | " render(d);\n" |
| 345 | " toast('Signed in as '+(d.account||'Claude account'));\n" |
| 346 | " }).catch(function(e){\n" |
| 347 | " b.disabled=false;b.textContent='Submit Code';\n" |
| 348 | " note($('loginNote'),'Exchange failed: '+e.message,'err');\n" |
| 349 | " });\n" |
| 350 | "}\n" |
| 351 | "\n" |
| 352 | "function cancel(){\n" |
| 353 | " api('cancel').then(function(){\n" |
| 354 | " $('step2').classList.remove('on');\n" |
| 355 | " $('step1').classList.add('on');\n" |
| 356 | " $('codeInput').value='';\n" |
| 357 | " note($('loginNote'),'');\n" |
| 358 | " toast('Pending login cancelled');\n" |
| 359 | " load();\n" |
| 360 | " }).catch(function(e){toast('Cancel failed: '+e.message);});\n" |
| 361 | "}\n" |
| 362 | "\n" |
| 363 | "function refreshToken(){\n" |
| 364 | " var b=$('btnRefresh');\n" |
| 365 | " b.disabled=true;b.classList.add('loading');\n" |
| 366 | " b.lastChild.textContent=' Refreshing...';\n" |
| 367 | " note($('refreshNote'),'Asking Claude for a new access token...');\n" |
| 368 | " api('refresh').then(function(d){\n" |
| 369 | " b.disabled=false;b.classList.remove('loading');\n" |
| 370 | " b.lastChild.textContent='Refresh Token Now';\n" |
| 371 | " if(!d||!d.ok){\n" |
| 372 | " note($('refreshNote'),(d&&(d.detail||d.error))||'refresh failed','err');\n" |
| 373 | " return;\n" |
| 374 | " }\n" |
| 375 | " note($('refreshNote'),'Token refreshed. Expires in '+fmtExpiry(d.expires_in_sec)+'.','ok');\n" |
| 376 | " render(d);\n" |
| 377 | " }).catch(function(e){\n" |
| 378 | " b.disabled=false;b.classList.remove('loading');\n" |
| 379 | " b.lastChild.textContent='Refresh Token Now';\n" |
| 380 | " note($('refreshNote'),'Refresh failed: '+e.message,'err');\n" |
| 381 | " });\n" |
| 382 | "}\n" |
| 383 | "\n" |
| 384 | "function copyLink(){\n" |
| 385 | " if(!authUrl)return;\n" |
| 386 | " var done=function(){toast('Link copied');};\n" |
| 387 | " if(navigator.clipboard&&navigator.clipboard.writeText){\n" |
| 388 | " navigator.clipboard.writeText(authUrl).then(done).catch(function(){toast('Copy failed');});\n" |
| 389 | " }else{toast('Copy not available');}\n" |
| 390 | "}\n" |
| 391 | "\n" |
| 392 | "$('btnStart').onclick=function(){start(false);};\n" |
| 393 | "$('btnRelogin').onclick=function(){start(true);};\n" |
| 394 | "$('btnFinish').onclick=finish;\n" |
| 395 | "$('btnCancel').onclick=cancel;\n" |
| 396 | "$('btnRefresh').onclick=refreshToken;\n" |
| 397 | "$('btnReload').onclick=load;\n" |
| 398 | "$('btnCopy').onclick=copyLink;\n" |
| 399 | "$('codeInput').addEventListener('keydown',function(e){\n" |
| 400 | " if(e.key==='Enter'&&(e.metaKey||e.ctrlKey)){e.preventDefault();finish();}\n" |
| 401 | "});\n" |
| 402 | "load();\n" |
| 403 | "</script>\n" |
| 404 | "\002</body></html>\n" |
| 405 | ; |
| 406 | |
| 407 | #endif /* SX_CCLOGIN_UI_HTML_H */ |