-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
691 lines (584 loc) · 24.8 KB
/
index.html
File metadata and controls
691 lines (584 loc) · 24.8 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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>M365 Connector — AI agent bridge to Microsoft 365</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@200;300;400&family=DM+Mono:wght@400&display=swap');
:root {
--bg: #faf9f7;
--text: #2c2a28;
--text-dim: #8a8580;
--text-light: #b0aaa4;
--accent: #0078d4;
--accent-hover: #005a9e;
--border: #e8e4e0;
--surface: #f2f0ed;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'DM Sans', sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
line-height: 1.7;
}
.page {
max-width: 680px;
margin: 0 auto;
padding: 6vh 2rem 8vh;
opacity: 0;
animation: fadeUp 1.4s cubic-bezier(0.16, 1, 0.3, 1) 0.15s forwards;
position: relative;
z-index: 1;
}
h1 {
font-weight: 200;
font-size: clamp(1.6rem, 4vw, 2.4rem);
letter-spacing: 0.15em;
text-transform: uppercase;
color: var(--text);
margin-bottom: 0.3em;
}
h1::after {
content: '';
display: block;
width: 32px;
height: 1px;
background: linear-gradient(90deg, var(--border), transparent);
margin-top: 1.2em;
}
.intro {
font-weight: 300;
font-size: clamp(0.88rem, 1.3vw, 0.95rem);
color: var(--text-dim);
font-style: italic;
margin-bottom: 2rem;
line-height: 1.7;
}
h2 {
font-weight: 300;
font-size: clamp(0.85rem, 1.5vw, 1.05rem);
letter-spacing: 0.18em;
text-transform: uppercase;
color: var(--text-dim);
margin: 3rem 0 1.5rem;
}
h3 {
font-weight: 400;
font-size: clamp(1rem, 1.8vw, 1.2rem);
letter-spacing: 0.04em;
color: var(--text);
margin: 2.5rem 0 0.6rem;
}
p {
font-weight: 300;
font-size: clamp(0.88rem, 1.3vw, 0.95rem);
color: var(--text);
margin-bottom: 0.8em;
}
a { color: var(--accent); text-decoration: none; transition: color 0.3s ease; }
a:hover { color: var(--accent-hover); }
code {
font-family: 'DM Mono', monospace;
font-size: 0.85em;
background: var(--surface);
padding: 0.15em 0.4em;
border-radius: 3px;
}
pre {
background: var(--surface);
padding: 1.2em 1.4em;
border-radius: 6px;
overflow-x: auto;
margin: 1em 0 1.5em;
border: 1px solid var(--border);
}
pre code {
background: none;
padding: 0;
font-size: 0.82rem;
line-height: 1.6;
color: var(--text);
}
.callout {
background: var(--surface);
border-left: 3px solid var(--accent);
padding: 1em 1.4em;
border-radius: 4px;
margin: 0 0 2rem;
font-weight: 300;
font-size: clamp(0.84rem, 1.2vw, 0.92rem);
color: var(--text-dim);
line-height: 1.7;
}
.callout strong { color: var(--text); }
table {
width: 100%;
border-collapse: collapse;
margin: 1em 0 1.5em;
font-size: clamp(0.82rem, 1.2vw, 0.9rem);
}
th {
font-weight: 400;
text-align: left;
padding: 0.6em 0.8em;
border-bottom: 2px solid var(--border);
color: var(--text-dim);
font-size: 0.8rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
td {
font-weight: 300;
padding: 0.6em 0.8em;
border-bottom: 1px solid var(--border);
}
ul, ol {
font-weight: 300;
font-size: clamp(0.88rem, 1.3vw, 0.95rem);
margin: 0.5em 0 1.2em 1.5em;
color: var(--text);
}
li { margin-bottom: 0.4em; }
.diagram {
font-family: 'DM Mono', monospace;
font-size: 0.82rem;
line-height: 1.6;
color: var(--text-dim);
background: var(--surface);
padding: 1.2em 1.4em;
border-radius: 6px;
border: 1px solid var(--border);
margin: 1em 0 1.5em;
overflow-x: auto;
white-space: pre;
}
@keyframes fadeUp {
from { opacity: 0; transform: translateY(18px); }
to { opacity: 1; transform: translateY(0); }
}
.anchor { text-decoration: none; color: var(--text-light); margin-left: 0.3em; opacity: 0; transition: opacity 0.3s; font-weight: 200; }
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; }
.anchor:hover { color: var(--accent); }
.badge {
display: inline-block;
font-family: 'DM Mono', monospace;
font-size: 0.7rem;
padding: 0.15em 0.5em;
border-radius: 3px;
background: var(--accent);
color: #fff;
letter-spacing: 0.04em;
vertical-align: middle;
margin-left: 0.4em;
}
.steps {
counter-reset: step;
list-style: none;
margin-left: 0;
padding-left: 0;
}
.steps li {
counter-increment: step;
position: relative;
padding-left: 2.4em;
margin-bottom: 1.2em;
}
.steps li::before {
content: counter(step);
position: absolute;
left: 0;
top: 0.05em;
width: 1.6em;
height: 1.6em;
border-radius: 50%;
background: var(--surface);
border: 1px solid var(--border);
text-align: center;
line-height: 1.6em;
font-size: 0.78rem;
font-weight: 400;
color: var(--text-dim);
}
.copy-wrap {
position: relative;
}
.copy-wrap pre {
padding-right: 3em;
white-space: pre-wrap;
word-break: break-all;
}
.copy-btn {
position: absolute;
top: 0.6em;
right: 0.6em;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 4px;
padding: 0.25em 0.5em;
cursor: pointer;
font-family: 'DM Mono', monospace;
font-size: 0.7rem;
color: var(--text-dim);
transition: all 0.2s;
line-height: 1;
}
.copy-btn:hover {
color: var(--accent);
border-color: var(--accent);
}
.copy-btn.copied {
color: #2ea043;
border-color: #2ea043;
}
</style>
</head>
<body>
<div class="page">
<h1 id="m365-connector">M365 Connector</h1>
<p style="font-size: 0.75rem; color: var(--text-light); font-weight: 200; margin-bottom: 2rem;">v1.2.4 · Updated Mar 23, 2026</p>
<div class="callout"><strong>Browser extension + MCP server</strong> that lets AI agents search, read, and interact with your Microsoft 365 data. Works with Claude Code, Claude Desktop, and any MCP-compatible client.</div>
<p class="intro">Install the Chrome extension, start the MCP server, and your AI agent gets full access to M365 — emails, files, Teams chats, calendar events, and people directory. No API keys, no app registrations. Tokens are captured passively from the browser.</p>
<!-- WHAT IT DOES -->
<h2 id="tools">MCP Tools</h2>
<p>Five tools exposed to any MCP client:</p>
<table>
<thead>
<tr><th>Tool</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>search</code></td><td>Search across emails, files, Teams chats, calendar events, and external connectors</td></tr>
<tr><td><code>open</code></td><td>Read best-effort content for a search result (via opaque read handle)</td></tr>
<tr><td><code>whoami</code></td><td>Query current signed-in user profile via Microsoft Graph <code>/me</code></td></tr>
<tr><td><code>find_people</code></td><td>Find directory people with multi-field filters</td></tr>
<tr><td><code>count_people</code></td><td>Count directory people matching filters</td></tr>
</tbody>
</table>
<!-- ARCHITECTURE -->
<h2 id="architecture">Architecture</h2>
<div class="diagram">MCP Client MCP Server (daemon) Browser Extension
(Claude Code) (Node.js) (Chrome/Edge MV3)
HTTP :52366 WebSocket :52365
───────────► ◄──────────────────►
Streamable HTTP IPC bridge Captures tokens,
transport (localhost) executes API calls</div>
<p>The MCP server runs as a long-lived process. The browser extension connects to it over WebSocket and handles all M365 API calls using tokens passively captured from the browser.</p>
<table>
<thead>
<tr><th>Layer</th><th>Details</th></tr>
</thead>
<tbody>
<tr><td>Extension</td><td>Chrome/Edge Manifest V3, captures Substrate + Graph tokens</td></tr>
<tr><td>MCP Server</td><td>Node.js, Streamable HTTP transport on port 52366</td></tr>
<tr><td>IPC</td><td>WebSocket on port 52365 (localhost only)</td></tr>
<tr><td>Auth</td><td>Passive token capture from browser sessions — no app registration needed</td></tr>
<tr><td>APIs</td><td>Microsoft Substrate + Microsoft Graph</td></tr>
</tbody>
</table>
<!-- INSTALL -->
<h2 id="install">Install</h2>
<h3 id="install-extension">1. Install the browser extension</h3>
<p>Install from the Chrome Web Store:</p>
<p><a href="https://chromewebstore.google.com/detail/m365-connector/igchbccebjlcdogcboebgldjdihkdmbb" style="font-family: 'DM Mono', monospace; font-size: 0.85rem;">Chrome Web Store → M365 Connector</a></p>
<p>Works on Chrome and Edge. After installing, the extension automatically captures auth tokens from your M365 session. Click the extension icon to verify — <strong>Substrate</strong> should show <strong>Valid</strong>.</p>
<h3 id="install-server">2. Start the MCP server</h3>
<p>Run with npx (no install needed):</p>
<div class="copy-wrap">
<button class="copy-btn" onclick="copyCmd(this)">copy</button>
<pre><code>npx m365connector</code></pre>
</div>
<p>Or install globally:</p>
<div class="copy-wrap">
<button class="copy-btn" onclick="copyCmd(this)">copy</button>
<pre><code>npm install -g m365connector && m365connector</code></pre>
</div>
<p>You should see:</p>
<pre><code>[m365connector/ws] listening on ws://127.0.0.1:52365
[m365connector] MCP HTTP listening on http://127.0.0.1:52366/mcp</code></pre>
<h3 id="configure-client">3. Configure your MCP client</h3>
<p>Add to your MCP config (e.g. <code>~/.claude/mcp.json</code>):</p>
<div class="copy-wrap">
<button class="copy-btn" onclick="copyCmd(this)">copy</button>
<pre><code>{
"mcpServers": {
"m365-connector": {
"type": "http",
"url": "http://127.0.0.1:52366/mcp"
}
}
}</code></pre>
</div>
<p>Restart your MCP client to pick up the config.</p>
<!-- PREREQUISITES -->
<h2 id="prerequisites">Prerequisites</h2>
<ul>
<li>Node.js 18+</li>
<li>Chrome or Edge browser</li>
<li>An M365 account (work or school)</li>
</ul>
<!-- USAGE -->
<h2 id="usage">Usage</h2>
<p>Once connected, ask your AI agent to search M365 naturally:</p>
<pre><code>> Search my email for messages about the quarterly review
> Find files related to Project Alpha
> Look up John in the company directory
> Search Teams chats about the deployment issue
> What meetings do I have tomorrow?</code></pre>
<p>The agent uses <code>search</code> to find results, then <code>open</code> with a result's <code>_readHandle</code> to fetch full content. It can also call <code>whoami</code>, <code>find_people</code>, and <code>count_people</code> for directory and profile lookups.</p>
<!-- TOOLS REFERENCE -->
<h2 id="tools-reference">Tools reference</h2>
<h3 id="tool-search">search</h3>
<p>Search across M365 data sources.</p>
<table>
<thead>
<tr><th>Parameter</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>query</code></td><td>string</td><td>yes</td><td></td><td>Search query</td></tr>
<tr><td><code>conversation_id</code></td><td>string</td><td>yes</td><td></td><td>Identifier for grouping related requests</td></tr>
<tr><td><code>source</code></td><td>string</td><td>no</td><td><code>all</code></td><td><code>all</code>, <code>email</code>, <code>files</code>, <code>chat</code>, <code>events</code>, <code>external</code></td></tr>
<tr><td><code>connector</code></td><td>string</td><td>no</td><td></td><td>External connector name (when source=<code>external</code>)</td></tr>
<tr><td><code>size</code></td><td>integer</td><td>no</td><td>10</td><td>Results per page (1–25)</td></tr>
<tr><td><code>from</code></td><td>integer</td><td>no</td><td>0</td><td>Pagination offset</td></tr>
</tbody>
</table>
<h3 id="tool-open">open</h3>
<p>Read the content of a search result.</p>
<table>
<thead>
<tr><th>Parameter</th><th>Type</th><th>Required</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>read_handle</code></td><td>string</td><td>yes</td><td>Opaque handle from a search result's <code>_readHandle</code> field</td></tr>
<tr><td><code>conversation_id</code></td><td>string</td><td>yes</td><td>Same conversation ID used in the originating search</td></tr>
</tbody>
</table>
<p>Returns content with a <code>completeness</code> field: <code>full</code>, <code>partial</code>, or <code>snippet</code>.</p>
<h3 id="tool-whoami">whoami</h3>
<p>Get the current signed-in user's basic profile from Graph.</p>
<table>
<thead>
<tr><th>Parameter</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>conversation_id</code></td><td>string</td><td>yes</td><td></td><td>Conversation identifier</td></tr>
<tr><td><code>direct_reports_size</code></td><td>integer</td><td>no</td><td>30</td><td>Max direct reports to return (1–100)</td></tr>
</tbody>
</table>
<p>Returns display name, alias, email/UPN, title, department, office, phones, and best-effort <code>manager</code> and <code>directReports</code> info when directory scopes are available.</p>
<h3 id="tool-find-people">find_people</h3>
<p>Find people via Graph directory query.</p>
<table>
<thead>
<tr><th>Parameter</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>conversation_id</code></td><td>string</td><td>yes</td><td></td><td>Conversation identifier</td></tr>
<tr><td><code>query</code></td><td>string</td><td>no</td><td></td><td>Free-text query across person fields</td></tr>
<tr><td><code>alias</code></td><td>string</td><td>no</td><td></td><td>Filter by alias (<code>mailNickname</code>)</td></tr>
<tr><td><code>principalName</code></td><td>string</td><td>no</td><td></td><td>Filter by user principal name</td></tr>
<tr><td><code>displayName</code></td><td>string</td><td>no</td><td></td><td>Filter by display name</td></tr>
<tr><td><code>department</code></td><td>string</td><td>no</td><td></td><td>Filter by department (prefix match)</td></tr>
<tr><td><code>office</code></td><td>string</td><td>no</td><td></td><td>Filter by office location (prefix match)</td></tr>
<tr><td><code>title</code></td><td>string</td><td>no</td><td></td><td>Filter by job title (prefix match)</td></tr>
<tr><td><code>size</code></td><td>integer</td><td>no</td><td>20</td><td>Max people to return (1–50)</td></tr>
<tr><td><code>include_direct_reports</code></td><td>boolean</td><td>no</td><td>false</td><td>Include direct reports for each result</td></tr>
<tr><td><code>direct_reports_size</code></td><td>integer</td><td>no</td><td>30</td><td>Max direct reports per result (1–100)</td></tr>
</tbody>
</table>
<p>At least one filter parameter is required. Returns <code>{ filters, results, total }</code>.</p>
<h3 id="tool-count-people">count_people</h3>
<p>Count people matching directory filters without returning full results.</p>
<table>
<thead>
<tr><th>Parameter</th><th>Type</th><th>Required</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>conversation_id</code></td><td>string</td><td>yes</td><td>Conversation identifier</td></tr>
<tr><td><code>query</code></td><td>string</td><td>no</td><td>Free-text query across person fields</td></tr>
<tr><td><code>alias</code></td><td>string</td><td>no</td><td>Filter by alias</td></tr>
<tr><td><code>principalName</code></td><td>string</td><td>no</td><td>Filter by user principal name</td></tr>
<tr><td><code>displayName</code></td><td>string</td><td>no</td><td>Filter by display name</td></tr>
<tr><td><code>department</code></td><td>string</td><td>no</td><td>Filter by department (prefix match)</td></tr>
<tr><td><code>office</code></td><td>string</td><td>no</td><td>Filter by office location (prefix match)</td></tr>
<tr><td><code>title</code></td><td>string</td><td>no</td><td>Filter by job title (prefix match)</td></tr>
</tbody>
</table>
<p>Returns <code>{ filters, count }</code>.</p>
<!-- SKILL -->
<h2 id="skill">Using as a Claude Code skill</h2>
<p>M365 Connector ships with a <strong>Research</strong> skill that combines M365 search with web search (Lumina) to answer questions comprehensively. The skill gives Claude full knowledge of all 5 MCP tools plus a parallel dual-backend search strategy.</p>
<ol class="steps">
<li>
<strong>Install the extension + server</strong> — follow the <a href="#install">install steps</a> above.
</li>
<li>
<strong>Install the skill</strong> — use Claude Code's plugin system:
<pre><code>/plugin marketplace add ttthree/m365connector-docs
/plugin install research@m365connector-docs</code></pre>
<p style="margin-top: 0.8em; font-size: 0.85rem; color: var(--text-dim);">Or manually download <code>SKILL.md</code>:</p>
<pre><code>mkdir -p .claude/skills/research
curl -fsSL https://raw.githubusercontent.com/ttthree/m365connector-docs/main/skills/research/SKILL.md \
-o .claude/skills/research/SKILL.md</code></pre>
</li>
<li>
<strong>Use it</strong> — Claude Code discovers the skill automatically. Just ask:
<pre><code>> What emails did I get from my manager today?
> Summarize what's been happening on Project Alpha
> Who is Alice Smith? What team is she on?
> Find files related to the quarterly report</code></pre>
</li>
</ol>
<div class="callout"><strong>Dual-backend search.</strong> The Research skill always searches both M365 (internal data) and Lumina (public web) in parallel, then synthesizes a comprehensive answer. Use <code>--high</code> for exhaustive research mode.</div>
<!-- ENVIRONMENT VARIABLES -->
<h2 id="env">Environment variables</h2>
<table>
<thead>
<tr><th>Variable</th><th>Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>M365C_MCP_PORT</code></td><td>52366</td><td>HTTP port for MCP clients</td></tr>
<tr><td><code>M365C_WS_PORT</code></td><td>52365</td><td>WebSocket port for extension IPC</td></tr>
</tbody>
</table>
<!-- SECURITY -->
<h2 id="security">Security</h2>
<ul>
<li>Both servers bind to <code>127.0.0.1</code> only — not accessible from the network</li>
<li>WebSocket accepts connections only from <code>chrome-extension://</code> origins</li>
<li>Auth tokens are captured passively and stored in Chrome's local storage</li>
<li>Read handles are server-issued opaque UUIDs with 30-minute TTL</li>
</ul>
<!-- LIMITATIONS -->
<h2 id="limitations">Limitations</h2>
<ul>
<li><strong>Token refresh</strong> — requires an active M365 session in the browser (you must be logged in). The extension auto-refreshes tokens before expiry.</li>
<li><strong>Chat content</strong> — only search snippets are returned (full thread reading requires Graph <code>Chat.Read</code> scope).</li>
<li><strong>File content</strong> — returns extracted summaries, not full document bytes.</li>
</ul>
<!-- TROUBLESHOOTING -->
<h2 id="troubleshooting">Troubleshooting</h2>
<table>
<thead>
<tr><th>Issue</th><th>Fix</th></tr>
</thead>
<tbody>
<tr><td>Extension shows "No token"</td><td>Open any M365 page (e.g. <code>outlook.office.com</code>) and wait a few seconds for the extension to capture tokens</td></tr>
<tr><td>MCP server won't start</td><td>Check that port 52366 is available: <code>lsof -i :52366</code></td></tr>
<tr><td>Claude Code can't connect</td><td>Verify MCP config in <code>~/.claude/mcp.json</code> and restart Claude Code</td></tr>
<tr><td>Search returns no results</td><td>Ensure the extension shows valid tokens — click the extension icon to check</td></tr>
<tr><td>WebSocket connection refused</td><td>Make sure the MCP server is running (<code>npx m365connector</code>)</td></tr>
</tbody>
</table>
</div>
<script>
// Anchor links
document.querySelectorAll('h1, h2, h3, h4').forEach(function(h) {
if (!h.id) h.id = h.textContent.trim().toLowerCase().replace(/[^\w]+/g, '-').replace(/-$/, '');
var a = document.createElement('a');
a.href = '#' + h.id;
a.className = 'anchor';
a.textContent = '#';
h.appendChild(a);
});
// Copy button
function copyCmd(btn) {
const code = btn.parentElement.querySelector('code').textContent;
navigator.clipboard.writeText(code).then(() => {
btn.textContent = 'copied';
btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'copy'; btn.classList.remove('copied'); }, 1500);
});
}
</script>
<!-- Ambient nebula effect -->
<script>
(() => {
const PALETTE = [
[0, 120, 212],
[0, 99, 177],
[16, 110, 190],
[0, 150, 214],
[80, 40, 170],
[0, 90, 158],
[50, 130, 200],
[30, 60, 150],
];
const canvas = document.createElement('canvas');
canvas.style.cssText =
'position:fixed;top:0;left:0;width:100%;height:100%;z-index:0;pointer-events:none';
document.body.prepend(canvas);
const ctx = canvas.getContext('2d');
let W, H, cx, cy;
function measure() {
W = canvas.width = innerWidth;
H = canvas.height = innerHeight;
const h1 = document.querySelector('h1');
if (h1) {
const r = h1.getBoundingClientRect();
cx = r.left + r.width / 2;
cy = r.top + scrollY + r.height / 2;
} else {
cx = W / 2;
cy = H * 0.12;
}
}
class Wisp {
constructor() { this.reset(true); }
reset(init) {
this.x = cx + (Math.random() - 0.5) * Math.min(W * 0.5, 480);
this.y = cy + (Math.random() - 0.5) * 100;
this.radius = 70 + Math.random() * 150;
this.life = init ? Math.random() * 550 : 0;
this.maxLife = 420 + Math.random() * 480;
this.vx = (Math.random() - 0.5) * 0.13;
this.vy = (Math.random() - 0.5) * 0.04;
this.angle = Math.random() * Math.PI * 2;
this.aSpeed = 0.0014 + Math.random() * 0.0028;
this.color = PALETTE[(Math.random() * PALETTE.length) | 0];
this.baseA = 0.038 + Math.random() * 0.05;
}
update() {
if (++this.life > this.maxLife) { this.reset(false); return; }
this.angle += this.aSpeed;
this.x += this.vx + Math.sin(this.angle) * 0.15;
this.y += this.vy + Math.cos(this.angle * 0.7) * 0.055;
this.radius += 0.05;
}
draw() {
const p = this.life / this.maxLife;
let a = this.baseA;
if (p < 0.15) a *= p / 0.15;
else if (p > 0.6) a *= (1 - p) / 0.4;
const [r, g, b] = this.color;
const rad = this.radius;
const gr = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, rad);
gr.addColorStop(0, `rgba(${r},${g},${b},${a * 2.4})`);
gr.addColorStop(0.25, `rgba(${r},${g},${b},${a * 1.4})`);
gr.addColorStop(0.6, `rgba(${r},${g},${b},${a * 0.35})`);
gr.addColorStop(1, `rgba(${r},${g},${b},0)`);
ctx.fillStyle = gr;
ctx.fillRect(this.x - rad, this.y - rad, rad * 2, rad * 2);
}
}
measure();
addEventListener('resize', measure);
const wisps = Array.from({ length: 12 }, () => new Wisp());
(function render() {
const fade = Math.max(0, 1 - Math.max(0, scrollY - 40) / 240);
ctx.clearRect(0, 0, W, H);
if (fade > 0.002) {
ctx.globalAlpha = fade;
for (const w of wisps) { w.update(); w.draw(); }
ctx.globalAlpha = 1;
} else {
for (const w of wisps) w.update();
}
requestAnimationFrame(render);
})();
})();
</script>
</body>
</html>