Fix for UCAS Teacher Training master
authorAdrian Iain Lam <adrianiainlam@users.noreply.github.com>
Thu, 15 Mar 2018 22:53:23 +0000 (22:53 +0000)
committerAdrian Iain Lam <adrianiainlam@users.noreply.github.com>
Thu, 15 Mar 2018 22:53:23 +0000 (22:53 +0000)
They use 80-char lines there instead of UCAS Undergrad's 94

index.html
script.js

index 90adfda..39009ac 100644 (file)
@@ -7,7 +7,7 @@ redirect_from:
 <html>
 <!--
 UCAS Personal Statement Word Counter
-Copyright (c) 2014-2016 Adrian Iain Lam
+Copyright (c) 2014-2018 Adrian Iain Lam
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -71,6 +71,15 @@ Contact: <ail30@cam.ac.uk>
           (For readability purpose only. Will NOT be present in the UCAS
           submission)
         </span>
+      <br />
+      <input id="teacher" type="checkbox" onclick="analyse()">
+        Teacher Training
+        <br />
+        <span class="note">
+          (UCAS Teacher Training uses a different counting method. Check
+          this box if you are applying for Teacher Training. Leave blank
+          for undergraduate application.)
+        </span>
       <div id="stats" class="topPadding">
         <div id="statLines">Lines: 0/47</div>
         <div id="statChars">Characters: 0/4000</div>
@@ -83,7 +92,7 @@ Contact: <ail30@cam.ac.uk>
         &lt;<a href="mailto:ail30@cam.ac.uk">ail30@cam.ac.uk</a>&gt;.
       </address>
       <footer>
-        <p>Copyright &copy; 2014-2016 Adrian Iain Lam</p>
+        <p>Copyright &copy; 2014-2018 Adrian Iain Lam</p>
         <p>
           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
index a90ac30..daa0df5 100644 (file)
--- a/script.js
+++ b/script.js
@@ -32,17 +32,37 @@ function analyse() {
         printStats(lines, 0, 0, parasWithExtraSpace, parasLines);
         return;
     }
+    
+    var maxlinelen = 94;
+    if($("teacher").checked) maxlinelen = 80;
+    
     for(var i=0; i<paras.length; i++) {
         if(paras[i][paras[i].length-1]==' ') parasWithExtraSpace.push(i+1);
         do {
-            if(paras[i][0]==' ') paras[i]=paras[i].substring(1); //remove preceding space
-            line=paras[i].substring(0, paras[i].length>94?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
+            if(paras[i][0]==' ') {
+                paras[i] = paras[i].substring(1); //remove preceding space
+            }
+
+            /* extract line of maxlinelen chars or fewer */
+            if(paras[i].length > maxlinelen) {
+                line = paras[i].substring(0, maxlinelen);
+            } else {
+                line = paras[i].substring(0, paras[i].length);
+            }
+            
+            var lastidx = line.lastIndexOf(' ');
+            if(lastidx >= 0) { //if there is a space in line
+                if(line.length < maxlinelen) {
+                    lastidx = line.length; //if it can contain whole line
+                }
+            } else {
+                lastidx = line.length; //cutoff line if line has maxlinelen
+            }                          // chars without spaces
+            
+            if(paras[i][maxlinelen] == ' ') { //if extracted right before a space
+                lastidx = maxlinelen;
+            }
+            paras[i] = line.substring(lastidx+1)+paras[i].substring(maxlinelen); //remove extracted string (up to lastidx) from paras
             line=line.substring(0, lastidx);
             lines.push(line);
         } while(paras[i]!="");