Change to old clipboard copy technique, to support chrome and older firefox versions
This commit is contained in:
parent
cfd3bf5f43
commit
1b6cc37bdd
|
@ -18,7 +18,8 @@
|
|||
|
||||
/*jshint esversion: 6 */
|
||||
/*
|
||||
* This script is responsible for context menu cleaning functions.
|
||||
* This script is responsible for context menu cleaning functions
|
||||
* and based on: https://github.com/mdn/webextensions-examples/tree/master/context-menu-copy-link-with-types
|
||||
*/
|
||||
|
||||
browser.contextMenus.create({
|
||||
|
@ -30,8 +31,23 @@ browser.contextMenus.create({
|
|||
browser.contextMenus.onClicked.addListener((info, tab) => {
|
||||
if (info.menuItemId === "copy-link-to-clipboard") {
|
||||
const url = contextCleaning(info.linkUrl);
|
||||
navigator.clipboard.writeText(url).then(() => {
|
||||
console.log("[ClearURLs] Copied cleaned url to clipboard.");
|
||||
const code = "copyToClipboard(" +
|
||||
JSON.stringify(url)+");";
|
||||
|
||||
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",
|
||||
});
|
||||
}
|
||||
}).then(() => {
|
||||
return browser.tabs.executeScript(tab.id, {
|
||||
code,
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error("Failed to copy text: " + error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
16
external_js/clipboard-helper.js
Normal file
16
external_js/clipboard-helper.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Source: https://github.com/mdn/webextensions-examples/tree/master/context-menu-copy-link-with-types
|
||||
*/
|
||||
function copyToClipboard(text) {
|
||||
function oncopy(event) {
|
||||
document.removeEventListener("copy", oncopy, true);
|
||||
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
event.preventDefault();
|
||||
event.clipboardData.setData("text/plain", text);
|
||||
}
|
||||
document.addEventListener("copy", oncopy, true);
|
||||
|
||||
document.execCommand("copy");
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "ClearURLs",
|
||||
"version": "1.5.7.1",
|
||||
"version": "1.5.8",
|
||||
"author": "Kevin R.",
|
||||
"description": "Remove tracking elements form URLs.",
|
||||
"homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls",
|
||||
|
|
Loading…
Reference in New Issue
Block a user