+24
-2
templates/header.html
+24
-2
templates/header.html
···
20
20
</nav>
21
21
</div>
22
22
<script>
23
+
async function resolveDidToPds(did) {
24
+
if (did.startsWith("did:plc:")) {
25
+
const res = await fetch(`https://plc.directory/${did}`);
26
+
const doc = await res.json();
27
+
return doc.service?.find(s => s.id === "#atproto_pds")?.serviceEndpoint;
28
+
} else if (did.startsWith("did:web:")) {
29
+
const domain = did.slice(8);
30
+
const res = await fetch(`https://${domain}/.well-known/did.json`);
31
+
const doc = await res.json();
32
+
return doc.service?.find(s => s.id === "#atproto_pds")?.serviceEndpoint;
33
+
}
34
+
return null;
35
+
}
36
+
async function fetchAtUriRecord(atUri) {
37
+
const match = atUri.match(/^at:\/\/([^/]+)\/([^/]+)\/([^/]+)$/);
38
+
if (!match) return null;
39
+
const [, repo, collection, rkey] = match;
40
+
const pds = await resolveDidToPds(repo);
41
+
if (!pds) return null;
42
+
const url = `${pds}/xrpc/com.atproto.repo.getRecord?repo=${encodeURIComponent(repo)}&collection=${encodeURIComponent(collection)}&rkey=${encodeURIComponent(rkey)}`;
43
+
const res = await fetch(url);
44
+
return res.ok ? res.json() : null;
45
+
}
23
46
let nowPlayingTimeout = null;
24
47
function fetchNowPlaying() {
25
48
if (nowPlayingTimeout) clearTimeout(nowPlayingTimeout);
26
-
fetch("https://bsky.social/xrpc/com.atproto.repo.getRecord?repo=did:plc:krxbvxvis5skq7jj6eot23ul&collection=fm.teal.alpha.actor.status&rkey=self")
27
-
.then((response) => response.ok ? response.json() : null)
49
+
fetchAtUriRecord("at://did:plc:krxbvxvis5skq7jj6eot23ul/fm.teal.alpha.actor.status/self")
28
50
.then((data) => {
29
51
const el = document.getElementById("now-playing");
30
52
if (!data?.value?.item) {
+25
-9
templates/shortcodes/is.md
+25
-9
templates/shortcodes/is.md
···
3
3
</div>
4
4
5
5
<script>
6
+
async function resolveDidToPds(did) {
7
+
if (did.startsWith("did:plc:")) {
8
+
const res = await fetch(`https://plc.directory/${did}`);
9
+
const doc = await res.json();
10
+
return doc.service?.find(s => s.id === "#atproto_pds")?.serviceEndpoint;
11
+
} else if (did.startsWith("did:web:")) {
12
+
const domain = did.slice(8);
13
+
const res = await fetch(`https://${domain}/.well-known/did.json`);
14
+
const doc = await res.json();
15
+
return doc.service?.find(s => s.id === "#atproto_pds")?.serviceEndpoint;
16
+
}
17
+
return null;
18
+
}
19
+
async function fetchAtUriListRecords(atUri) {
20
+
const match = atUri.match(/^at:\/\/([^/]+)\/([^/]+)$/);
21
+
if (!match) return null;
22
+
const [, repo, collection] = match;
23
+
const pds = await resolveDidToPds(repo);
24
+
if (!pds) return null;
25
+
const url = `${pds}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(repo)}&collection=${encodeURIComponent(collection)}`;
26
+
const res = await fetch(url);
27
+
return res.ok ? res.json() : null;
28
+
}
6
29
function fetchStatus() {
7
-
fetch(
8
-
"https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=dunkirk.sh&collection=a.status.update",
9
-
)
10
-
.then((response) => {
11
-
if (!response.ok) {
12
-
throw new Error("Network response was not ok");
13
-
}
14
-
return response.json();
15
-
})
30
+
fetchAtUriListRecords("at://did:plc:krxbvxvis5skq7jj6eot23ul/a.status.update")
16
31
.then((statusData) => {
32
+
if (!statusData) return;
17
33
const bubble = document.querySelector(".bubble");
18
34
if (statusData.records && statusData.records.length > 0) {
19
35
if (statusData.records[0].value.createdAt) {