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
// shared: bluesky-compatible client registry + preferred-client preference.
// mirrors the shape used in ../@zzstoatzz.io/status and ../@chicago.at so
// users get consistent behavior across these atproto experiments.
//
// stored in localStorage under `leaflet.preferredClient`. default = bsky.
// `profileUrlFor(handle)` returns the resolved profile URL for the current
// preference; unknown values fall back to the first registered client.
(function() {
'use strict';
var STORAGE_KEY = 'leaflet.preferredClient';
var CLIENTS = [
{ value: 'bsky', label: 'Bluesky', profileUrl: function(h) { return 'https://bsky.app/profile/' + h; }, iconUrl: 'https://web-cdn.bsky.app/static/apple-touch-icon.png' },
{ value: 'blacksky', label: 'Blacksky', profileUrl: function(h) { return 'https://blacksky.community/profile/' + h; }, iconUrl: 'https://blacksky.community/static/apple-touch-icon.png' },
{ value: 'witchsky', label: 'Witchsky', profileUrl: function(h) { return 'https://witchsky.app/profile/' + h; }, iconUrl: 'https://witchsky.app/static/favicon.ico' },
{ value: 'reddwarf', label: 'Red Dwarf', profileUrl: function(h) { return 'https://reddwarf.app/profile/' + h; }, iconUrl: 'https://reddwarf.app/redstar.png' },
{ value: 'mu', label: 'mu.social', profileUrl: function(h) { return 'https://mu.social/profile/' + h; }, iconUrl: 'https://mu.social/favicon.ico' },
{ value: 'pdsls', label: 'PDSls', profileUrl: function(h) { return 'https://pdsls.dev/at/' + h; }, iconUrl: 'https://pdsls.dev/favicon.ico' },
];
function readPreferred() {
try { return localStorage.getItem(STORAGE_KEY); } catch (e) { return null; }
}
function writePreferred(value) {
try { localStorage.setItem(STORAGE_KEY, value); } catch (e) {}
}
function getPreferredClient() {
var v = readPreferred();
return CLIENTS.find(function(c) { return c.value === v; }) || CLIENTS[0];
}
function setPreferredClient(value) {
if (CLIENTS.some(function(c) { return c.value === value; })) {
writePreferred(value);
window.dispatchEvent(new CustomEvent('leaflet:preferred-client-changed', { detail: value }));
}
}
function profileUrlFor(handleOrDid) {
return getPreferredClient().profileUrl(handleOrDid);
}
// Profile links bake the preferred-client URL into their href at render time.
// Rather than make every page listen for changes (easy to forget on a new
// surface), keep them fresh here: any anchor tagged `data-profile-did` gets
// its href rewritten app-wide when the preference changes. Render sites just
// need the attribute — no per-page wiring.
window.addEventListener('leaflet:preferred-client-changed', function() {
document.querySelectorAll('a[data-profile-did]').forEach(function(a) {
a.href = profileUrlFor(a.getAttribute('data-profile-did'));
});
});
window.LeafletClients = {
CLIENTS: CLIENTS,
getPreferredClient: getPreferredClient,
setPreferredClient: setPreferredClient,
profileUrlFor: profileUrlFor,
};
})();