misuzu/assets/redir-bsky.js/main.js

26 lines
746 B
JavaScript
Raw Normal View History

2025-01-29 21:07:12 +00:00
(async () => {
const status = document.querySelector('.js-status');
status.textContent = 'Looking up DID...';
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 = BSKY_FORMAT.replace('%s', did);
status.textContent = `Redirecting to ${url}...`;
location.replace(url);
})();