this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #4 from jessejanderson/use-did-for-profile

authored by

Jesse J. Anderson and committed by
GitHub
a0bdcc22 d8d91bbd

+32 -16
+4
CHANGELOG.md
··· 7 7 8 8 ## [Unreleased] 9 9 10 + ## [1.1.0] - 2023-05-03 11 + 12 + - use DID for profile url instead of domain name 13 + 10 14 ## [1.0.1] - 2023-04-30 11 15 12 16 ### Fixed
+6 -9
background.js
··· 1 - const tabsWithDID = new Set() 1 + const tabsWithDID = new Map() 2 2 3 3 const bskyAppUrl = "https://staging.bsky.app" 4 4 ··· 15 15 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { 16 16 if (message.type === "DID_FOUND") { 17 17 setIcon(sender.tab.id, "logo48.png") 18 - tabsWithDID.add(sender.tab.id) 18 + tabsWithDID.set(sender.tab.id, message.did) 19 19 } else { 20 20 setIcon(sender.tab.id, "logo48_gray.png") 21 21 tabsWithDID.delete(sender.tab.id) ··· 23 23 }) 24 24 25 25 chrome.action.onClicked.addListener((tab) => { 26 - if (tabsWithDID.has(tab.id)) { 27 - chrome.tabs.sendMessage(tab.id, { type: "GET_DOMAIN" }, (response) => { 28 - if (response && response.domain) { 29 - const newUrl = `${bskyAppUrl}/profile/${response.domain}` 30 - chrome.tabs.create({ url: newUrl }) 31 - } 32 - }) 26 + const did = tabsWithDID.get(tab.id) 27 + if (did) { 28 + const newUrl = `${bskyAppUrl}/profile/${did}` 29 + chrome.tabs.create({ url: newUrl }) 33 30 } 34 31 })
+21 -6
content.js
··· 4 4 } 5 5 6 6 async function checkForDID(domain) { 7 + // We use Google's DNS over HTTPS API to resolve the TXT record 7 8 const response = await fetch( 8 9 `https://dns.google/resolve?name=_atproto.${domain}&type=TXT` 9 10 ) 10 11 const data = await response.json() 12 + 13 + // We use the TXT record type to avoid CORS issues 11 14 const records = data?.Answer?.filter((record) => record.type === 16) || [] 12 - return records.some((record) => record.data.includes("did=did:plc:")) 15 + 16 + // We filter out all records that are not TXT records 17 + const didRecord = records.find((record) => 18 + record.data.includes("did=did:plc:") 19 + ) 20 + 21 + // We return the DID if we found one 22 + return didRecord ? didRecord.data.replace("did=", "") : null 13 23 } 14 24 25 + // We check for a DID on the current domain 15 26 ;(async function () { 16 27 const domain = getDomainName() 17 - const didFound = await checkForDID(domain) 28 + const did = await checkForDID(domain) 18 29 19 - if (didFound) { 20 - chrome.runtime.sendMessage({ type: "DID_FOUND" }) 30 + if (did) { 31 + chrome.runtime.sendMessage({ type: "DID_FOUND", did }) 21 32 } else { 22 33 chrome.runtime.sendMessage({ type: "DID_NOT_FOUND" }) 23 34 } 24 35 })() 25 36 37 + // We listen for messages from the background script 26 38 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { 27 - if (message.type === "GET_DOMAIN") { 28 - sendResponse({ domain: getDomainName() }) 39 + if (message.type === "GET_DID") { 40 + checkForDID(getDomainName()) 41 + .then((did) => sendResponse({ did })) 42 + .catch(() => sendResponse({ did: null })) 43 + return true // Indicate that the response will be sent asynchronously. 29 44 } 30 45 })
+1 -1
manifest.json
··· 2 2 "manifest_version": 3, 3 3 "name": "SkyLink - Bluesky DID Detector", 4 4 "short_name": "SkyLink", 5 - "version": "1.0.1", 5 + "version": "1.1.0", 6 6 "author": "jesse@adhdjesse.com", 7 7 "action": { 8 8 "default_icon": { "48": "logo48_gray.png", "128": "logo128_gray.png" }