-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
33 lines (29 loc) · 858 Bytes
/
background.js
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
async function resolve(mention) {
// Strip @ from start of mention, if present
if (mention.startsWith('@')) {
mention = mention.substring(1)
}
const domain = mention.split('@')[1]
const response = await fetch(
`https://${domain}/.well-known/webfinger?resource=acct:${mention}`,
{
headers: {
Accept: 'application/jrd+json',
},
}
).then((response) => response.json())
return (
response.links.find(
(link) => link.rel === 'http://webfinger.net/rel/profile-page'
)?.href ?? response.aliases[0]
)
}
chrome.omnibox.onInputEntered.addListener(async (text) => {
// Encode user input for special characters , / ? : @ & = + $ #
// chrome.tabs.create({ url: await resolve(text) })
const [tab] = await chrome.tabs.query({
active: true,
lastFocusedWindow: true,
})
chrome.tabs.update(tab.id, { url: await resolve(text) })
})