🍣 improved logic of redrect and opening a new tab

This commit is contained in:
Shiba 2022-08-10 08:12:04 +00:00
parent 28ef256c40
commit 1ee722b6ff
2 changed files with 4 additions and 14 deletions

View file

@ -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':

View file

@ -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) {