Created
February 27, 2014 23:07
-
-
Save osuushi/9261629 to your computer and use it in GitHub Desktop.
OpenSpritz bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:void(function(){function spritzify(e,t,n){for(var i=6e4/n,l=e.split(" "),o=l.slice(0),r=0,a=0;a<l.length;a++)-1!=l[a].indexOf(".")&&(o[r]=l[a].replace(".","•")),(-1!=l[a].indexOf(",")||-1!=l[a].indexOf(":")||-1!=l[a].indexOf("-")||-1!=l[a].indexOf("(")||l[a].length>8)&&-1==l[a].indexOf(".")&&(o.splice(r+1,0,l[a]),o.splice(r+1,0,l[a]),r++,r++),(-1!=l[a].indexOf(".")||-1!=l[a].indexOf("!")||-1!=l[a].indexOf("?")||-1!=l[a].indexOf(":")||-1!=l[a].indexOf(";")||-1!=l[a].indexOf(")"))&&(o.splice(r+1,0,"."),o.splice(r+1,0,"."),o.splice(r+1,0,"."),r++,r++,r++),r++;l=o.slice(0);for(var a=0;a<l.length;a++)setTimeout(function(e){return function(){var n=pivot(l[e]);"undefined"!=typeof $?$(t).html(n):t.tagName?t.innerHTML=n:document.querySelector(t).innerHTML=n}}(a),i*a)}function pivot(e){var t=e.length;if(6>t){for(var n=1;e.length<22;)n>0?e+=".":e="."+e,n=-1*n;var i="",l="";t%2===0?(i=e.slice(0,e.length/2),l=e.slice(e.length/2,e.length)):(i=e.slice(0,e.length/2),l=e.slice(e.length/2,e.length));var o;o="<span class='start'>"+i.slice(0,i.length-1),o+="</span><span class='pivot'>",o+=i.slice(i.length-1,i.length),o+="</span><span class='end'>",o+=l,o+="</span>"}else{var r=22-(e.length+7);e="......."+e+".".repeat(r);var o,i=e.slice(0,e.length/2),l=e.slice(e.length/2,e.length);o="<span class='start'>"+i.slice(0,i.length-1),o+="</span><span class='pivot'>",o+=i.slice(i.length-1,i.length),o+="</span><span class='end'>",o+=l,o+="</span>"}return o=o.replace(/\./g,"<span class='invisible'>.</span>")}function clearTimeouts(){for(var e=window.setTimeout(function(){},0);e--;)window.clearTimeout(e)}function getSelectionText(){var e="";if(window.getSelection){var t=window.getSelection();if(t.rangeCount){for(var n=document.createElement("div"),i=0;i<t.rangeCount;++i)n.appendChild(t.getRangeAt(i).cloneContents());e=n.textContent}}else document.selection&&"Text"==document.selection.type&&(e=document.selection.createRange().text);return e}String.prototype.repeat=function(e){return new Array(e+1).join(this)},document.body.innerHTML+="<style>@import url(http://fonts.googleapis.com/css?family=Droid+Sans+Mono); #openspritz-text .pivot { color: #D00; }#openspritz-text .invisible { color: #fff }#openspritz-text { text-align: center; }";var container=document.createElement("div");container.style.position="fixed",container.style.top="0",container.style.left="0",container.style.width="100%",container.style.zIndex="90000";var bar=document.createElement("div");bar.style.width="360px",bar.style.marginLeft=bar.style.marginRight="auto",bar.style.height="90px",bar.style.backgroundColor="white",bar.style.border="2px solid grey",bar.style.fontFamily="Droid Sans Mono",bar.style.paddingTop="9px",bar.style.textAlign="center",bar.style.boxSizing="border-box",document.body.appendChild(container),container.appendChild(bar);var text=document.createElement("div");text.id="openspritz-text",text.innerHTML="Select Some Text",text.style.fontSize="24px";for(var speedSelect=document.createElement("select"),i=100;1e3>=i;i+=100){var opt=document.createElement("option");opt.value=i,opt.innerHTML=i+"wpm",speedSelect.appendChild(opt)}bar.appendChild(speedSelect);var startButton=document.createElement("button");startButton.innerHTML="->",bar.appendChild(startButton),bar.appendChild(text),startButton.onclick=function(){var e=getSelectionText(),t=speedSelect.value;clearTimeouts(),spritzify(e,text,t)};}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment