Watch-on-LBRY/src/scripts/background.ts
Shiba c895d53253 🍙 new stuff and some changes
- channel buttons and redirect
- in button mode if there is no target try to find lbry url in the description
- used a loop in content script instead of events and stuff to make it less confusing
2022-07-02 15:15:36 +00:00

26 lines
No EOL
891 B
TypeScript

import { resolveById } from "../modules/yt/urlResolve"
const onGoingLbryPathnameRequest: Record<string, ReturnType<typeof resolveById>> = {}
chrome.runtime.onMessage.addListener(({ json }, sender, sendResponse) => {
function resolve(result: Awaited<ReturnType<typeof resolveById>>) {
sendResponse(JSON.stringify(result))
}
(async () => {
try {
const params: Parameters<typeof resolveById> = JSON.parse(json)
// Don't create a new Promise for same ID until on going one is over.
const promise = onGoingLbryPathnameRequest[json] ?? (onGoingLbryPathnameRequest[json] = resolveById(...params))
console.log('lbrypathname request', params, await promise)
resolve(await promise)
} catch (error) {
sendResponse('error')
console.error(error)
}
finally {
delete onGoingLbryPathnameRequest[json]
}
})()
return true
})