mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
🍣 little bug fix
This commit is contained in:
parent
1eb21eb51f
commit
ce11d4fdf3
1 changed files with 59 additions and 55 deletions
|
@ -159,69 +159,73 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
const url = new URL(location.href);
|
const url = new URL(location.href);
|
||||||
let target = (await getTargetsByURL(url))[url.href]
|
let target = (await getTargetsByURL(url))[url.href]
|
||||||
|
|
||||||
if (settings.redirect) {
|
try {
|
||||||
if (!target) continue
|
if (settings.redirect) {
|
||||||
if (url === urlCache) continue
|
if (!target) continue
|
||||||
|
if (url === urlCache) continue
|
||||||
const lbryURL = getLbryUrlByTarget(target)
|
|
||||||
|
const lbryURL = getLbryUrlByTarget(target)
|
||||||
findVideoElementAwait().then((videoElement) => {
|
|
||||||
videoElement.addEventListener('play', () => videoElement.pause(), { once: true })
|
findVideoElementAwait().then((videoElement) => {
|
||||||
videoElement.pause()
|
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 }))
|
if (target.platform === targetPlatformSettings.app) {
|
||||||
// Its not gonna be able to replace anyway
|
if (document.hidden) await new Promise((resolve) => document.addEventListener('visibilitychange', resolve, { once: true }))
|
||||||
// This was empty window doesnt stay open
|
// Its not gonna be able to replace anyway
|
||||||
location.replace(lbryURL)
|
// This was empty window doesnt stay open
|
||||||
|
location.replace(lbryURL)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
open(lbryURL, '_blank')
|
||||||
|
if (window.history.length === 1) window.close()
|
||||||
|
else window.history.back()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
open(lbryURL, '_blank')
|
if (!target) {
|
||||||
if (window.history.length === 1) window.close()
|
const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
|
||||||
else window.history.back()
|
if (descriptionElement) {
|
||||||
}
|
const anchors = Array.from(descriptionElement.querySelectorAll<HTMLAnchorElement>('a'))
|
||||||
}
|
|
||||||
else {
|
for (const anchor of anchors) {
|
||||||
if (!target) {
|
if (!anchor.href) continue
|
||||||
const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
|
const url = new URL(anchor.href)
|
||||||
if (descriptionElement) {
|
let lbryURL: URL | null = null
|
||||||
const anchors = Array.from(descriptionElement.querySelectorAll<HTMLAnchorElement>('a'))
|
if (sourcePlatform === sourcePlatfromSettings['youtube.com']) {
|
||||||
|
if (!targetPlatforms.some(([key, platform]) => url.searchParams.get('q')?.startsWith(platform.domainPrefix))) continue
|
||||||
for (const anchor of anchors) {
|
lbryURL = new URL(url.searchParams.get('q')!)
|
||||||
const url = new URL(anchor.href)
|
}
|
||||||
let lbryURL: URL | null = null
|
else {
|
||||||
if (sourcePlatform === sourcePlatfromSettings['youtube.com']) {
|
if (!targetPlatforms.some(([key, platform]) => url.href.startsWith(platform.domainPrefix))) continue
|
||||||
if (!targetPlatforms.some(([key, platform]) => url.searchParams.get('q')?.startsWith(platform.domainPrefix))) continue
|
lbryURL = new URL(url.href)
|
||||||
lbryURL = new URL(url.searchParams.get('q')!)
|
}
|
||||||
}
|
|
||||||
else {
|
if (lbryURL) {
|
||||||
if (!targetPlatforms.some(([key, platform]) => url.href.startsWith(platform.domainPrefix))) continue
|
target = {
|
||||||
lbryURL = new URL(url.href)
|
lbryPathname: lbryURL.pathname.substring(1),
|
||||||
}
|
time: null,
|
||||||
|
type: 'video',
|
||||||
if (lbryURL) {
|
platform: targetPlatformSettings[settings.targetPlatform]
|
||||||
target = {
|
}
|
||||||
lbryPathname: lbryURL.pathname.substring(1),
|
break
|
||||||
time: null,
|
|
||||||
type: 'video',
|
|
||||||
platform: targetPlatformSettings[settings.targetPlatform]
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target) {
|
||||||
|
const videoElement = document.querySelector<HTMLVideoElement>(sourcePlatform.htmlQueries.videoPlayer)
|
||||||
|
if (videoElement) target.time = videoElement.currentTime > 3 && videoElement.currentTime < videoElement.duration - 1 ? videoElement.currentTime : null
|
||||||
|
}
|
||||||
|
|
||||||
|
// We run it anyway with null target to hide the button
|
||||||
|
updateButton(target)
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
if (target) {
|
console.error(error)
|
||||||
const videoElement = document.querySelector<HTMLVideoElement>(sourcePlatform.htmlQueries.videoPlayer)
|
|
||||||
if (videoElement) target.time = videoElement.currentTime > 3 && videoElement.currentTime < videoElement.duration - 1 ? videoElement.currentTime : null
|
|
||||||
}
|
|
||||||
|
|
||||||
// We run it anyway with null target to hide the button
|
|
||||||
updateButton(target)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
urlCache = url
|
urlCache = url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue