-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.html
More file actions
445 lines (381 loc) · 12.7 KB
/
Copy pathSidebar.html
File metadata and controls
445 lines (381 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<base target="_top">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Google Sans', Roboto, Arial, sans-serif;
font-size: 13px;
color: #202124;
background: #fff;
height: 100vh;
display: flex;
flex-direction: column;
}
/* ── Header ── */
.header {
display: flex;
align-items: center;
gap: 8px;
padding: 14px 16px 12px;
border-bottom: 1px solid #e8eaed;
}
.header-icon {
width: 24px;
height: 24px;
background: #1a73e8;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.header-icon svg { display: block; }
.header-title {
font-size: 14px;
font-weight: 500;
color: #202124;
flex: 1;
}
/* ── Content ── */
.content {
flex: 1;
padding: 20px 16px;
display: flex;
flex-direction: column;
}
/* ── Setup State ── */
#setup-state { display: none; }
#setup-state.visible { display: flex; flex-direction: column; gap: 16px; }
.setup-description {
font-size: 12px;
color: #5f6368;
line-height: 1.5;
}
.field-label {
font-size: 11px;
font-weight: 500;
color: #3c4043;
margin-bottom: 5px;
text-transform: uppercase;
letter-spacing: 0.3px;
}
.input-row {
display: flex;
gap: 6px;
}
.input-row input {
flex: 1;
padding: 8px 10px;
border: 1px solid #dadce0;
border-radius: 4px;
font-size: 13px;
color: #202124;
outline: none;
font-family: inherit;
transition: border-color 0.15s;
}
.input-row input:focus { border-color: #1a73e8; }
.btn-secondary {
padding: 8px 12px;
background: #f1f3f4;
color: #3c4043;
border: 1px solid #dadce0;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
white-space: nowrap;
font-family: inherit;
transition: background 0.15s;
}
.btn-secondary:hover:not(:disabled) { background: #e8eaed; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.key-status {
font-size: 11px;
min-height: 14px;
margin-top: 4px;
}
.key-status.valid { color: #188038; }
.key-status.invalid { color: #c5221f; }
.key-status.testing { color: #5f6368; }
.btn-primary {
width: 100%;
padding: 10px;
background: #1a73e8;
color: #fff;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
font-family: inherit;
transition: background 0.15s;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.btn-primary:hover:not(:disabled) { background: #1557b0; }
.btn-primary:disabled { background: #dadce0; color: #80868b; cursor: not-allowed; }
/* ── Active State ── */
#active-state { display: none; }
#active-state.visible { display: flex; flex-direction: column; gap: 20px; }
.status-card {
background: #f0f7ff;
border: 1px solid #c5dff8;
border-radius: 8px;
padding: 14px 16px;
display: flex;
align-items: flex-start;
gap: 12px;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #188038;
margin-top: 3px;
flex-shrink: 0;
box-shadow: 0 0 0 3px rgba(24,128,56,0.15);
}
.status-info {}
.status-label {
font-size: 13px;
font-weight: 500;
color: #202124;
}
.status-expires {
font-size: 11px;
color: #5f6368;
margin-top: 2px;
}
.btn-danger {
width: 100%;
padding: 10px;
background: #fff;
color: #c5221f;
border: 1px solid #f28b82;
border-radius: 6px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
font-family: inherit;
transition: background 0.15s;
}
.btn-danger:hover:not(:disabled) { background: #fce8e6; }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
/* ── Info banner ── */
.info-msg {
padding: 10px 12px;
background: #fef7e0;
border: 1px solid #f9c945;
border-radius: 4px;
font-size: 12px;
color: #7a5900;
line-height: 1.4;
}
/* ── Error / Info ── */
.error-msg {
display: none;
padding: 10px 12px;
background: #fce8e6;
border: 1px solid #f28b82;
border-radius: 4px;
font-size: 12px;
color: #c5221f;
line-height: 1.4;
}
.error-msg.visible { display: block; }
/* ── Spinner ── */
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
display: inline-block;
width: 13px;
height: 13px;
border: 2px solid rgba(255,255,255,0.4);
border-top-color: #fff;
border-radius: 50%;
animation: spin 0.7s linear infinite;
}
.spinner.dark {
border-color: rgba(0,0,0,0.15);
border-top-color: #c5221f;
}
</style>
</head>
<body>
<div class="header">
<div class="header-icon">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
<path d="M7 1L8.5 5.5H13L9.5 8.5L11 13L7 10L3 13L4.5 8.5L1 5.5H5.5L7 1Z" fill="white"/>
</svg>
</div>
<span class="header-title">Claude Assistant</span>
</div>
<div class="content">
<!-- ── Setup State ── -->
<div id="setup-state">
<p class="setup-description">
Automatically responds to <strong>@claude</strong> comments in this document.
Replies appear under the Claude Assistant account.
Your API key is stored securely in your Google account and never shared.
</p>
<div>
<div class="field-label">Anthropic API Key</div>
<div class="input-row">
<input type="password" id="api-key-input" placeholder="sk-ant-…" autocomplete="off">
<button class="btn-secondary" id="test-btn">Test</button>
</div>
<div class="key-status" id="key-status"></div>
</div>
<div class="error-msg" id="activate-error"></div>
<button class="btn-primary" id="activate-btn" disabled>Activate</button>
</div>
<!-- ── Active State ── -->
<div id="active-state">
<div class="status-card">
<div class="status-dot"></div>
<div class="status-info">
<div class="status-label">Active in this document</div>
<div class="status-expires" id="expires-text"></div>
</div>
</div>
<div class="info-msg">
If another collaborator activates Claude Assistant on this document, their channel becomes active and yours stops processing. Reactivate to reclaim it.
</div>
<div class="error-msg" id="deactivate-error"></div>
<button class="btn-danger" id="deactivate-btn">Deactivate</button>
</div>
</div>
<script>
var keyValid = false;
// ── Helpers ──────────────────────────────────────────────────────────────
function showState(name) {
document.getElementById('setup-state').classList.remove('visible');
document.getElementById('active-state').classList.remove('visible');
document.getElementById(name + '-state').classList.add('visible');
}
function showError(id, msg) {
var el = document.getElementById(id);
el.textContent = msg;
el.classList.add('visible');
}
function clearError(id) {
var el = document.getElementById(id);
el.textContent = '';
el.classList.remove('visible');
}
// ── Test API Key ─────────────────────────────────────────────────────────
document.getElementById('test-btn').addEventListener('click', function() {
var key = document.getElementById('api-key-input').value.trim();
var statusEl = document.getElementById('key-status');
var testBtn = document.getElementById('test-btn');
var activateBtn = document.getElementById('activate-btn');
if (!key) {
statusEl.className = 'key-status invalid';
statusEl.textContent = 'Enter a key first.';
return;
}
keyValid = false;
activateBtn.disabled = true;
testBtn.disabled = true;
statusEl.className = 'key-status testing';
statusEl.textContent = 'Testing\u2026';
google.script.run
.withSuccessHandler(function(result) {
testBtn.disabled = false;
if (result.ok) {
keyValid = true;
statusEl.className = 'key-status valid';
statusEl.textContent = '\u2713 Key is valid';
activateBtn.disabled = false;
} else {
statusEl.className = 'key-status invalid';
statusEl.textContent = '\u2717 ' + result.error;
}
})
.withFailureHandler(function(err) {
testBtn.disabled = false;
statusEl.className = 'key-status invalid';
statusEl.textContent = '\u2717 ' + (err.message || String(err));
})
.testApiKey(key);
});
// ── Activate ─────────────────────────────────────────────────────────────
document.getElementById('activate-btn').addEventListener('click', function() {
if (!keyValid) return;
var key = document.getElementById('api-key-input').value.trim();
var btn = document.getElementById('activate-btn');
clearError('activate-error');
btn.disabled = true;
btn.innerHTML = '<span class="spinner"></span> Activating\u2026';
google.script.run
.withSuccessHandler(function(result) {
btn.innerHTML = 'Activate';
renderActiveState(result);
})
.withFailureHandler(function(err) {
btn.disabled = false;
btn.innerHTML = 'Activate';
showError('activate-error', err.message || String(err));
})
.activate(key);
});
// ── Deactivate ───────────────────────────────────────────────────────────
document.getElementById('deactivate-btn').addEventListener('click', function() {
var btn = document.getElementById('deactivate-btn');
clearError('deactivate-error');
btn.disabled = true;
btn.innerHTML = '<span class="spinner dark"></span> Deactivating\u2026';
google.script.run
.withSuccessHandler(function() {
btn.innerHTML = 'Deactivate';
// Clear input and key status before showing setup
document.getElementById('api-key-input').value = '';
document.getElementById('key-status').textContent = '';
document.getElementById('key-status').className = 'key-status';
keyValid = false;
document.getElementById('activate-btn').disabled = true;
showState('setup');
})
.withFailureHandler(function(err) {
btn.disabled = false;
btn.innerHTML = 'Deactivate';
showError('deactivate-error', err.message || String(err));
})
.deactivateDoc();
});
// ── Render Active State ───────────────────────────────────────────────────
function renderActiveState(status) {
var expiresEl = document.getElementById('expires-text');
if (status && status.expiresAt) {
expiresEl.textContent = 'Active until ' + status.expiresAt;
} else {
expiresEl.textContent = '';
}
showState('active');
}
// ── Init ─────────────────────────────────────────────────────────────────
document.addEventListener('DOMContentLoaded', function() {
google.script.run
.withSuccessHandler(function(status) {
if (status && status.active) {
renderActiveState(status);
} else {
showState('setup');
}
})
.withFailureHandler(function() {
showState('setup');
})
.getWatchStatus();
});
</script>
</body>
</html>