Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Ability to select new text and pause. Also added a bookmarklet.html page. #63

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ OpenSpritz currently needs a little more love to make it work with JSONP and nee

Once you have tested your changes and confirmed they work, send a pull request. Add yourself to the list of contributors below as well!

## Bookmarklet

[Bookmarklet](https://rawgithub.com/smorin/OpenSpritz/master/bookmarklet.html)

```
<a class="btn btn-large" href="javascript:(function(){ cb = function(){ create_spritz();}; var script=document.createElement('SCRIPT');script.src='https://miserlou.github.io/OpenSpritz/spritz.js?callback=cb?callback=cb'; script.onload=cb; document.body.appendChild(script);})();"> OpenSpritz this!</a>

```

### Contributors

* [Rich Jones](https://github.com/Miserlou)
Expand Down
5 changes: 5 additions & 0 deletions bookmarklet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<html><head><title>OpenSpritz</title></head><body>
<a class="btn btn-large" href="javascript:(function(){ cb = function(){ create_spritz();}; var script=document.createElement('SCRIPT');script.src='https://rawgithub.com/smorin/OpenSpritz/master/spritz.js?callback=cb?callback=cb'; script.onload=cb; document.body.appendChild(script);})();"> OpenSpritz this!</a>
</body>
<html>
2 changes: 2 additions & 0 deletions spritz.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<option value="900">900wpm</option>
<option value="950">950wpm</option>
</select>

<button type="button" onclick="spritz_pause_toggle()">Toggle Pause</button>

<span id="spritz_credits">
<a href="http://github.com/Miserlou/OpenSpritz">
Expand Down
101 changes: 99 additions & 2 deletions spritz.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ function create_spritz(){

spritz_loader = function() {

$.get("https://rawgithub.com/Miserlou/OpenSpritz/master/spritz.html", function(data){
//$.get("https://rawgithub.com/Miserlou/OpenSpritz/master/spritz.html", function(data){
$.get("https://rawgithub.com/smorin/OpenSpritz/master/spritz.html", function(data){

if (!($("#spritz_container").length) ) {
$("body").prepend(data);
}
},'html');

//$(document).bind('keypress', 'ctrl+a', function() {alert("worked")});
// Hot keys throws an error and seems to bind to every ket instead of just shift
//jQuery(document).bind('keypress', 'Shift+p',function (evt){alert('shift+p'); return false; });

};

load_jq(spritz_loader);
Expand All @@ -35,13 +41,18 @@ function load_jq(spritz_loader){
var done = false;
var script = document.createElement("script");
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
// https://github.com/jeresig/jquery.hotkeys
var script_keys = document.createElement("script");
script_keys.src = "https://rawgithub.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.js";

script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
spritz_loader();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
document.getElementsByTagName("head")[0].appendChild(script_keys);
} else{
spritz_loader();
}
Expand Down Expand Up @@ -71,8 +82,91 @@ function spritz(){
}
}

// The meat!
spritz_words = [""];
spritz_index = 1;
spritz_interval = undefined;
spritz_pause = false;

function spritz_pause_toggle() {
if (spritz_pause == true) {
spritz_pause = false;
} else {
spritz_pause = true;
}
}

function spritzify(input){
spritz_index = 1;
spritz_pause = false;
spritzify_go(input);
}

function spritzify_go(input){

var wpm = parseInt($("#spritz_selector").val(), 10);
var ms_per_word = 60000/wpm;

// Split on any spaces.
spritz_words = input.split(/\s+/);

var word = '';
var result = '';


// Preprocess words
var temp_words = spritz_words.slice(0); // copy Array
var t = 0;

for (var i=0; i<spritz_words.length; i++){

if(spritz_words[i].indexOf('.') != -1){
temp_words[t] = spritz_words[i].replace('.', '&#8226;');
}

// Double up on long words and words with commas.
if((spritz_words[i].indexOf(',') != -1 || spritz_words[i].indexOf(':') != -1 || spritz_words[i].indexOf('-') != -1 || spritz_words[i].indexOf('(') != -1|| spritz_words[i].length > 8) && spritz_words[i].indexOf('.') == -1){
temp_words.splice(t+1, 0, spritz_words[i]);
temp_words.splice(t+1, 0, spritz_words[i]);
t++;
t++;
}

// Add an additional space after punctuation.
if(spritz_words[i].indexOf('.') != -1 || spritz_words[i].indexOf('!') != -1 || spritz_words[i].indexOf('?') != -1 || spritz_words[i].indexOf(':') != -1 || spritz_words[i].indexOf(';') != -1|| spritz_words[i].indexOf(')') != -1){
temp_words.splice(t+1, 0, ".");
temp_words.splice(t+1, 0, ".");
temp_words.splice(t+1, 0, ".");
t++;
t++;
t++;
}

t++;

}
spritz_words = temp_words.slice(0);

// Set the timers!
if (! spritz_interval === undefined ) {
clearInterval(spritz_interval);
}
spritz_interval= setInterval(function() {
if (spritz_index < spritz_words.length) {
if (! spritz_pause) {
var p = pivot(spritz_words[spritz_index]);
spritz_index = spritz_index + 1;
$('#spritz_result').html(p);
}
} else {
clearInterval(spritz_interval);
}
} , ms_per_word);


}

// The meat!
function spritzify_orig(input){

var wpm = parseInt($("#spritz_selector").val(), 10);
var ms_per_word = 60000/wpm;
Expand Down Expand Up @@ -170,6 +264,9 @@ function pivot(word){
else{

var tail = 22 - (word.length + 7);
if( tail < 0) {
tail = 0;
}
word = '.......' + word + ('.'.repeat(tail));

var start = word.slice(0, word.length/2);
Expand Down