forked from angus-c/wordy-extension
/
bookmarklet.txt
1 lines (1 loc) · 2.44 KB
/
bookmarklet.txt
1
javascript: (function(){window.counter={analyze:function(m,k,l){this.data={};this.data.total=0;var n={};var j=m.split(/[\?\!\.\,;]*[\s+–]|[\?\!\.\,;]$/);j.forEach(function(o){o=o.toLowerCase();if((o.length>=k)&&!/[^a-zA-ZÅåÄäâàáÖöØøÆæÉéÈèÜüÊêÛûÎî\-\']/.test(o)&&l.test(o)){n[o]?n[o]++:n[o]=1;this.data.total++}},this);this.data.words=Object.keys(n).sort(function(p,o){return n[o]>n[p]?1:-1}).map(function(o){return[o,n[o]]});return this},tabulate:function(){var j="";this.data.words.forEach(function(k){j+="<tr>";j+=['<td style="padding-right: 15px">',k[0],"</td>",'<td style="padding-right: 15px">',k[1],"</td>",'<td style="padding-right: 45px">',["(",(100*(k[1]/this.data.total)).toFixed(2),"%)"].join(""),"</td>"].join("");j+="</tr>"},this);return j}};var a,h,g,b,e;function i(j){a=document.createElement("iframe");a.frameBorder=0;document.body.appendChild(a);var l=a.contentDocument;a.id="popup";h=l.createElement("table");g=l.createElement("span");b=l.createElement("input");b.id="slider";b.type="range";b.min=1;b.max=8;b.value=5;b.title="minimum word size";e=l.createElement("input");e.id="regex";e.type="text";e.value=".";e.title="filter by regular expression";g.innerHTML="x";g.title="close";a.style.cssText="position:fixed; right:10px; top: 0; height: 300px; min-width: 400px; z-index: 99999999; overflow: auto";l.body.style.cssText="font-family: 'Helvetica Neue', Verdana, Arial, sans serif; background:rgba(50,50,50,0.9); font-size: 11pt";h.style.cssText="color: #eee; border: 0; margin-top: 30px; text-align: left; font-size: 9pt";b.style.cssText="position:absolute; left:10px; top:5px; width: 150px; color: #fff; background-color: #000; cursor: pointer";e.style.cssText="position:absolute; left:180px; top:5px; width: 150px; background: transparent; outline: 0; color: #fff; border: solid 1px white";g.style.cssText="position:absolute; right:10px; top:3px; font-size: 14pt; color: #aeaeae; cursor: pointer";l.body.appendChild(g);l.body.appendChild(b);l.body.appendChild(e);l.body.appendChild(h);g.addEventListener("click",d);b.addEventListener("change",function(){k});e.addEventListener("keyup",function(){k});g.addEventListener("click",d);b.addEventListener("change",k);e.addEventListener("keyup",k);k();function k(){c(l.getElementById("slider").value,new RegExp(l.getElementById("regex").value))}}function d(){a.parentNode.removeChild(a);a=null}function f(j){h.innerHTML=j}function c(k,j){f(counter.analyze(document.body.textContent,k,j).tabulate())}i()})();