Commits

Alexey Kozlov committed c4a0404

version 2.0

Comments (0)

Files changed (4)

+<script>
+
+var TheText = ''
+
+function genericOnClick(info, tab) {
+  TheText = info.selectionText;
+  var n = webkitNotifications.createHTMLNotification("notification.html");
+  n.show();
+}
+
+chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
+  sendResponse(TheText);
+});
+
+chrome.contextMenus.create({"title": "Text Statistics",
+                            "contexts":["selection"],
+                            "onclick": genericOnClick});
+</script>
-{
-   "name": "Text Statistic Counter",
-   "description": "Counts the words and characters in your selection",
-   "version": "1.0",
-   "browser_action": {
-      "default_icon": "48_.png",
-      "default_title": "Count a statistic of selected text",
-      "popup": "popup.html"
-   },
-   "icons": {
-      "128": "128_.png",
-      "48": "48_.png",
-      "16": "16_.png"
-   },
-   "permissions": [ "tabs", "http://*/*", "https://*/*" ]
-}
+{
+   "name": "Text Statistic Counter",
+   "description": "Counts the words and characters in your selection",
+   "version": "2.0",
+   "icons": {
+      "128": "128_.png",
+      "48": "48_.png",
+      "16": "16_.png"
+   },
+   "permissions": [ "notifications", "tabs", "contextMenus", "http://*/*", "https://*/*" ],
+   "background_page": "background.html"
+}

notification.html

+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <style type="text/css">
+      body {
+        font-family: Helvetica, Arial, sans-serif;
+        font-size: 14px;
+        background-color: #F5F5DC;
+      }
+      div {
+        padding:7px 5px 14px 5px;
+      }
+      p {
+        padding:0 0 5px 0;
+        margin:0;
+      }
+    </style>
+    <script>
+      chrome.extension.sendRequest({}, function(response){
+
+        content_div = document.getElementById("content");
+        if (response.length > 0) {
+          text_nodes = [
+            "Words: " + response.split(/\s+/).length,
+            "Characters with spaces: " + response.length,
+            "Characters without spaces: " + response.split(/\s+/).join('').length
+          ]
+        } else {
+          text_nodes = ["No text selected"]
+        }
+        for (i in text_nodes) {
+          tmp_para = document.createElement("p");
+          tmptext = document.createTextNode(text_nodes[i]);
+          tmp_para.appendChild(tmptext);
+          content_div.appendChild(tmp_para);
+        }
+      });
+    </script>
+  </head>
+  <body>
+    <div>
+      <div style="float: left;top-margin:100px"><img src="48_.png"></div>
+      <div id="content" style="float: left"></div>
+    </div>
+  </body>
+</html>

popup.html

-<html>
-<style>
-body {
-  min-width:400px;
-  /*overflow-x:hidden;*/
-}
-div {
-  padding:0 10px 10px 10px;
-}
-p {
-  padding:5px 0;
-  margin:0;
-}
-</style>
-<head>
- <script type="text/javascript"> 
-  chrome.tabs.executeScript(null, {code: "chrome.extension.sendRequest(window.getSelection().toString());"});
-  chrome.extension.onRequest.addListener(function(request) { count_text_stat(request) });
-
-  function count_text_stat(request) {
-
-    output_div = document.getElementById("output");
-
-    if (request.length > 0) {
-
-      text_nodes = [
-        "Words: " + request.split(/\s+/).length,
-        "Characters with spaces: " + request.length,
-        "Characters without spaces: " + request.split(/\s+/).join('').length
-      ]
-
-    } else {
-
-      text_nodes = ["No text selected"]
-
-    }
-
-    for (i in text_nodes) {
-
-      tmp_para = document.createElement("p");
-      tmptext = document.createTextNode(text_nodes[i]);
-      tmp_para.appendChild(tmptext);
-      output_div.appendChild(tmp_para);
-
-    }
-
-  }
- </script> 
-</head>
-<body>
-<div>
- <div style="float: left"><img src="48_.png"></div>
- <div id="output" style="float: left"></div>
-</div>
-</body>
-</html>