Skip to content

Instantly share code, notes, and snippets.

@madaan
Last active September 3, 2022 14:37
Show Gist options
  • Save madaan/1e495c954639b34214b445d32fd07b66 to your computer and use it in GitHub Desktop.
Save madaan/1e495c954639b34214b445d32fd07b66 to your computer and use it in GitHub Desktop.
A word counter for Softconf (Google Chrome only)
//based on the original checkwords provided by softconf
/*
To use this script:
1. Copy this script (you can select contents of this box + copy. Alternatively, click `Raw` on top-right of this box, then CTRL + A and copy).
2. Go to softconf author response page.
3. Right click anywhere on the page, and click `Inspect`.
4. Switch to `Console` tab.
5. Paste the script (copied in step 1).
6. Live wordcount will be displayed as you edit your response.
*/
function checkwords(area) {
section_names = {"resp1": "r1", "resp2": "r2", "resp3": "r3", "responseToReviews": "r2r"};
if (!maxwords) {return true;}
var total = 0;
var summary = "";
for (i=0; i<tocheck.length; i++) {
wc = wordcount(tocheck[i]);
total += wc;
summary += section_names[tocheck[i]] + "=" + wc + ", ";
}
summary += "total=" + total;
console.log(summary);
if (total > maxwords) {
jQuery("#showhide").hide();
jQuery(":submit").attr("disabled", true);
//alert ('Maximum word count of ' + maxwords + ' exceeded. Please shorten your response.');
var x2 = jQuery(area).val();
x2=x2.replace(/\b(\w+)$/g,'');
jQuery(area).val(x2);
return false;
}
else {
jQuery("#showhide").show();
jQuery(":submit").attr("disabled", false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment