From 450bc415180c7267dc00c3ed7101755f77f53180 Mon Sep 17 00:00:00 2001 From: David Byers <david.byers@liu.se> Date: Mon, 25 Jan 2021 08:56:52 +0100 Subject: [PATCH] Added support for unmangling links on compose. --- extension/background.js | 13 ++++++++----- extension/common.js | 20 ++++++++++++++++++++ extension/{content.js => display.js} | 20 -------------------- extension/manifest.json | 3 ++- 4 files changed, 30 insertions(+), 26 deletions(-) rename extension/{content.js => display.js} (56%) diff --git a/extension/background.js b/extension/background.js index 2db81a7..534b37e 100644 --- a/extension/background.js +++ b/extension/background.js @@ -1,17 +1,20 @@ +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"), diff --git a/extension/common.js b/extension/common.js index e872137..f1fd15f 100644 --- a/extension/common.js +++ b/extension/common.js @@ -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; +} diff --git a/extension/content.js b/extension/display.js similarity index 56% rename from extension/content.js rename to extension/display.js index 32b8707..abae2db 100644 --- a/extension/content.js +++ b/extension/display.js @@ -1,26 +1,6 @@ // 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)) { diff --git a/extension/manifest.json b/extension/manifest.json index cd14e05..2ff8088 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -27,6 +27,7 @@ "permissions": [ "messagesModify", "clipboardWrite", - "menus" + "menus", + "compose" ] } -- GitLab