This commit is contained in:
ManeraKai 2023-02-09 01:31:45 +03:00
parent 9441f89ed5
commit b91ae8e816
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 58 additions and 7 deletions

View File

@ -25,6 +25,7 @@
"storage", "storage",
"clipboardWrite", "clipboardWrite",
"contextMenus", "contextMenus",
"bookmarks",
"<all_urls>" "<all_urls>"
], ],
"browser_action": { "browser_action": {

View File

@ -138,7 +138,26 @@ browser.contextMenus.create({
contexts: ["link"], contexts: ["link"],
}) })
browser.contextMenus.onClicked.addListener(async (info, tab) => { browser.contextMenus.create({
id: "redirectBookmark",
title: 'Redirect',
contexts: ["bookmark"],
})
browser.contextMenus.create({
id: "reverseBookmark",
title: 'Reverse redirect',
contexts: ["bookmark"],
})
browser.contextMenus.create({
id: "copyReverseBookmark",
title: 'Copy Reverse',
contexts: ["bookmark"],
})
browser.contextMenus.onClicked.addListener(async (info) => {
switch (info.menuItemId) { switch (info.menuItemId) {
case 'switchInstance': { case 'switchInstance': {
const url = new URL(info.pageUrl) const url = new URL(info.pageUrl)
@ -161,8 +180,9 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
const url = new URL(info.pageUrl) const url = new URL(info.pageUrl)
const newUrl = await servicesHelper.reverse(url) const newUrl = await servicesHelper.reverse(url)
if (newUrl) { if (newUrl) {
browser.tabs.create({ url: newUrl }, tab => {
tabIdRedirects[tab.id] = false tabIdRedirects[tab.id] = false
browser.tabs.update({ url: newUrl }) })
} }
return return
} }
@ -170,8 +190,9 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
const url = new URL(info.pageUrl) const url = new URL(info.pageUrl)
const newUrl = servicesHelper.redirect(url, "main_frame", null, true) const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
if (newUrl) { if (newUrl) {
tabIdRedirects[tab.id] = true browser.tabs.create({ url: newUrl }, tab => {
browser.tabs.update({ url: newUrl }) tabIdRedirects[tab.id] = false
})
} }
return return
} }
@ -191,12 +212,41 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
const url = new URL(info.linkUrl) const url = new URL(info.linkUrl)
const newUrl = await servicesHelper.reverse(url) const newUrl = await servicesHelper.reverse(url)
if (newUrl) { if (newUrl) {
browser.tabs.create({ url: newUrl }, tab => {
tabIdRedirects[tab.id] = false tabIdRedirects[tab.id] = false
browser.tabs.create({ url: newUrl }) })
} }
return return
} }
case 'copyReverseBookmark': {
browser.bookmarks.get(info.bookmarkId, bookmarks => {
const url = new URL(bookmarks[0].url)
servicesHelper.copyRaw(url)
});
return
}
case 'redirectBookmark': {
browser.bookmarks.get(info.bookmarkId, bookmarks => {
const url = new URL(bookmarks[0].url)
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
if (newUrl) browser.tabs.create({ url: newUrl })
})
return
}
case 'reverseBookmark': {
browser.bookmarks.get(info.bookmarkId, async bookmarks => {
const url = new URL(bookmarks[0].url)
const newUrl = await servicesHelper.reverse(url)
if (newUrl) {
browser.tabs.update({ url: newUrl }, tab => {
tabIdRedirects[tab.id] = false
})
}
})
return
}
} }
}) })