scorpiox-bot-plugin-antigravity-login
←ui.htmlhtml
331 lines · 13 KBHEADBlameDownload
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>google</title>
5<!--TOKENS-->
6<style>
7*{box-sizing:border-box}
8html,body{margin:0;min-height:100%}
9body{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)}
40a.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.hint{font-size:12px;color:var(--text-2);margin:10px 0 0}
46.step{display:none}
47.step.on{display:block}
48.authurl{margin:10px 0;padding:10px 11px;border-radius:10px;background:var(--code-bg);
49 border:1px solid var(--line);font-family:var(--mono);font-size:11.5px;
50 word-break:break-all;max-height:120px;overflow:auto;color:var(--text)}
51textarea{width:100%;min-height:82px;resize:vertical;border-radius:10px;padding:10px 11px;
52 border:1px solid var(--line);background:var(--input-bg);color:var(--text);
53 font-family:var(--mono);font-size:12px;line-height:1.45}
54textarea:focus{outline:2px solid var(--blue);outline-offset:-1px}
55.note{display:none;margin-top:10px;padding:9px 11px;border-radius:10px;font-size:12.5px;
56 border:1px solid var(--line);background:var(--surface-2)}
57.note.show{display:block}
58.note.err{color:var(--red);border-color:rgba(255,69,58,.35)}
59.note.ok{color:var(--green);border-color:rgba(48,209,88,.35)}
60.empty{padding:10px 0;color:var(--text-2);font-size:12.5px}
61.toast{position:fixed;left:50%;bottom:18px;transform:translate(-50%,14px);opacity:0;
62 pointer-events:none;background:var(--modal-bg);border:1px solid var(--line-2);
63 color:var(--text);border-radius:999px;padding:8px 16px;font-size:12.5px;
64 box-shadow:var(--shadow-lg);transition:opacity .18s var(--ease),transform .18s var(--ease);
65 z-index:9;max-width:calc(100vw - 32px)}
66.toast.show{opacity:1;transform:translate(-50%,0)}
67#themeToggle{background:var(--surface-2);border:1px solid var(--line);color:var(--text);
68 border-radius:980px;padding:5px 12px;font-size:12px;font-weight:600;cursor:pointer;
69 font-family:inherit}
70@media (max-width:520px){
71 #app{padding:12px 12px 32px}
72 .kv{grid-template-columns:1fr;gap:2px 0}
73 .kv .k{margin-top:8px}
74 .card{padding:13px;border-radius:12px}
75}
76</style>
77</head>
78<body>
79<div id="app">
80 <div class="hd">
81 <div class="grow">
82 <h1>Google Antigravity</h1>
83 <div class="sub" id="sub">OAuth 2.0 PKCE login on this node</div>
84 </div>
85 <span class="pill off" id="pill"><span class="dot"></span><span id="pillText">Checking</span></span>
86 <button id="themeToggle" class="embed-hide" type="button">Theme</button>
87 </div>
88
89 <div class="card">
90 <h2>Session</h2>
91 <p class="lead" id="sessionLead">Reading the local Antigravity credentials.</p>
92 <div class="kv" id="session"></div>
93 <div class="row" style="margin-top:14px">
94 <button class="btn ghost" id="btnRefresh" type="button">Refresh Token Now</button>
95 <button class="btn ghost" id="btnReload" type="button">Reload</button>
96 </div>
97 <div class="note" id="refreshNote"></div>
98 </div>
99
100 <div class="card">
101 <h2>OAuth login</h2>
102 <p class="lead">Sign in with Google. Nothing leaves this node: the login CLI performs the
103 exchange and writes the credential file here.</p>
104
105 <div class="step on" id="step1">
106 <button class="btn" id="btnStart" type="button">Start Google Login</button>
107 <p class="hint">This generates a PKCE challenge and an authorization link. No token is
108 created until you paste the code back.</p>
109 </div>
110
111 <div class="step" id="step2">
112 <div class="row">
113 <a class="btn" id="linkOpen" href="#" target="_blank" rel="noopener noreferrer">Open Google Sign-in</a>
114 <button class="btn ghost" id="btnCopy" type="button">Copy link</button>
115 <button class="btn ghost" id="btnCancel" type="button">Cancel</button>
116 </div>
117 <div class="authurl" id="authUrl"></div>
118 <p class="hint" id="flowHint">After approving, the browser lands on antigravity.google. Copy the
119 whole address (or just the <span style="font-family:var(--mono)">code=</span> value) and paste it below.</p>
120 <textarea id="codeInput" spellcheck="false" autocomplete="off"
121 placeholder="Paste the authorization code or the full redirect URL"></textarea>
122 <div class="row" style="margin-top:10px">
123 <button class="btn" id="btnFinish" type="button">Authorize &amp; Discover Project</button>
124 </div>
125 <div class="note" id="loginNote"></div>
126 </div>
127 </div>
128
129 <div class="card">
130 <h2>Companion project</h2>
131 <p class="lead">The Google Cloud project the Antigravity session bills against.</p>
132 <div class="kv" id="project"></div>
133 </div>
134</div>
135
136<div class="toast" id="toast"></div>
137
138<script>
139var q=new URLSearchParams(location.search);
140var node=q.get('node')||'';
141var sid=q.get('id')||'';
142var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||
143 localStorage.getItem('bot_active_pwd')||'';
144
145/* Two call routes. Getting this wrong is the most common plugin bug:
146 * page served through the hub (bot.scorpiox.net/plugins?plugin=...&node=..)
147 * -> call the hub proxy back: /plugins?plugin=plugin_antigravity_login&action=..
148 * opened directly on the node
149 * -> the plugin itself is the route: /plugin_antigravity_login?action=..
150 * Calling /plugins?plugin= on the node returns the discovery list, not us. */
151var HUB=q.get('plugin')||'';
152function url(action,extra){
153 return (HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_antigravity_login')+
154 '?action='+encodeURIComponent(action)+
155 (extra?('&'+extra):'')+
156 (node?'&node='+encodeURIComponent(node):'')+
157 (sid?'&id='+encodeURIComponent(sid):'')+
158 (pwd?'&pwd='+encodeURIComponent(pwd):'');
159}
160function hdr(){
161 var h={};
162 if(pwd)h['X-Bot-Password']=pwd;
163 return h;
164}
165function api(action,extra){
166 return fetch(url(action,extra),{headers:hdr()}).then(function(r){
167 return r.json().catch(function(){return {ok:false,error:'bad response'};});
168 });
169}
170
171var $=function(id){return document.getElementById(id);};
172function toast(msg){
173 var t=$('toast');t.textContent=msg;t.classList.add('show');
174 clearTimeout(t._t);t._t=setTimeout(function(){t.classList.remove('show');},2200);
175}
176function note(el,msg,kind){
177 el.textContent=msg||'';
178 el.className='note'+(msg?' show '+(kind||''):'');
179}
180function kv(el,rows){
181 el.innerHTML='';
182 rows.forEach(function(r){
183 var a=document.createElement('div');a.className='k';a.textContent=r[0];
184 var b=document.createElement('div');b.className='v'+(r[2]?' plain':'');
185 b.textContent=r[1];el.appendChild(a);el.appendChild(b);
186 });
187}
188function fmtExpiry(sec){
189 if(typeof sec!=='number')return '-';
190 if(sec<=0)return 'expired';
191 if(sec<90)return sec+'s';
192 if(sec<5400)return Math.round(sec/60)+' min';
193 if(sec<172800)return Math.round(sec/3600)+' h';
194 if(sec<63072000)return Math.round(sec/86400)+' d';
195 return Math.round(sec/31536000)+' yr';
196}
197function setPill(st){
198 var p=$('pill'),t=$('pillText');
199 if(st.logged_in&&st.expired){p.className='pill warn';t.textContent='Expired';}
200 else if(st.logged_in){p.className='pill ok';t.textContent='Connected';}
201 else if(st.pending){p.className='pill warn';t.textContent='Signing in';}
202 else {p.className='pill off';t.textContent='Not Connected';}
203}
204function render(st){
205 setPill(st);
206 $('sub').textContent=st.email?st.email:'OAuth 2.0 PKCE login on this node';
207
208 if(st.logged_in){
209 $('sessionLead').textContent=st.expired
210 ? 'The session is present but its access token has expired. Use Refresh Token Now.'
211 : 'This node holds a Google Antigravity session.';
212 }else{
213 $('sessionLead').textContent='No Google session on this node yet. Start a login below.';
214 }
215 kv($('session'),[
216 ['Account', st.email||'-', true],
217 ['Logged in', st.logged_in?'yes':'no', true],
218 ['Refresh token', st.has_refresh?'stored':'none', true],
219 ['Token expires', st.logged_in?fmtExpiry(st.expires_in_sec):'-', true],
220 ['Login pending', st.pending?'yes':'no', true],
221 ['Login CLI', st.cli_present?'found':'not found', true],
222 ['Credentials', st.credentials_path||'-']
223 ]);
224 kv($('project'),[
225 ['Project ID', st.project_id||'(consumer shared project)', !st.project_id],
226 ['Profile', st.profile||'-', true],
227 ['Provider', 'google (Antigravity)', true]
228 ]);
229
230 if(st.pending){$('step1').classList.remove('on');$('step2').classList.add('on');}
231}
232function load(){
233 return api('status').then(function(d){
234 if(d&&d.ok)render(d);
235 else toast((d&&d.error)||'status failed');
236 }).catch(function(e){toast('Status failed: '+e.message);});
237}
238
239var authUrl='';
240function start(){
241 var b=$('btnStart');
242 b.disabled=true;b.textContent='Starting...';
243 api('start').then(function(d){
244 b.disabled=false;b.textContent='Start Google Login';
245 if(!d||!d.ok){toast((d&&(d.detail||d.error))||'start failed');return;}
246 authUrl=d.auth_url||'';
247 $('authUrl').textContent=authUrl;
248 $('linkOpen').setAttribute('href',authUrl);
249 if(d.hint)$('flowHint').textContent=d.hint;
250 $('step1').classList.remove('on');
251 $('step2').classList.add('on');
252 $('codeInput').focus();
253 }).catch(function(e){
254 b.disabled=false;b.textContent='Start Google Login';
255 toast('Start failed: '+e.message);
256 });
257}
258
259function finish(){
260 var raw=$('codeInput').value.trim();
261 if(!raw){note($('loginNote'),'Paste the code or the redirect address first.','err');return;}
262 var b=$('btnFinish');
263 b.disabled=true;b.textContent='Authorizing...';
264 note($('loginNote'),'Exchange in progress. The Google project discovery can take a few seconds.');
265 api('finish','code='+encodeURIComponent(raw)).then(function(d){
266 b.disabled=false;b.textContent='Authorize & Discover Project';
267 if(!d||!d.ok){
268 note($('loginNote'),(d&&(d.detail||d.error))||'exchange failed','err');
269 return;
270 }
271 note($('loginNote'),'');
272 $('step2').classList.remove('on');
273 $('step1').classList.add('on');
274 $('codeInput').value='';
275 render(d);
276 toast('Signed in as '+(d.email||'Google account'));
277 }).catch(function(e){
278 b.disabled=false;b.textContent='Authorize & Discover Project';
279 note($('loginNote'),'Exchange failed: '+e.message,'err');
280 });
281}
282
283function cancel(){
284 api('cancel').then(function(){
285 $('step2').classList.remove('on');
286 $('step1').classList.add('on');
287 $('codeInput').value='';
288 note($('loginNote'),'');
289 toast('Pending login cancelled');
290 load();
291 }).catch(function(e){toast('Cancel failed: '+e.message);});
292}
293
294function refreshToken(){
295 var b=$('btnRefresh');
296 b.disabled=true;b.textContent='Refreshing...';
297 note($('refreshNote'),'Asking Google for a new access token...');
298 api('refresh').then(function(d){
299 b.disabled=false;b.textContent='Refresh Token Now';
300 if(!d||!d.ok){
301 note($('refreshNote'),(d&&(d.detail||d.error))||'refresh failed','err');
302 return;
303 }
304 note($('refreshNote'),'Token refreshed. Expires in '+fmtExpiry(d.expires_in_sec)+'.','ok');
305 render(d);
306 }).catch(function(e){
307 b.disabled=false;b.textContent='Refresh Token Now';
308 note($('refreshNote'),'Refresh failed: '+e.message,'err');
309 });
310}
311
312function copyLink(){
313 if(!authUrl)return;
314 var done=function(){toast('Link copied');};
315 if(navigator.clipboard&&navigator.clipboard.writeText){
316 navigator.clipboard.writeText(authUrl).then(done).catch(function(){toast('Copy failed');});
317 }else{toast('Copy not available');}
318}
319
320$('btnStart').onclick=start;
321$('btnFinish').onclick=finish;
322$('btnCancel').onclick=cancel;
323$('btnRefresh').onclick=refreshToken;
324$('btnReload').onclick=load;
325$('btnCopy').onclick=copyLink;
326$('codeInput').addEventListener('keydown',function(e){
327 if(e.key==='Enter'&&(e.metaKey||e.ctrlKey)){e.preventDefault();finish();}
328});
329load();
330</script>
331</body></html>