mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
- 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
26 lines
No EOL
891 B
TypeScript
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
|
|
}) |