mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
🍣 improved logic of redrect and opening a new tab
This commit is contained in:
parent
28ef256c40
commit
1ee722b6ff
2 changed files with 4 additions and 14 deletions
|
@ -11,8 +11,8 @@ chrome.runtime.onMessage.addListener(({ method, data }, sender, sendResponse) =>
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'openTab':
|
case 'openTab':
|
||||||
{
|
{
|
||||||
const { href, active }: { href: string, active: boolean } = JSON.parse(data)
|
const { href }: { href: string } = JSON.parse(data)
|
||||||
chrome.tabs.create({ url: href, active })
|
chrome.tabs.create({ url: href, active: sender.tab?.active, index: sender.tab ? sender.tab.index + 1 : undefined })
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'resolveUrl':
|
case 'resolveUrl':
|
||||||
|
|
|
@ -237,8 +237,7 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
|
|
||||||
// Request new tab
|
// Request new tab
|
||||||
async function openNewTab(url: URL) {
|
async function openNewTab(url: URL) {
|
||||||
if (!open(url.href, '_blank'))
|
chrome.runtime.sendMessage({ method: 'openTab', data: JSON.stringify({ href: url.href }) })
|
||||||
chrome.runtime.sendMessage({ method: 'openTab', data: JSON.stringify({ href: url.href, active: document.hasFocus() }) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTargetFromSourcePage(source: Source): Target | null {
|
function findTargetFromSourcePage(source: Source): Target | null {
|
||||||
|
@ -350,20 +349,11 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
location.replace(lbryURL)
|
location.replace(lbryURL)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
openNewTab(lbryURL)
|
||||||
if (window.history.length === 1)
|
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()
|
window.close()
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
openNewTab(lbryURL)
|
|
||||||
window.history.back()
|
window.history.back()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue