From b7cefbb8906a6edad4fd5445c50c41adba582b87 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 8 May 2015 12:54:40 +0300 Subject: This seems to work --- coqCounter.js | 30 ++++++++++++++++++++++++++++++ index.html | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 coqCounter.js create mode 100644 index.html diff --git a/coqCounter.js b/coqCounter.js new file mode 100644 index 0000000..72f7ad7 --- /dev/null +++ b/coqCounter.js @@ -0,0 +1,30 @@ +$.fn.coqCounter = function(output) { + $(this).change(function(){ + var regex = /[\n^]([a-zA-Z_'0-9]+)/g; + var value = $(this).val(); + var matches = [], i = 0; + + do { + match = regex.exec(value); + if (match != null) { + matches[i++] = match[1]; + } + } while (match != null); + + matches.sort(); + + var counts = {}; + matches.forEach(function(x) { counts[x] = (counts[x] || 0)+1; }); + + var counts_output = [], i = 0; + for (cmd in counts) { + counts_output[i++] = counts[cmd] + "x " + cmd; + } + + console.log(counts_output); + + $(output).val(counts_output.join(", ")); + }); + + return this; +}; \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..549b2cb --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + +
+