From 1eb21eb51fe92f2be1895b972bd2a0f8ce62c51e Mon Sep 17 00:00:00 2001
From: Shiba <44804845+DeepDoge@users.noreply.github.com>
Date: Wed, 6 Jul 2022 13:10:32 +0000
Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8D=99=20made=20yt=20video=20pause,?=
=?UTF-8?q?=20since=20we=20use=20new=20tab=20now?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/scripts/ytContent.tsx | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx
index 91d3ba9..4d41de4 100644
--- a/src/scripts/ytContent.tsx
+++ b/src/scripts/ytContent.tsx
@@ -49,7 +49,11 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
fontSize: '14px',
textDecoration: 'none',
...target.platform.button.style?.button,
- }}>
+ }}
+ onClick={() => findVideoElementAwait().then((videoElement) => {
+ videoElement.pause()
+ })}
+ >
{target.platform.button.text}
From ce11d4fdf3f71a41b7d7e161af5fc1d6223523df Mon Sep 17 00:00:00 2001
From: Shiba <44804845+DeepDoge@users.noreply.github.com>
Date: Thu, 7 Jul 2022 17:37:57 +0000
Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8D=A3=20little=20bug=20fix?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/scripts/ytContent.tsx | 114 ++++++++++++++++++++------------------
1 file changed, 59 insertions(+), 55 deletions(-)
diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx
index 4d41de4..2e41d0e 100644
--- a/src/scripts/ytContent.tsx
+++ b/src/scripts/ytContent.tsx
@@ -159,69 +159,73 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
const url = new URL(location.href);
let target = (await getTargetsByURL(url))[url.href]
- if (settings.redirect) {
- if (!target) continue
- if (url === urlCache) continue
-
- const lbryURL = getLbryUrlByTarget(target)
-
- findVideoElementAwait().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 }))
- // Its not gonna be able to replace anyway
- // This was empty window doesnt stay open
- location.replace(lbryURL)
+ try {
+ if (settings.redirect) {
+ if (!target) continue
+ if (url === urlCache) continue
+
+ const lbryURL = getLbryUrlByTarget(target)
+
+ findVideoElementAwait().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 }))
+ // Its not gonna be able to replace anyway
+ // 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 {
- open(lbryURL, '_blank')
- if (window.history.length === 1) window.close()
- else window.history.back()
- }
- }
- else {
- if (!target) {
- const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
- if (descriptionElement) {
- const anchors = Array.from(descriptionElement.querySelectorAll('a'))
-
- for (const anchor of anchors) {
- const url = new URL(anchor.href)
- let lbryURL: URL | null = null
- if (sourcePlatform === sourcePlatfromSettings['youtube.com']) {
- if (!targetPlatforms.some(([key, platform]) => url.searchParams.get('q')?.startsWith(platform.domainPrefix))) continue
- lbryURL = new URL(url.searchParams.get('q')!)
- }
- else {
- if (!targetPlatforms.some(([key, platform]) => url.href.startsWith(platform.domainPrefix))) continue
- lbryURL = new URL(url.href)
- }
-
- if (lbryURL) {
- target = {
- lbryPathname: lbryURL.pathname.substring(1),
- time: null,
- type: 'video',
- platform: targetPlatformSettings[settings.targetPlatform]
+ if (!target) {
+ const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
+ if (descriptionElement) {
+ const anchors = Array.from(descriptionElement.querySelectorAll('a'))
+
+ for (const anchor of anchors) {
+ if (!anchor.href) continue
+ const url = new URL(anchor.href)
+ let lbryURL: URL | null = null
+ if (sourcePlatform === sourcePlatfromSettings['youtube.com']) {
+ if (!targetPlatforms.some(([key, platform]) => url.searchParams.get('q')?.startsWith(platform.domainPrefix))) continue
+ lbryURL = new URL(url.searchParams.get('q')!)
+ }
+ else {
+ if (!targetPlatforms.some(([key, platform]) => url.href.startsWith(platform.domainPrefix))) continue
+ lbryURL = new URL(url.href)
+ }
+
+ if (lbryURL) {
+ target = {
+ lbryPathname: lbryURL.pathname.substring(1),
+ time: null,
+ type: 'video',
+ platform: targetPlatformSettings[settings.targetPlatform]
+ }
+ break
}
- break
}
}
}
+
+ if (target) {
+ const videoElement = document.querySelector(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)
}
-
- if (target) {
- const videoElement = document.querySelector(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) {
+ console.error(error)
}
-
urlCache = url
}
From 4102177212fce8de23ae38569374197549b5dc40 Mon Sep 17 00:00:00 2001
From: Shiba <44804845+DeepDoge@users.noreply.github.com>
Date: Thu, 7 Jul 2022 18:00:32 +0000
Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8D=A3=20Some=20more=20bug=20fixes?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/scripts/ytContent.tsx | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx
index 2e41d0e..e4294cc 100644
--- a/src/scripts/ytContent.tsx
+++ b/src/scripts/ytContent.tsx
@@ -141,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
async function requestResolveById(...params: Parameters): ReturnType {
const json = await new Promise((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
}
@@ -156,11 +160,10 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
while (true) {
await sleep(500)
- const url = new URL(location.href);
- let target = (await getTargetsByURL(url))[url.href]
-
+ const url: URL = (urlCache?.href === location.href) ? urlCache : new URL(location.href);
try {
if (settings.redirect) {
+ const target = (await getTargetsByURL(url))[url.href]
if (!target) continue
if (url === urlCache) continue
@@ -184,6 +187,8 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
}
}
else {
+ if (urlCache !== url) updateButton(null)
+ let target = (await getTargetsByURL(url))[url.href]
if (!target) {
const descriptionElement = document.querySelector(sourcePlatform.htmlQueries.videoDescription)
if (descriptionElement) {
@@ -215,7 +220,7 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
}
}
- if (target) {
+ if (target?.type === 'video') {
const videoElement = document.querySelector(sourcePlatform.htmlQueries.videoPlayer)
if (videoElement) target.time = videoElement.currentTime > 3 && videoElement.currentTime < videoElement.duration - 1 ? videoElement.currentTime : null
}