mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
Merge pull request #125 from DeepDoge/master
Made yt video pause, since we use new tab now
This commit is contained in:
commit
1f29fc7c29
1 changed files with 73 additions and 60 deletions
|
@ -49,7 +49,11 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
...target.platform.button.style?.button,
|
...target.platform.button.style?.button,
|
||||||
}}>
|
}}
|
||||||
|
onClick={() => findVideoElementAwait().then((videoElement) => {
|
||||||
|
videoElement.pause()
|
||||||
|
})}
|
||||||
|
>
|
||||||
<img src={target.platform.button.icon} height={16}
|
<img src={target.platform.button.icon} height={16}
|
||||||
style={{ transform: 'scale(1.5)', ...target.platform.button.style?.icon }} />
|
style={{ transform: 'scale(1.5)', ...target.platform.button.style?.icon }} />
|
||||||
<span>{target.platform.button.text}</span>
|
<span>{target.platform.button.text}</span>
|
||||||
|
@ -137,7 +141,11 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
// We should get this from background, so the caching works and we don't get errors in the future if yt decides to impliment CORS
|
// We should get this from background, so the caching works and we don't get errors in the future if yt decides to impliment CORS
|
||||||
async function requestResolveById(...params: Parameters<typeof resolveById>): ReturnType<typeof resolveById> {
|
async function requestResolveById(...params: Parameters<typeof resolveById>): ReturnType<typeof resolveById> {
|
||||||
const json = await new Promise<string | null | 'error'>((resolve) => chrome.runtime.sendMessage({ json: JSON.stringify(params) }, resolve))
|
const json = await new Promise<string | null | 'error'>((resolve) => chrome.runtime.sendMessage({ json: JSON.stringify(params) }, resolve))
|
||||||
if (json === 'error') throw new Error("Background error.")
|
if (json === 'error')
|
||||||
|
{
|
||||||
|
console.error("Background error on:", params)
|
||||||
|
throw new Error("Background error.")
|
||||||
|
}
|
||||||
return json ? JSON.parse(json) : null
|
return json ? JSON.parse(json) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +160,10 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
while (true) {
|
while (true) {
|
||||||
await sleep(500)
|
await sleep(500)
|
||||||
|
|
||||||
const url = new URL(location.href);
|
const url: URL = (urlCache?.href === location.href) ? urlCache : new URL(location.href);
|
||||||
let target = (await getTargetsByURL(url))[url.href]
|
try {
|
||||||
|
|
||||||
if (settings.redirect) {
|
if (settings.redirect) {
|
||||||
|
const target = (await getTargetsByURL(url))[url.href]
|
||||||
if (!target) continue
|
if (!target) continue
|
||||||
if (url === urlCache) continue
|
if (url === urlCache) continue
|
||||||
|
|
||||||
|
@ -179,12 +187,15 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (urlCache !== url) updateButton(null)
|
||||||
|
let target = (await getTargetsByURL(url))[url.href]
|
||||||
if (!target) {
|
if (!target) {
|
||||||
const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
|
const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
|
||||||
if (descriptionElement) {
|
if (descriptionElement) {
|
||||||
const anchors = Array.from(descriptionElement.querySelectorAll<HTMLAnchorElement>('a'))
|
const anchors = Array.from(descriptionElement.querySelectorAll<HTMLAnchorElement>('a'))
|
||||||
|
|
||||||
for (const anchor of anchors) {
|
for (const anchor of anchors) {
|
||||||
|
if (!anchor.href) continue
|
||||||
const url = new URL(anchor.href)
|
const url = new URL(anchor.href)
|
||||||
let lbryURL: URL | null = null
|
let lbryURL: URL | null = null
|
||||||
if (sourcePlatform === sourcePlatfromSettings['youtube.com']) {
|
if (sourcePlatform === sourcePlatfromSettings['youtube.com']) {
|
||||||
|
@ -209,7 +220,7 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target) {
|
if (target?.type === 'video') {
|
||||||
const videoElement = document.querySelector<HTMLVideoElement>(sourcePlatform.htmlQueries.videoPlayer)
|
const videoElement = document.querySelector<HTMLVideoElement>(sourcePlatform.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
|
||||||
}
|
}
|
||||||
|
@ -217,7 +228,9 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
// We run it anyway with null target to hide the button
|
// We run it anyway with null target to hide the button
|
||||||
updateButton(target)
|
updateButton(target)
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
urlCache = url
|
urlCache = url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue