mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
🍣 bug fixes
This commit is contained in:
parent
619d66d6aa
commit
4295dbe1fe
1 changed files with 87 additions and 82 deletions
|
@ -246,97 +246,102 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
let urlHrefCache: string | null = null
|
let urlHrefCache: string | null = null
|
||||||
while (true) {
|
while (true) {
|
||||||
await sleep(500)
|
await sleep(500)
|
||||||
|
const url: URL = new URL(location.href);
|
||||||
const url: URL = new URL(location.href)
|
|
||||||
const source = await getSourceByUrl(new URL(location.href))
|
await (async () => {
|
||||||
if (!source) continue
|
const source = await getSourceByUrl(new URL(location.href))
|
||||||
|
if (!source) return
|
||||||
try {
|
|
||||||
if (settings.redirect) {
|
try {
|
||||||
const target = (await getTargetsBySources(source))[source.id]
|
if (settings.redirect) {
|
||||||
if (!target) continue
|
const target = (await getTargetsBySources(source))[source.id]
|
||||||
if (url.href === urlHrefCache) continue
|
if (!target) return
|
||||||
|
console.log(url.href, urlHrefCache)
|
||||||
const lbryURL = getLbryUrlByTarget(target)
|
if (url.href === urlHrefCache) return
|
||||||
|
|
||||||
if (source.type === 'video') {
|
const lbryURL = getLbryUrlByTarget(target)
|
||||||
// As soon as video play is ready and start playing, pause it.
|
|
||||||
findVideoElementAwait(source).then((videoElement) => {
|
if (source.type === 'video') {
|
||||||
videoElement.addEventListener('play', () => videoElement.pause(), { once: true })
|
// As soon as video play is ready and start playing, pause it.
|
||||||
videoElement.pause()
|
findVideoElementAwait(source).then((videoElement) => {
|
||||||
})
|
videoElement.addEventListener('play', () => videoElement.pause(), { once: true })
|
||||||
}
|
videoElement.pause()
|
||||||
|
})
|
||||||
if (target.platform === targetPlatformSettings.app) {
|
}
|
||||||
if (document.hidden) await new Promise((resolve) => document.addEventListener('visibilitychange', resolve, { once: true }))
|
|
||||||
// Replace is being used so browser doesnt start an empty window
|
if (target.platform === targetPlatformSettings.app) {
|
||||||
// Its not gonna be able to replace anyway, since its a LBRY Uri
|
if (document.hidden) await new Promise((resolve) => document.addEventListener('visibilitychange', resolve, { once: true }))
|
||||||
location.replace(lbryURL)
|
// Replace is being used so browser doesnt start an empty window
|
||||||
|
// Its not gonna be able to replace anyway, since its a LBRY Uri
|
||||||
|
location.replace(lbryURL)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('open', lbryURL.href)
|
||||||
|
openNewTab(lbryURL, document.hasFocus())
|
||||||
|
|
||||||
|
if (window.history.length === 1) window.close()
|
||||||
|
else window.history.back()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
openNewTab(lbryURL, document.hasFocus())
|
if (urlHrefCache !== url.href) updateButton(null)
|
||||||
|
let target = (await getTargetsBySources(source))[source.id]
|
||||||
if (window.history.length === 1) window.close()
|
|
||||||
else window.history.back()
|
// There is no target found via API try to check Video Description for LBRY links.
|
||||||
}
|
if (!target) {
|
||||||
}
|
const linksContainer =
|
||||||
else {
|
source.type === 'video' ?
|
||||||
if (urlHrefCache !== url.href) updateButton(null)
|
document.querySelector(source.platform.htmlQueries.videoDescription) :
|
||||||
let target = (await getTargetsBySources(source))[source.id]
|
source.platform.htmlQueries.channelLinks ? document.querySelector(source.platform.htmlQueries.channelLinks) : null
|
||||||
|
|
||||||
// There is no target found via API try to check Video Description for LBRY links.
|
if (linksContainer) {
|
||||||
if (!target) {
|
const anchors = Array.from(linksContainer.querySelectorAll<HTMLAnchorElement>('a'))
|
||||||
const linksContainer =
|
|
||||||
source.type === 'video' ?
|
for (const anchor of anchors) {
|
||||||
document.querySelector(source.platform.htmlQueries.videoDescription) :
|
if (!anchor.href) continue
|
||||||
source.platform.htmlQueries.channelLinks ? document.querySelector(source.platform.htmlQueries.channelLinks) : null
|
const url = new URL(anchor.href)
|
||||||
|
let lbryURL: URL | null = null
|
||||||
if (linksContainer) {
|
|
||||||
const anchors = Array.from(linksContainer.querySelectorAll<HTMLAnchorElement>('a'))
|
// Extract real link from youtube's redirect link
|
||||||
|
if (source.platform === sourcePlatfromSettings['youtube.com']) {
|
||||||
for (const anchor of anchors) {
|
if (!targetPlatforms.some(([key, platform]) => url.searchParams.get('q')?.startsWith(platform.domainPrefix))) continue
|
||||||
if (!anchor.href) continue
|
lbryURL = new URL(url.searchParams.get('q')!)
|
||||||
const url = new URL(anchor.href)
|
}
|
||||||
let lbryURL: URL | null = null
|
// Just directly use the link itself on other platforms
|
||||||
|
else {
|
||||||
// Extract real link from youtube's redirect link
|
if (!targetPlatforms.some(([key, platform]) => url.href.startsWith(platform.domainPrefix))) continue
|
||||||
if (source.platform === sourcePlatfromSettings['youtube.com']) {
|
lbryURL = new URL(url.href)
|
||||||
if (!targetPlatforms.some(([key, platform]) => url.searchParams.get('q')?.startsWith(platform.domainPrefix))) continue
|
}
|
||||||
lbryURL = new URL(url.searchParams.get('q')!)
|
|
||||||
}
|
if (lbryURL) {
|
||||||
// Just directly use the link itself on other platforms
|
target = {
|
||||||
else {
|
lbryPathname: lbryURL.pathname.substring(1),
|
||||||
if (!targetPlatforms.some(([key, platform]) => url.href.startsWith(platform.domainPrefix))) continue
|
time: null,
|
||||||
lbryURL = new URL(url.href)
|
type: lbryURL.pathname.substring(1).includes('/') ? 'video' : 'channel',
|
||||||
}
|
platform: targetPlatformSettings[settings.targetPlatform]
|
||||||
|
}
|
||||||
if (lbryURL) {
|
break
|
||||||
target = {
|
|
||||||
lbryPathname: lbryURL.pathname.substring(1),
|
|
||||||
time: null,
|
|
||||||
type: lbryURL.pathname.substring(1).includes('/') ? 'video' : 'channel',
|
|
||||||
platform: targetPlatformSettings[settings.targetPlatform]
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (!target) updateButton(null)
|
||||||
if (!target) updateButton(null)
|
else {
|
||||||
else {
|
// If target is a video target add timestampt to it
|
||||||
// If target is a video target add timestampt to it
|
if (target.type === 'video') {
|
||||||
if (target.type === 'video') {
|
const videoElement = document.querySelector<HTMLVideoElement>(source.platform.htmlQueries.videoPlayer)
|
||||||
const videoElement = document.querySelector<HTMLVideoElement>(source.platform.htmlQueries.videoPlayer)
|
if (videoElement) target.time = videoElement.currentTime > 3 && videoElement.currentTime < videoElement.duration - 1 ? videoElement.currentTime : null
|
||||||
if (videoElement) target.time = videoElement.currentTime > 3 && videoElement.currentTime < videoElement.duration - 1 ? videoElement.currentTime : null
|
}
|
||||||
|
|
||||||
|
updateButton({ target, source })
|
||||||
}
|
}
|
||||||
|
|
||||||
updateButton({ target, source })
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
})()
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
urlHrefCache = url.href
|
urlHrefCache = url.href
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue