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) {
|
||||
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':
|
||||
|
|
|
@ -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,22 +349,13 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
|||
location.replace(lbryURL)
|
||||
}
|
||||
else {
|
||||
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)
|
||||
if (window.history.length === 1)
|
||||
window.close()
|
||||
else
|
||||
window.history.back()
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue