diff --git a/extension/background.js b/extension/background.js index 2db81a7458ae3d339a2812616fb0b19b835a6355..534b37e511439d749e9d7720240088c5068e34a3 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 e8721378ff34f21c835a42d1c998f70bca6acb8a..f1fd15f857447a4367562fd0aeb9f707e62e44d9 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 32b87070ccbf990a38f9d06c80bb8c54d7d88036..abae2dbff3259fe10f33507cb388448aba52d55a 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 cd14e0542a727944ca198b116cf41f64ae6bc905..2ff80881b35551103507bfa547c3756eb334a63d 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -27,6 +27,7 @@ "permissions": [ "messagesModify", "clipboardWrite", - "menus" + "menus", + "compose" ] }