Commits

Alexey Kozlov committed 4effbed

version 1.0

Comments (0)

Files changed (5)

128_.png

Added
New image

16_.png

Added
New image

48_.png

Added
New image
+{
+   "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://*/*" ]
+}
+<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>