mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-18 07:05:37 +07:00
Migration to MV3
This commit is contained in:
@@ -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
|
||||
]
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user