From fb9acd1539d5dedbfc43d5ed6522a8d0c4d59d48 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sat, 21 Oct 2023 22:34:48 +0300 Subject: [PATCH] Added Bypass & Bypass In New Tab https://codeberg.org/LibRedirect/browser_extension/issues/112 --- src/pages/background/background.js | 38 +++++++++++++++++++++++++++++- src/pages/options/index.js | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 961dac1..542ef03 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -142,6 +142,8 @@ browser.contextMenus.create({ id: "redirectLinkInNewTab", title: 'Redirect In Ne browser.contextMenus.create({ id: "reverseLink", title: 'Redirect To Original', contexts: ["link"] }) browser.contextMenus.create({ id: "reverseLinkInNewTab", title: 'Redirect To Original In New Tab', contexts: ["link"] }) browser.contextMenus.create({ id: "copyReverseLink", title: 'Copy Original', contexts: ["link"] }) +browser.contextMenus.create({ id: "bypassLink", title: 'Bypass', contexts: ["link"] }) +browser.contextMenus.create({ id: "bypassLinkInNewTab", title: 'Bypass In New Tab', contexts: ["link"] }) if (!isChrome) { browser.contextMenus.create({ id: "redirectBookmark", title: 'Redirect', contexts: ["bookmark"] }) @@ -149,9 +151,10 @@ if (!isChrome) { browser.contextMenus.create({ id: "reverseBookmark", title: 'Redirect To Original', contexts: ["bookmark"] }) browser.contextMenus.create({ id: "reverseBookmarkInNewTab", title: 'Redirect To Original In New Tab', contexts: ["bookmark"] }) browser.contextMenus.create({ id: "copyReverseBookmark", title: 'Copy Original', contexts: ["bookmark"] }) + browser.contextMenus.create({ id: "bypassBookmark", title: 'Bypass', contexts: ["bookmark"] }) + browser.contextMenus.create({ id: "bypassBookmarkInNewTab", title: 'Bypass In New Tab', contexts: ["bookmark"] }) } - browser.contextMenus.onClicked.addListener(async (info) => { switch (info.menuItemId) { case 'switchInstanceTab': { @@ -237,6 +240,21 @@ browser.contextMenus.onClicked.addListener(async (info) => { return } + case 'bypassLink': + case 'bypassLinkInNewTab': { + const url = new URL(info.linkUrl) + if (info.menuItemId == "bypassLink") { + browser.tabs.update({ url: url.href }, tab => { + tabIdRedirects[tab.id] = false + }) + } else { + browser.tabs.create({ url: url.href }, tab => { + tabIdRedirects[tab.id] = false + }) + } + return + } + case 'copyReverseBookmark': { browser.bookmarks.get(info.bookmarkId, bookmarks => { const url = new URL(bookmarks[0].url) @@ -244,6 +262,7 @@ browser.contextMenus.onClicked.addListener(async (info) => { }); return } + case 'redirectBookmark': case 'redirectBookmarkInNewTab': { browser.bookmarks.get(info.bookmarkId, bookmarks => { @@ -275,6 +294,23 @@ browser.contextMenus.onClicked.addListener(async (info) => { }) return } + + case 'bypassBookmark': + case 'bypassBookmarkInNewTab': { + browser.bookmarks.get(info.bookmarkId, async bookmarks => { + const url = new URL(bookmarks[0].url) + if (info.menuItemId == "bypassBookmark") { + browser.tabs.update({ url: url.href }, tab => { + tabIdRedirects[tab.id] = false + }) + } else { + browser.tabs.create({ url: url.href }, tab => { + tabIdRedirects[tab.id] = false + }) + } + return + }) + } } }) diff --git a/src/pages/options/index.js b/src/pages/options/index.js index 020980b..dd1a6ff 100644 --- a/src/pages/options/index.js +++ b/src/pages/options/index.js @@ -347,7 +347,7 @@ async function ping(frontend) { element.appendChild(span) const href = element.getElementsByTagName('a')[0].href const innerHTML = element.getElementsByTagName('a')[0].innerHTML - const time = redundancyList[innerHTML] ?? await utils.ping(href) + const time = redundancyList[innerHTML] ?? await utils.ping(href) const { color, text } = processTime(time) span.innerHTML = `${text}` pingCache[innerHTML] = time