This repository has been archived on 2025-01-29. You can view files and clone it, but cannot push or open issues or pull requests.
awaki/public/assets/bsky.js

26 lines
849 B
JavaScript

(async () => {
const status = document.querySelector('.js-status');
status.textContent = 'Looking up DID...';
const format = BSKY_FORMAT.replace('%s', location.protocol.substring(0, location.protocol.length - 1));
let did = null;
try {
const response = await fetch(`${location.protocol}//${BSKY_HANDLE}/.well-known/atproto-did`);
did = await response.text();
} catch(ex) {
status.style.color = 'red';
status.textContent = `Could not find DID! ${ex}`;
return;
}
if(typeof did !== 'string' || !did.startsWith('did:')) {
status.style.color = 'red';
status.textContent = 'Look up result was not a valid DID.';
return;
}
const url = format.replace('%s', did);
status.textContent = `Redirecting to ${url}...`;
location.replace(url);
})();