-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5176c14
commit 8706a03
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Function to hit the back button on the given tab | ||
* @param {Tab} tabInfo - The tab to go back on. | ||
*/ | ||
async function goBack(tabInfo) { | ||
let withGoBack = browser.tabs.goBack(tabInfo.id); | ||
} | ||
|
||
/** | ||
* Function to handle the context menu click event. | ||
* @param {Object} info - Information about the item clicked and the context where the click happened. | ||
* @param {Object} tab - The details of the tab where the click took place. | ||
*/ | ||
async function openPreviousPage(info, tab) { | ||
try { | ||
let duplicated = browser.tabs.duplicate(tab.id, {index: tab.index}); | ||
duplicated.then(goBack, console.log) | ||
} catch (error) { | ||
console.error("Error retrieving previous URL:", error); | ||
} | ||
} | ||
|
||
/** | ||
* Function to create the context menu item. | ||
*/ | ||
function createContextMenuItem() { | ||
browser.contextMenus.create({ | ||
id: "open-previous-page", | ||
title: "Open Previous Page in New Tab", | ||
contexts: ["tab"] | ||
}); | ||
} | ||
|
||
// Add listener for the context menu click event | ||
browser.contextMenus.onClicked.addListener(openPreviousPage); | ||
|
||
// Create the context menu item when the extension is installed or updated | ||
browser.runtime.onInstalled.addListener(createContextMenuItem); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "Open Previous Page in New Tab", | ||
"version": "1.0", | ||
"description": "Adds a context menu option to open the previous page of a tab in a new tab.", | ||
"permissions": [ | ||
"contextMenus", | ||
"history", | ||
"tabs" | ||
], | ||
"background": { | ||
"scripts": ["background.js"] | ||
}, | ||
"icons": { | ||
"48": "icon/icon-48-2.png" | ||
}, | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "{c06ad177-7a43-4a29-875f-beec98bd53be}" | ||
} | ||
} | ||
} |