From 1ee722b6ff6eebd3765db92d1255c369d67443c7 Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Wed, 10 Aug 2022 08:12:04 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=A3=20improved=20logic=20of=20redrect?= =?UTF-8?q?=20and=20opening=20a=20new=20tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/background.ts | 4 ++-- src/scripts/ytContent.tsx | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/scripts/background.ts b/src/scripts/background.ts index 051762d..3996ccf 100644 --- a/src/scripts/background.ts +++ b/src/scripts/background.ts @@ -11,8 +11,8 @@ chrome.runtime.onMessage.addListener(({ method, data }, sender, sendResponse) => switch (method) { case 'openTab': { - const { href, active }: { href: string, active: boolean } = JSON.parse(data) - chrome.tabs.create({ url: href, active }) + const { href }: { href: string } = JSON.parse(data) + chrome.tabs.create({ url: href, active: sender.tab?.active, index: sender.tab ? sender.tab.index + 1 : undefined }) } break case 'resolveUrl': diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx index 824e8e4..f4c69c2 100644 --- a/src/scripts/ytContent.tsx +++ b/src/scripts/ytContent.tsx @@ -237,8 +237,7 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa // Request new tab async function openNewTab(url: URL) { - if (!open(url.href, '_blank')) - chrome.runtime.sendMessage({ method: 'openTab', data: JSON.stringify({ href: url.href, active: document.hasFocus() }) }) + chrome.runtime.sendMessage({ method: 'openTab', data: JSON.stringify({ href: url.href }) }) } function findTargetFromSourcePage(source: Source): Target | null { @@ -350,20 +349,11 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa location.replace(lbryURL) } else { + openNewTab(lbryURL) if (window.history.length === 1) - { - location.replace(lbryURL) - - // Some extensions such as Firefox Multi-Account Containers, opens new tab for Odysee even though we say replace - // In those cases if the window is still active after 2 seconds we close it manually - await sleep(2000) window.close() - } else - { - openNewTab(lbryURL) window.history.back() - } } } } catch (error) {