Skip to content

Commit

Permalink
Added support for bookmarks libredirect/browser_extension#568
Browse files Browse the repository at this point in the history
  • Loading branch information
RustomDuck committed Feb 8, 2023
1 parent 51c69b4 commit 1c4aea9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"storage",
"clipboardWrite",
"contextMenus",
"bookmarks",
"<all_urls>"
],
"browser_action": {
Expand Down
64 changes: 57 additions & 7 deletions src/pages/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -161,17 +180,19 @@ 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
}
case 'redirectTab': {
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
}
Expand All @@ -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
}

}
})

Expand Down

0 comments on commit 1c4aea9

Please sign in to comment.