Added support for bookmarks https://github.com/libredirect/libredirect/issues/568
This commit is contained in:
parent
9441f89ed5
commit
b91ae8e816
|
@ -25,6 +25,7 @@
|
||||||
"storage",
|
"storage",
|
||||||
"clipboardWrite",
|
"clipboardWrite",
|
||||||
"contextMenus",
|
"contextMenus",
|
||||||
|
"bookmarks",
|
||||||
"<all_urls>"
|
"<all_urls>"
|
||||||
],
|
],
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue