Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="overlay"></div>

<div id="wrapper">

  <div id="aboutbox" class="modal">
    <p class="right"><span id="close">X</span></p>
    <p>Welcome to the Word Crawl for the Motivationally Challenged (or anyone who wants a push to get some words out)!</p>
    <p>This challenge is derived from a popular <a href="http://www.nanowrimo.org">NaNoWriMo</a> thread. You will be prompted to write words in small chunks - no more than 200 at a time, and often much less. By the time you're done, the chunks will have
      added up to at least 3,000 words - double your daily NaNoWriMo goal!</p>
    <p>Go ahead and enjoy your writing!</p>
    <p class="right">-J. Sanderson</p>
  </div>
  
  <div id="storagebox" class="modal">
    <p>Switching this on will use your browser's <a href="https://en.wikipedia.org/wiki/Web_storage">local storage</a> to store your progress and written words as you type for safekeeping in case you accidentally close or navigate away from the page. Your writing is only stored in your browser, on your machine, and does not leave it - I have no access to what you wrote and nor does the website this page is hosted on. It is not shared with any other sites in any way, and they can't access your words either.</p>
    <p>Remember this is not a substitute for copy-pasting your words in another document - always remember to do that when you're done.</p>
    <p>If you'd like to enable local storage, click OK, else click Cancel. To clear local storage later, switch this setting to Off.</p>
    <button id="storeok">OK</button>
    <button id="storecancel">Cancel</button>
  </div>

  <h1>A Word Crawl for the Motivationally Challenged!</h1>

  <button id="about">About</button>

  <p class="center"><strong>Warning:</strong> This page does not, by default, save your words! Always copy-paste them somewhere safe before you leave. If you'd like to use your browser's local storage to save your words, check "Save words to local storage" below.</p>
  
  <form id="storage" class="center">
    Save words to local storage:<br />
    <input type="radio" name="storage" id="storeon" value="on"> On<br>
    <input type="radio" name="storage" id="storeoff" value="off" checked> Off<br>
  </form>

  <form id="progbar" class="center">
    Progress bar:<br />
    <input type="radio" name="progbar" id="progon" value="on" checked> On<br>
    <input type="radio" name="progbar" id="progoff" value="off"> Off<br>
  </form>

  <hr>

  <p id="howmuch"></p>

  <div id="progwrapper">
    <div id="prog">
    </div>
  </div>

  <textarea rows="10" cols="90">
      </textarea>

  <div id="counter">
    0
  </div>

  <button id="donebut" class="inactivebut">Done!</button>

</div>

<div id="done"></div>
              
            
!

CSS

              
                /*http://paletton.com/#uid=7142w0kaC2RdcY3avkIffi6rmv-*/

:root {
  --darkbrown: #17140F;
  --tan: #DDCDA8;
  --lightblue: #7D91A4;
  --midblue: #4B5B6B;
  --darkgrey: #0A0C0F;
  --progress: #2264A3;
  --inactive: #90744C
}

body {
  background-color: var(--darkbrown);
  font-family:Arial, Helvetica, sans-serif;
  color: var(--tan);
}

h1 {
  text-align:center;
  color: var(--lightblue);
}

a {
  color: var(--midblue);
}

hr {
  width:70%;
  background-color: var(--midblue);
  height:1px;
  border:none;
}

button {
  background-color: var(--tan);
  margin-left:auto;
  margin-right:auto;
  display:block;
  border:0px;
  font-size:140%;
  padding:10px;
  border-radius:10px;
  cursor:pointer;
}

#wrapper {
  width:70%;
  margin-left:auto;
  margin-right:auto;
}

form {
  margin: 5px;
}

button:active, button:focus, textarea:focus {
  outline: none;
}

/*alignment*/

.right {
  text-align:right;
}

.center {
  text-align:center;
}

/*about box and overlay*/

#overlay {
  display:none;
  background-color:rgba(0, 0, 0, 0.6); 
  width:100%;
  height:100%; 
  z-index:10;
  top:0; 
  left:0; 
  position:fixed; 
}

.modal {
  display:none;
  background-color: var(--tan);
  color: var(--darkbrown);
  position:fixed;
  width:60%;
  left: 50%;
  margin-left: -30%;
  z-index:20;
  padding: 0px 10px;
  border-radius: 10px;
  overflow: auto;
}

.modal button {
  display: inline-block;
  background-color: var(--midblue);
  color: #fff;
  margin: 10px;
}

#close {
  cursor:pointer;
  font-size:140%;
}

/*progress bar etc*/

#howmuch {
  text-align:center;
}

#progwrapper {
  border:1px solid var(--darkgrey);
  background-color: var(--tan);
  height:30px;
  margin-bottom:20px;
}

#prog {
  width:0%;
  height:30px;
  background-color: var(--progress);
}

.invisible {
  display:none;
}

/*writing stuff*/

textarea {
  font-family:'courier new', monospace;
  background-color: var(--tan);
  color: var(--darkgrey);
  border:1px solid var(--darkgrey);
  display:block;
  margin-left:auto;
  margin-right:auto;
  margin-bottom:15px;
  width:100%;
}

#counter {
  text-align:center;
  width:100px;
  margin-left:auto;
  margin-right:auto;
  background-color: var(--tan);
  border:1px solid var(--darkgrey);
  color: var(--darkgrey);
  margin-bottom:15px;
  font-size:120%;
}

#donebut {
  margin-bottom:15px;
}

.inactivebut {
  color: var(--inactive);
  cursor:not-allowed;
}

.activebut {
  color: var(--darkgrey);
}

@media screen and (max-width: 700px) {
  #wrapper {
    width:100%;
  }
}
              
            
!

JS

              
                const PERCENTAGE_STEP = 3.33;
var goalList = [
  10,
  15,
  25,
  50,
  75,
  100,
  100,
  75,
  100,
  110,
  120,
  125,
  150,
  100,
  125,
  150,
  120,
  100,
  80,
  60,
  50,
  75,
  100,
  150,
  200,
  175,
  150,
  125,
  100,
  150
];
var counter, goal, storeWords;

function isStored() {
  return (
    localStorage.hasOwnProperty("_currentText") &&
    localStorage.hasOwnProperty("_writtenText") &&
    localStorage.hasOwnProperty("_counter")
  );
}

function getWordCount(input) {
  //whitespace management (from writtenkitten.co)
  input = input.replace(/^\s*|\s*$/g, ""); //leading/trailing whitespace
  input = input.replace(/\s+/g, " "); //multiple consecutive spaces
  input = input.replace(/\n/g, " "); //new lines

  var words = input.split(" ");
  if (words[0] === "") {
    //set to 0 if all text deleted
    return 0;
  } else {
    //count words in array
    return words.length;
  }
}

function moveToBottom(text) {
  text = text.replace(/\n/g, "<br>");
  //TODO add line break? make optional?
  $("#done").append(" " + text);
}

function textHandler() {
  //have you reached the end of the goal list?
  if (counter >= goalList.length) {
    finish();
    return;
  } else {
    goal = goalList[counter];
    $("#howmuch")
      .empty()
      .append("Write " + goal + " words");

    //live word counter
    $("textarea").keyup(function() {
      var input = $("textarea").val();
      var wc = getWordCount(input);
      if (storeWords) {
        localStorage.setItem("_currentText", input);
      }
      //update counter
      $("#counter")
        .empty()
        .append(wc);
      //make button active if goal met
      if (wc >= goal) {
        $("#donebut")
          .removeClass("inactivebut")
          .addClass("activebut");
      }
    });

    //move text when user clicks done
    $("#donebut").click(function() {
      var wc = parseInt($("#counter").text());
      if (wc >= goal) {
        moveToBottom($("textarea").val());
        //iterate counter
        counter++;
        if (storeWords) {
          localStorage.setItem("_counter", counter);
          localStorage.setItem("_writtenText", $("#done").html());
          localStorage.setItem("_currentText", "");
        }
        $("textarea").val("");
        $("#counter")
          .empty()
          .append(0);
        //deactivate button
        $("#donebut")
          .removeClass("activebut")
          .addClass("inactivebut");
        //set percentage for progress bar
        //set last segment to 100% as the step is technically 3.33 recurring
        var percentage =
          counter > 29 ? 100 + "%" : PERCENTAGE_STEP * counter + "%";
        //animate progress bar
        $("#prog").animate({ width: percentage }, 1000);
        //start again with new goal
        textHandler();
      }
    });
  }
}

function finish() {
  $("#howmuch")
    .empty()
    .append("You did it!");
}

$(document).ready(function() {
  counter = 0;
  storeWords = false;

  //restore existing words
  if (isStored()) {
    if (
      confirm(
        "Your browser's local storage contains existing text you typed in on a previous visit to this page. If you would like to restore this text, click OK. Otherwise, click Cancel to delete this text and turn off local storage for this page."
      )
    ) {
      storeWords = true;
      moveToBottom(localStorage._writtenText);
      $("textarea").val(localStorage._currentText);
      counter = parseInt(localStorage._counter);
      //animate progress bar
      var percentage =
        counter > 29 ? 100 + "%" : PERCENTAGE_STEP * counter + "%";
      $("#prog").animate({ width: percentage }, 1000);
      $("#counter")
        .empty()
        .append(getWordCount(localStorage._currentText));
      $("#storeon").prop("checked", true);
    } else {
      storeWords = false;
      localStorage.removeItem("_currentText");
      localStorage.removeItem("_writtenText");
      localStorage.removeItem("_counter");
    }
  }

  textHandler();

  //progress bar on/off
  $('input[name="progbar"]:radio').change(function() {
    if ($("#progon").is(":checked")) {
      $("#progwrapper").removeClass("invisible");
    } else {
      $("#progwrapper").addClass("invisible");
    }
  });

  //storage on/off
  $('input[name="storage"]:radio').change(function() {
    if ($("#storeon").is(":checked") && !storeWords) {
      $("#overlay").show();
      $("#storagebox").show();
    } else {
      if (storeWords) {
        if (
          confirm(
            "This will remove any words stored by your browser. If you leave this page without copy-pasting them somewhere safe, you will not be able to get them back! Do you want to proceed?"
          )
        ) {
          storeWords = false;
          localStorage.removeItem("_currentText");
          localStorage.removeItem("_writtenText");
          localStorage.removeItem("_counter");
        }
      }
    }
  });

  //accept storage
  $("#storeok").click(function() {
    $("#overlay").hide();
    $("#storagebox").hide();
    storeWords = true;
    localStorage.setItem("_currentText", "");
    localStorage.setItem("_writtenText", $("#done").html());
    localStorage.setItem("_counter", counter);
  });

  //cancel storage
  $("#storecancel").click(function() {
    $("#overlay").hide();
    $("#storagebox").hide();
    storeWords = false;
    //set off to checked
    $("#storeon").prop("checked", false);
    $("#storeoff").prop("checked", true);
    //delete local storage object
    localStorage.removeItem("_currentText");
    localStorage.removeItem("_writtenText");
    localStorage.removeItem("_counter");
  });

  //display about box
  $("#about").click(function() {
    $("#overlay").show();
    $("#aboutbox").show();
  });

  //hide about box
  $("#close").click(function() {
    $("#overlay").hide();
    $("#aboutbox").hide();
  });
});

              
            
!
999px

Console