clear-urls-browser-extension/core_js/context_menu.js
Kevin Röbert 91d46a7b70 ClearURLs v.1.6
- Added listener to the browser history to prevent tracking with the [history.pushState method](https://developer.mozilla.org/en-US/docs/Web/API/History_API)
- Added webNavigation and tabs permissions, for the new feature
- Added switches in settings to enable and disable the context menu entry and the history listener
- Added tool to clean URLs, that was pasted into a textbox
- Added icon for new tool to clean URLs

- Fixed [#40](https://gitlab.com/KevinRoebert/ClearUrls/issues/40), see also https://curl.kevinroebert.de
- Fixed [#103](https://gitlab.com/KevinRoebert/ClearUrls/issues/103), see also https://curl.kevinroebert.de

- Changed clipboard-helper.js path to be absolute to prevent problems
- Changed rewrite of old GitHub links to the new data.min.json and rules.min.hash
- Config icon is now bigger and above the config label
- Update Traditional Chinese Translation by [@yipinghuang](https://gitlab.com/yipinghuang)

#161 #162 #157 #40 #103 #158
2019-04-11 16:40:48 +02:00

58 lines
2.1 KiB
JavaScript

/*
* ClearURLs
* Copyright (c) 2017-2019 Kevin Röbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*jshint esversion: 6 */
/*
* 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
*/
function contextMenuStart() {
if(storage.contextMenuEnabled) {
browser.contextMenus.create({
id: "copy-link-to-clipboard",
title: translate("clipboard_copy_link"),
contexts: ["link"]
});
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "copy-link-to-clipboard") {
const url = pureCleaning(info.linkUrl);
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);
});
}
});
}
}