From: adrianiainlam Date: Tue, 12 Jul 2016 16:15:53 +0000 (+0800) Subject: Clean up personal statement code X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=3d0fb55f6cb156b890f9061f26f1c23d33cca8d7;p=ucas-personal-statement-counter.git Clean up personal statement code --- diff --git a/index.html b/index.html new file mode 100644 index 0000000..d46a01c --- /dev/null +++ b/index.html @@ -0,0 +1,99 @@ + + + + + UCAS Personal Statement Line & Character Counter + + + + + + + + +

UCAS Personal Statement Line & Character Counter

+
+ Paste your personal statement here!
+ +
+ +
+
+
+ + +
+ +
+ + Automatic analysis + (Not recommended for slow computers) + +
+ + Separate paragraphs +
+ + (For readability purpose only. Will NOT be present in the UCAS + submission) + +
+
Lines: 0/47
+
Characters: 0/4000
+ +
+
+ Found a bug? Please report to + <ail30@cam.ac.uk>. +
+
+

Copyright © 2014-2016 Adrian Iain Lam

+

+ This program is free software, and you are welcome to redistribute it + under the terms of the GNU GPL. This program comes with ABSOLUTELY NO + WARRANTY. View the source for details. +

+

+ This site is not affiliated with, endorsed by, approved by, + or related to UCAS. +

+

+ Unlike the counter + by Maccery, no personal statements are sent to the hosting server. + All codes are executed on the client-side. +

+
+
+ + diff --git a/script.js b/script.js new file mode 100644 index 0000000..a90ac30 --- /dev/null +++ b/script.js @@ -0,0 +1,63 @@ +$ = document.getElementById.bind(document); +function printStats(lines, numLines, numChars, parasWithExtraSpace, parasLines) { + $("results").innerHTML=""; + for(var i=0; i"; + if(parasLines.indexOf(i+1)>=0 && $("chk2").checked) $("results").innerHTML+="
"; + } + + $("statLines").innerHTML="Lines: "+numLines+"/47"; + $("statLines").style.color=numLines>47?"red":"initial"; + $("statChars").innerHTML="Characters: "+numChars+"/4000"; + $("statChars").style.color=numChars>4000?"red":"initial"; + + if(parasWithExtraSpace.length>0) { + $("statWarn").innerHTML="Warning: Extra space(s) found at end of paragraph(s) "+parasWithExtraSpace.join(", "); + $("statWarn").style.visibility="visible"; + $("statWarn").style.color="red"; + } else { + $("statWarn").innerHTML="Warning: Extra space(s) found at end of paragraph(s) "; + $("statWarn").style.visibility="hidden"; + } +} + +function analyse() { + var text=$("txt1").value; + var parasWithExtraSpace=[]; + var parasLines=[]; + var paras=text.split('\n'); + var lines=[]; + var line="" + if(text=="") { + printStats(lines, 0, 0, parasWithExtraSpace, parasLines); + return; + } + for(var i=0; i94?94:paras[i].length); //extract line of 94 chars or fewer + var lastidx=line.lastIndexOf(' '); + if(lastidx>=0) { //if there is a space in line + if(line.length<94) lastidx=line.length; //if it can contain whole line + } else lastidx=line.length; + if(paras[i][94]==' ') lastidx=94; //if extracted right before a space + paras[i] = line.substring(lastidx+1)+paras[i].substring(94); //remove extracted string (up to lastidx) from paras + line=line.substring(0, lastidx); + lines.push(line); + } while(paras[i]!=""); + parasLines.push(lines.length); //lines where paragraphs end + } + printStats(lines, lines.length, text.length+paras.length-1, parasWithExtraSpace, parasLines); +} + +function autocheck() { + if($("chk1").checked) { + $("txt1").addEventListener("input", analyse); + $("btn1").style.visibility='hidden'; + analyse(); + } else { + $("txt1").removeEventListener("input", analyse); + $("btn1").style.visibility='visible'; + } +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..48c1907 --- /dev/null +++ b/style.css @@ -0,0 +1,35 @@ +#txt1 { + font-family: "Liberation Serif", "Times New Roman", serif; + width: 100%; + padding-left: 1em; + padding-right: 1em; + height: 15em; + box-sizing: border-box; +} +.topPadding { + padding-top: 12pt; +} +#resultsContainer { + font-family: monospace; + float: right; + min-width: 100ch; + border-left-style: solid; + border-left-width: 1px; + border-left-color: black; + box-sizing: border-box; + white-space: nowrap; +} +#statContainer { + overflow: auto; + padding-right: 8pt; +} +span.note { + font-size: 8pt; +} +footer { + font-size: 8pt; +} +.hidden { + visibility: hidden; +} +