css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <header id="spritz">
  <div><input type="tel" value="250" id="wpm"/><label>WPM</label>
   
  </div>
   <p>Reading will complete in <span id="completeTime"></span></p>
  <div id="redicle">
    <div></div>
  </div>
  <div id="controls">
    <button id="fastback" data-label="Move back one sentence"><i class="fa fa-fast-backward" aria-hidden="true"></i></button>
    <button id="stepback"  data-label="Move back one word"><i class="fa fa-step-backward" aria-hidden="true"></i></button>
    <button id="stop"  data-label="Stop reading"><i class="fa fa-stop" aria-hidden="true"></i></button>
    <button id="play" data-label="Start / Pause reading"><i class="fa fa-play" aria-hidden="true"></i></button>
    <button id="stepforward"  data-label="Move forward one word"><i class="fa fa-step-forward" aria-hidden="true"></i></button>
    <button id="fastforward"  data-label="Move forward one sentence"><i class="fa fa-fast-forward" aria-hidden="true"></i></button>
  </div>
  
</header>
<textarea id="text">Clinton Deploys Vowels to Bosnia

(originally appeared in The Onion, Number One In News)
Cities of Sjlbvdnzv, Grzny to Be First Recipients

Before an emergency joint session of Congress yesterday, President Clinton announced US plans to deploy over 75,000 vowels to the war-torn region of Bosnia. The deployment, the largest of its kind in American history, will provide the region with the critically needed letters A,E,I,O and U, and is hoped to render countless Bosnian names more pronounceable.
"For six years, we have stood by while names like Ygrjvslhv and Tzlynhr and Glrm have been horribly butchered by millions around the world," Clinton said. "Today, the United States must finally stand up and say 'Enough.' It is time the people of Bosnia finally had some vowels in their incomprehensible words. The US is proud to lead the crusade in this noble endeavour."

The deployment, dubbed Operation Vowel Storm by the State Department, is set for early next week, with the Adriatic port cities of Sjlbvdnzv and Grzny slated to be the first recipients. Two C-130 transport planes, each carrying over 500 24-count boxes of "E's," will fly from Andrews Air Force Base across the Atlantic and airdrop the letters over the cities.

Citizens of Grzny and Sjlbvdnzv eagerly await the arrival of the vowels. "My God, I do not think we can last another day," Trszg Grzdnjkln, 44, said. "I have six children and none of them has a name that is understandable to me or to anyone else. Mr. Clinton, please send my poor, wretched family just one 'E.' Please."

Said Sjlbvdnzv resident Grg Hmphrs, 67: "With just a few key letters, I could be George Humphries. This is my dream."

The airdrop represents the largest deployment of any letter to a foreign country since 1984. During the summer of that year, the US shipped 92,000 consonants to Ethiopia, providing cities like Ouaouoaua, Eaoiiuae, and Aao with vital, life-giving supplies of L's, S's and T's.
</textarea>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Montserrat|Roboto+Slab);
@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css);

*,*:before,*:after{
  box-sizing:border-box;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#spritz{
  font-family:Montserrat;
  background:#000;
  color:#fff;
  text-align:center;
  padding:1em;
}

#spritz > div:first-child{
  border:1px solid #212121;
  display:inline-block;
  padding:6px 12px;
  text-align:center;
  border-radius:2px;
}

#wpm{
  width:3ch;
  display:inline-block;
  text-align:left;
  font-family:inherit;
  margin-right:1ex;
  font-size:1em;
  border:0;
  background:none;
  color:inherit;
}

#text{
  flex: 1;
  font-family:"Roboto Slab";
  font-size:inherit;
  padding:1em;
}

#controls button{
  background:#424242;
  border:0;
  border-radius:3px;
  display:inline-block;
  min-width:2.5em;
  min-height:2.5em;
  cursor:pointer;
  padding:.5em;
  transition:.218s ease;
  margin:0 6px;
}

input:focus, button:focus{
  outline:0;
}

#controls button:hover{
  background-color:#5677fc;
  color:#fff;
}

#controls button{
  position:relative;
}

#controls button[data-label]:hover:before{
  content:"";
  border-width:12px;
  border-style:solid;
  border-color:transparent;
  border-bottom-color:#222;
  position:absolute;
  top:100%;
  margin-top:-12px;
  z-index:10;
  left:50%;
  margin-left:-12px;
}

#controls button[data-label]:hover:after{
  content:attr(data-label);
  position:absolute;
  background:#222;
  color:#fff;
  font-family:Montserrat;
  padding:6px;
  top:100%;
  left:50%;
  transform:translateX(-50%);
  white-space: nowrap;
  margin-top:6px;
  z-index:10;
  border-radius:3px;
  box-shadow:0 0 10px 0 rgba(50, 50, 50, .5);
}

#redicle{
  position:relative;
  border-top:4px solid #fff;
  border-bottom:4px solid #fff;
  width:10em;
  height:3.3ch;
  font-size:2em;
  margin:12px auto;
}

#redicle:before,
#redicle:after{
  content:"";
  border-left:4px solid #fff;
  position:absolute;
  height:.4ch;
  left:38%;
}

#redicle:before{
  top:0;
}

#redicle:after{
  bottom:0;
}

#redicle span{
  font-weight:400;
  display:block;
  position:absolute;
  top:.5ch;
  color:#fff;
}

#redicle span b{
  font-weight:400;
  color:#f00;
}

#redicle > div{
  height:100%;
  width:100%;
  margin-left:0;
  transition-property:width, margin-left;
  transition-timing-function:linear, linear;
}

#redicle > div.quotes{
  font-style: initial;
}

#redicle > div.quotes:before{
  content:"\"";
  position:absolute;
  left:0;
  font-size:1.5em;
}

#redicle > div.quotes:after{
  content:"\"";
  position:absolute;
  right:0;
  font-size:1.5em;
}

#redicle > div.parenthesis{
  opacity:1;
}

#redicle > div.parenthesis:before{
  content:"(";
  position:absolute;
  left:0;
  font-size:1.5em;
}

#redicle > div.parenthesis:after{
  content:")";
  position:absolute;
  right:0;
  font-size:1.5em;
}
            
          
!
            
              var words;
var sentences;
var t;

//elements
var redicle = document.getElementById('redicle').firstElementChild;
var wpm = document.getElementById('wpm');
var copy = document.getElementById('text');
var complete = document.getElementById('completeTime');

function getORP(word){
  var orp = Math.ceil((word.length - 1) / 4);
  if(/\W/.test(word[orp])) orp = orp - 1;
  return orp;
}

function processText(text) {
  sentences = [0];
  var parenthesis = false;
  var quotes = false;
  words = text.replace(/((?=\w{15,})(\w{7})|(?!^\w{1,14})$)/g, '$1- ')
              .match(/[^\s-]+-?/g)
              .filter(function(v){return /[\w]/.test(v)})
              .map(function(v, i, arr) {
                if (/[.?!]/.test(v) && arr[i + 1]) sentences.push(i + 1);
                return {
                  content: v.replace(/[\(|\)\"]/g, ''),
                  orp: getORP(v),
                  parenthesis: checkP(v),
                  quotes: checkQ(v)
                }
              });

  function checkP(word) {
    word = word.replace(/[.?!,;:]/g, '');
    if (parenthesis && /\)$/.test(word)) {
      parenthesis = false;
      return true;
    }
    if (!parenthesis && /^\(/.test(word)) {
      if (/\)$/.test(word)) {
        return true
      };
      parenthesis = true;
    }
    return parenthesis;
  };

  function checkQ(word) {
    word = word.replace(/[.?!,;:]/g, '');
    if (quotes && /\"$/.test(word)) {
      quotes = false;
      return true;
    }
    if (!quotes && /^\"/.test(word)) {
      if (/\"$/.test(word)) return true;
      quotes = true;
    }
    return quotes;
  };
  
  completeTime();
};

function wrap(bool, type) {
  var classes = redicle.className.split(' ');
  if (bool) {
    if (classes.indexOf(type) < 0) classes.push(type);
  } else {
    if (classes.indexOf(type) >= 0) classes.splice(classes.indexOf(type), 1);
  }
  redicle.className = classes.join(' ');
};

processText(copy.value);

function applyWord(index) {
  redicle.innerHTML = '';
  var word = words[index];
  var percent = 38 / 100;
  var span = document.createElement('span');
  span.dataset.index = index;
  span.innerHTML = word.content.replace(/./g, function(char, i) {
    return i ===  getORP(word.content) ? '<b>' + char + '</b>' : char;
  });
  redicle.appendChild(span);
  //adjust location
  var orp = span.getElementsByTagName('b')[0];
  var center = Math.ceil(orp.offsetWidth / 2) - 2; //2px is half marker width
  span.style.left = (redicle.parentNode.offsetWidth * percent) - (orp.offsetLeft + center) + 'px';
  //wrap
  wrap(word.parenthesis, 'parenthesis');
  wrap(word.quotes, 'quotes');
};

function completeTime(){
  complete.innerText = (words.length / wpm.value).toFixed(1) + ' minutes';
};

function redicleIndex() {
  return redicle.firstElementChild ? parseInt(redicle.firstElementChild.dataset.index) : 0;
}

//controls
copy.addEventListener('blur', function() {
  pause();
  processText(copy.value);
});

document.getElementById('fastback').addEventListener('click', function() {
  pause();
  var index = redicleIndex();
  var goto = sentences.filter(function(v) {
    return v < index;
  }).pop() || 0;
  applyWord(goto);
});

document.getElementById('stepback').addEventListener('click', function() {
  pause();
  var index = redicleIndex();
  if (index !== 0) applyWord(index - 1);
});

document.getElementById('stop').addEventListener('click', function() {
  pause();
  redicle.innerHTML = '';
  redicle.className = '';
});

document.getElementById('play').addEventListener('click', function() {
  var classname = this.childNodes[0].className;
  if (classname.indexOf('play') >= 0) {
    var avgtime = 60000 / wpm.value;
    this.childNodes[0].className = classname.replace('play', 'pause');
    begin(avgtime);
  } else {
    pause();
  };
});

function begin(time){
  redicle.style.transitionDuration = (time*3) + 'ms';
  redicle.style.width = 0;
  redicle.style.marginLeft = '38%';
  redicle.style.backgroundColor = 'rgba(50,50,50,.8)';
  
  var b = setTimeout(function(){
    clearTimeout(b);
    redicle.removeAttribute('style');
    play(redicleIndex(), time);
  }, parseFloat(redicle.style.transitionDuration));
}

document.getElementById('stepforward').addEventListener('click', function() {
  pause();
  var index = redicleIndex();
  if (index !== words.length - 1) applyWord(index + 1);
});

document.getElementById('fastforward').addEventListener('click', function() {
  pause();
  var index = redicleIndex();
  var goto = sentences.filter(function(v) {
    return v > index;
  }).shift() || sentences.shift();
  applyWord(goto);
});

wpm.addEventListener('input', function(){
  this.style.width = this.value !== '' ? this.value.length + 'ch' : '1ch';
  completeTime();
});

var exceptions = [ 
  'ave.',
  'blvd.',
  'ct.',
  'dr.',
  'eg.',
  'etc.',
  'ie.',
  'mr.',
  'mrs.',
  'mo.',
  'rd.',
  'sr.',
  'st.',
  'ste.',
  'tpk.'
]

function play(index, time) {
  var ms = time;
  var word = words[index].content;
  if (/[,:;]$/.test(word)) ms = ms * 1.5;
  if (/\d+[^,:;.!?]{0,}$/.test(word)) ms = ms * 1.5;
  if (/[.?!]$/.test(word) && exceptions.indexOf(word.toLowerCase()) < 0) ms = ms * 3;
  applyWord(index);
  t = setTimeout(function() {
    if (words[index + 1]){
      play(index + 1, time);
    } else {
      pause();
      redicle.innerHTML = '';
      redicle.className = '';
    }
  }, ms);
}

function pause() {
  clearTimeout(t);
  var play = document.getElementById('play');
  var classname = play.childNodes[0].className;
  if (classname.indexOf('pause') >= 0) play.childNodes[0].className = classname.replace('pause', 'play');
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console