Permalink
Browse files

Merge pull request #13 from willscott/master

Was able to get clear-sign working for gmail compose
  • Loading branch information...
2 parents 367d54b + 1b88b07 commit ecc7cde67b9b890912f9af7b2c93d581b33d0b0c @Mononofu committed Feb 28, 2012
Showing with 38 additions and 31 deletions.
  1. +13 −2 README.md
  2. +3 −3 background.html
  3. +22 −26 content_script.js
View
@@ -9,18 +9,29 @@
-CryptoChrome is a small Chrome extension to encrypt your text and emails with GnuPG. Currently, it only works on Linux. You'll also have to build the plugin yourself - it's not in the Chrome Webstore yet.
+CryptoChrome is a small Chrome extension to encrypt your text and emails with GnuPG. Currently, it works on Linux and Mac. You'll also have to build the plugin yourself - it's not in the Chrome Webstore yet.
Building
========
+Linux
+-----
+
This should be easy, just run
./build.sh
However, make sure that you have libgtk2.0-dev and cmake installed. Of course, you'll also need make, gcc, etc.
+Mac
+-----
+
+Make sure you have xcode tools and cmake installed (The binary cmake [package](http://cmake.org/cmake/resources/software.html) will work). Then run
+
+ ./buildmac.sh
+
+
Details
=======
-For more information and some screenshots, also check out [my blog post](http://www.furidamu.org/blog/2012/02/26/protecting-your-mails-with-gnupg/) about it.
+For more information and some screenshots, also check out [my blog post](http://www.furidamu.org/blog/2012/02/26/protecting-your-mails-with-gnupg/) about it.
View
@@ -61,9 +61,9 @@
return "";
}
-function decryptText(cipther_txt) {
- if (clear_txt && clear_txt.length) {
- return plugin().decrypt(cipther_txt);
+function decryptText(cipher_txt) {
+ if (cipher_txt && cipher_txt.length) {
+ return plugin().decrypt(cipher_txt);
}
return "";
}
View
@@ -6,28 +6,8 @@ var isSelectedFrame = function() {
return null;
}
-var getNodeWithText = function(root, string) {
- if(root.nodeType == Node.TEXT_NODE && root.data.indexOf(string) >= 0) {
- return root;
- } else if (root.nodeType != Node.TEXT_NODE) {
- if (root.value && root.value.indexOf(string) >= 0) {
- return root;
- }
-
- for (var i=0; i < root.childNodes.length;i++) {
- var ret = getNodeWithText(root.childNodes[i], string);
- if (ret) {
- return ret;
- }
- }
- }
- return null;
-}
-
var channel = channel || function(request, sender, sendResponse) {
- console.log(sender.tab ?
- "from a content script:" + sender.tab.url : "from the extension");
- // The background page is asking us for the selected text
+ // The background page is asking for selected text.
if (request.cmd == "get_selected")
{
var txt = '';
@@ -40,23 +20,39 @@ var channel = channel || function(request, sender, sendResponse) {
  txt = window.document.getSelection();
}
sendResponse( { msg: ""+txt } );
+ // The background page is asking us to replace selection with processed text.
} else if (request.cmd == "replace_selected") {
var replacement = request.text;
if(!isSelectedFrame()) {
return;
}
var selection = window.getSelection();
- var el = getNodeWithText(selection.anchorNode, selection.toString());
- if (!el) {
- alert(replacement);
- } else if (el.nodeType == Node.TEXT_NODE) {
+ if (selection.anchorNode == selection.focusNode && selection.anchorNode.nodeType == Node.TEXT_NODE) {
+ var el = selection.anchorNode;
var pos = el.data.indexOf(selection.toString());
var newText = window.document.createTextNode(el.data.substring(0,pos) + replacement + el.data.substring(pos+selection.toString().length));
el.parentNode.insertBefore(newText, el);
el.parentNode.removeChild(el);
- } else {
+ } else if (selection.anchorNode == selection.focusNode && selection.anchorNode.value) {
+ var el = selection.anchorNode;
var pos = el.value.indexOf(selection.toString());
el.value = el.value.substring(0,pos) + replacement + el.value.substring(pos+selection.toString().length);
+ } else if (selection.anchorNode != selection.focusNode) {
+ if (selection.anchorOffset > 0) {
+ }
+ selection.deleteFromDocument();
+ var el = selection.anchorNode;
+ var newText = document.createElement("span");
+ newText.innerHTML = replacement.replace(/\n/g,"<br/>");
+ if (el.nodeType == Node.TEXT_NODE) {
+ el.parentNode.insertBefore(newText, el);
+ el.parentNode.removeChild(el);
+ } else {
+ el.appendChild(newText);
+ }
+ } else {
+ // A single selected element with no value or text. Hopefully shouldn't happen.
+ alert(replacement);
}
} else {
sendResponse({}); // snub them.

0 comments on commit ecc7cde

Please sign in to comment.