()
| 23 | */ |
| 24 | |
| 25 | function contextMenuStart() { |
| 26 | if(storage.contextMenuEnabled) { |
| 27 | browser.contextMenus.create({ |
| 28 | id: "copy-link-to-clipboard", |
| 29 | title: translate("clipboard_copy_link"), |
| 30 | contexts: ["link"] |
| 31 | }); |
| 32 | |
| 33 | browser.contextMenus.onClicked.addListener((info, tab) => { |
| 34 | if (info.menuItemId === "copy-link-to-clipboard") { |
| 35 | const url = pureCleaning(info.linkUrl); |
| 36 | const code = "copyToClipboard(" + |
| 37 | JSON.stringify(url)+");"; |
| 38 | |
| 39 | browser.tabs.executeScript({ |
| 40 | code: "typeof copyToClipboard === 'function';", |
| 41 | }).then((results) => { |
| 42 | if (!results || results[0] !== true) { |
| 43 | return browser.tabs.executeScript(tab.id, { |
| 44 | file: "/external_js/clipboard-helper.js", |
| 45 | }).catch(handleError); |
| 46 | } |
| 47 | }).then(() => { |
| 48 | return browser.tabs.executeScript(tab.id, { |
| 49 | code, |
| 50 | }); |
| 51 | }).catch((error) => { |
| 52 | console.error("Failed to copy text: " + error); |
| 53 | }); |
| 54 | } |
| 55 | }); |
| 56 | } |
| 57 | } |
no test coverage detected