Skip to content
Snippets Groups Projects
Commit 450bc415 authored by David Byers's avatar David Byers
Browse files

Added support for unmangling links on compose.

parent 291bfb6f
No related branches found
No related tags found
No related merge requests found
Pipeline #32533 passed
browser.composeScripts.register({
js: [
{file: "common.js"},
{file: "compose.js"}
],
});
browser.messageDisplayScripts.register({
css: [
{file: "/style.css"}
],
js: [
{file: "/common.js"},
{file: "/content.js"}
{file: "/display.js"}
],
});
console.log(browser);
console.log(browser.i18n);
browser.menus.create({
id: "liu-safelinks-copy",
title: browser.i18n.getMessage("copyLinkMenuTitle"),
......
......@@ -19,3 +19,23 @@ function untangleLink(link) {
function isTangledLink(link) {
return link.match(safelinksRegexp);
}
function getTextNodes(elem) {
var result = [];
if (elem) {
for (var nodes = elem.childNodes, i = nodes.length; i--;) {
let node = nodes[i];
let nodeType = node.nodeType;
if (nodeType == Node.TEXT_NODE) {
result.push(node);
}
else if (nodeType == Node.ELEMENT_NODE
|| nodeType == Node.DOCUMENT_NODE
|| nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
result = result.concat(getTextNodes(node));
}
}
}
return result;
}
// Modify the displayed message to clarify where safelinks are
// inserted and to show the actual link targets.
function getTextNodes(elem) {
var result = [];
if (elem) {
for (var nodes = elem.childNodes, i = nodes.length; i--;) {
let node = nodes[i];
let nodeType = node.nodeType;
if (nodeType == Node.TEXT_NODE) {
result.push(node);
}
else if (nodeType == Node.ELEMENT_NODE
|| nodeType == Node.DOCUMENT_NODE
|| nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
result = result.concat(getTextNodes(node));
}
}
}
return result;
}
for (const link of document.links) {
// Mangle the link text
for (const node of getTextNodes(link)) {
......
......@@ -27,6 +27,7 @@
"permissions": [
"messagesModify",
"clipboardWrite",
"menus"
"menus",
"compose"
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment