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",
"clipboardWrite",
"contextMenus",
"bookmarks",
"<all_urls>"
],
"browser_action": {

View File

@ -138,7 +138,26 @@ browser.contextMenus.create({
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) {
case 'switchInstance': {
const url = new URL(info.pageUrl)
@ -161,8 +180,9 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
const url = new URL(info.pageUrl)
const newUrl = await servicesHelper.reverse(url)
if (newUrl) {
tabIdRedirects[tab.id] = false
browser.tabs.update({ url: newUrl })
browser.tabs.create({ url: newUrl }, tab => {
tabIdRedirects[tab.id] = false
})
}
return
}
@ -170,8 +190,9 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
const url = new URL(info.pageUrl)
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
if (newUrl) {
tabIdRedirects[tab.id] = true
browser.tabs.update({ url: newUrl })
browser.tabs.create({ url: newUrl }, tab => {
tabIdRedirects[tab.id] = false
})
}
return
}
@ -191,12 +212,41 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
const url = new URL(info.linkUrl)
const newUrl = await servicesHelper.reverse(url)
if (newUrl) {
tabIdRedirects[tab.id] = false
browser.tabs.create({ url: newUrl })
browser.tabs.create({ url: newUrl }, tab => {
tabIdRedirects[tab.id] = false
})
}
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
}
}
})