Don't redirect if the current tab is already a redirectable URL.
This commit is contained in:
parent
4f9b7b81e0
commit
e5bf102aa3
|
@ -29,6 +29,10 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tab = await browser.tabs.query({active: true, lastFocusedWindow: true});
|
||||||
|
const currentTabUrl =
|
||||||
|
tab[0]?.url === undefined ? undefined : new URL(tab[0].url);
|
||||||
|
|
||||||
const url = new URL(details.url);
|
const url = new URL(details.url);
|
||||||
const {latestUrl} = await browser.storage.local.get('latestUrl');
|
const {latestUrl} = await browser.storage.local.get('latestUrl');
|
||||||
if (redirectDelta < 30_000 && url.href === latestUrl) {
|
if (redirectDelta < 30_000 && url.href === latestUrl) {
|
||||||
|
@ -41,6 +45,15 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirect.isMatch(url)) {
|
if (redirect.isMatch(url)) {
|
||||||
|
// Don't redirect if the URL before going to a new page is also a match.
|
||||||
|
// This will happen when the user is already on a website that has a
|
||||||
|
// redirect, but for whatever reason hasn't redirected. So it's safe to
|
||||||
|
// assume that they want to stay on this website, rather than get
|
||||||
|
// redirected.
|
||||||
|
if (currentTabUrl !== undefined && redirect.isMatch(currentTabUrl)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const redirectedUrl = redirect.redirect(url);
|
const redirectedUrl = redirect.redirect(url);
|
||||||
await browser.tabs.update(details.tabId, {url: redirectedUrl.href});
|
await browser.tabs.update(details.tabId, {url: redirectedUrl.href});
|
||||||
await browser.storage.local.set({
|
await browser.storage.local.set({
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default function createManifest(
|
||||||
name: 'Re-Nav',
|
name: 'Re-Nav',
|
||||||
description: 'Navigation redirects for the masses.',
|
description: 'Navigation redirects for the masses.',
|
||||||
version: '0.1.1',
|
version: '0.1.1',
|
||||||
permissions: ['storage', 'webNavigation'],
|
permissions: ['storage', 'tabs', 'webNavigation'],
|
||||||
options_ui: {
|
options_ui: {
|
||||||
page: 'options/index.html',
|
page: 'options/index.html',
|
||||||
open_in_tab: true,
|
open_in_tab: true,
|
||||||
|
|
Loading…
Reference in New Issue