Migration to MV3

This commit is contained in:
Kevin R
2023-11-11 17:49:00 +01:00
parent 92e43b7f61
commit b55b6af007
11 changed files with 96 additions and 105 deletions

View File

@@ -22,36 +22,29 @@
* and based on: https://github.com/mdn/webextensions-examples/tree/master/context-menu-copy-link-with-types
*/
function contextMenuStart() {
if(storage.contextMenuEnabled) {
browser.contextMenus.create({
id: "copy-link-to-clipboard",
title: translate("clipboard_copy_link"),
contexts: ["link"]
});
browser.runtime.onInstalled.addListener(contextMenuStart);
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "copy-link-to-clipboard") {
const url = pureCleaning(info.linkUrl);
const code = "copyToClipboard(" +
JSON.stringify(url)+");";
function contextMenuStart(details) {
browser.contextMenus.create({
id: "copy-link-to-clipboard",
title: translate("clipboard_copy_link"),
contexts: ["link"]
});
browser.tabs.executeScript({
code: "typeof copyToClipboard === 'function';",
}).then((results) => {
if (!results || results[0] !== true) {
return browser.tabs.executeScript(tab.id, {
file: "/external_js/clipboard-helper.js",
}).catch(handleError);
}
}).then(() => {
return browser.tabs.executeScript(tab.id, {
code,
});
}).catch((error) => {
console.error("Failed to copy text: " + error);
});
}
});
}
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "copy-link-to-clipboard") {
const url = pureCleaning(info.linkUrl);
browser.scripting.executeScript({
target: {
tabId: tab.id,
allFrames: true
},
func: (text) => navigator.clipboard.writeText(text),
args: [
url
]
});
}
});
}