diff --git a/README b/README.md similarity index 86% rename from README rename to README.md index a210463..6014671 100644 --- a/README +++ b/README.md @@ -1,7 +1,6 @@ -ABOUT ------------------------------------------------------------------------------- +# ABOUT -This is the source code for http://writtenkitten.net/, provided for the +This is the source code for , provided for the interest of anyone who'd like to know how it works, or adapt it for their own use. @@ -11,8 +10,7 @@ awesome me might consider it. -- Skud and Emily -LICENSE ------------------------------------------------------------------------------- +# LICENSE Copyright (c) 2011 Alex "Skud" Bayley and Emily Turner All rights reserved. diff --git a/index.html b/index.html index d2206cf..42af7e5 100644 --- a/index.html +++ b/index.html @@ -1,24 +1,27 @@ - + + Written? Kitten! - - - - - - + + + + @@ -139,82 +120,85 @@ var kittens_earned = 0; var kittens_shown = 0; var warning_shown = false; +var warning; +if (typeof localStorage == "undefined") warning = "#warning-no-ls" +else warning = "#warning-ls"; var next_kitten = { - img_url: '', - page_url: '', - alt: '' + img_url: '', + page_url: '', + alt: '' }; function word_count(text, wc) { - if (current_word_count >= 10 && warning_shown == false) { - show_warning(); - } - text = text.replace(/^\s*|\s*$/g,''); //removes whitespace from front and end - text = text.replace(/\s+/g,' '); // collapse multiple consecutive spaces - var words = text.split(" "); - wc.value = words.length; - current_word_count = wc.value = words.length; - current_word_count = document.getElementById('displayWords').innerHTML = words.length; - kittens_earned = current_word_count / words_for_reward; - if (kittens_earned >= kittens_shown+1) { - show_kitten(); - } + if (typeof localStorage != "undefined") localStorage.text = text; + if (current_word_count >= 10 && warning_shown == false) { + show_warning(); + } + text = text.replace(/^\s*|\s*$/g,''); //removes whitespace from front and end + text = text.replace(/\s+/g,' '); // collapse multiple consecutive spaces + var words = text.split(" "); + wc.value = words.length; + current_word_count = wc.value = words.length; + $("#displayWords").html(wc.value); + kittens_earned = current_word_count / words_for_reward; + if (kittens_earned >= kittens_shown+1) { + show_kitten(); + } } function show_warning() { - $("#warning").fadeIn('slow'); + $(warning).fadeIn("slow"); } function hide_warning(immediate) { - if (immediate == true) { - $("#warning").hide(); - } else { - $("#warning").fadeOut('slow'); - } - warning_shown = true; + if (immediate == true) { + $(warning).hide(); + } else { + $(warning).fadeOut("slow"); + } + warning_shown = true; } function show_kitten() { - hide_warning("immediate"); - kittens_shown++; - document.getElementById('kittenFrame').style.backgroundImage = "url(" + next_kitten.img_url + ")"; - document.getElementById('kittenCredit').innerHTML = "" + next_kitten.alt + ""; - fetch_next_kitten(); +// console.log("show"); + hide_warning(true); + kittens_shown++; + $("#kittenFrame").css("background-image", "url(" + next_kitten.img_url + ")"); + $("#kittenCredit").html("" + next_kitten.alt + ""); + fetch_next_kitten(); } function fetch_next_kitten() { - if (tmp = getParameterByName("search")) { - search = tmp; - document.getElementById("titleKitten").innerHTML = "Kitten!"; - document.getElementById("titleSearch").innerHTML = " " + search + "!"; - } else { - search = "kitten,cute" - } - - var flickr_url = "http://api.flickr.com/services/rest/?format=json&sort=interestingness-desc&method=flickr.photos.search&license=4&extras=owner_name&tags=" + search + "&tag_mode=all&api_key=5dfc80756edad8d0566cf40f0909324e&jsoncallback=?"; - - $.getJSON(flickr_url, function(data){ - if (data.stat == "ok") { - var i = Math.random(); - i = i * 100; - i = Math.ceil(i); - photo = data.photos.photo[i]; - next_kitten.img_url = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_z.jpg"; - next_kitten.page_url = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id; - next_kitten.alt = photo.title + " by " + photo.ownername + " (under CC-BY)"; - document.getElementById('nextKitten').src = next_kitten.img_url; - } - }); + if (tmp = getParameterByName("search")) { + search = tmp; + $("#titleKitten").html("Kitten!"); + $("#titleSearch").html(" );" + search + "!"); + } else { + search = "kitten,cute"; + } + + var flickr_url = "http://api.flickr.com/services/rest/?format=json&sort=interestingness-desc&method=flickr.photos.search&license=4&extras=owner_name&tags=" + search + "&tag_mode=all&api_key=5dfc80756edad8d0566cf40f0909324e&jsoncallback=?"; + + $.getJSON(flickr_url, function(data) { + if (data.stat == "ok") { + var i = Math.ceil(Math.random() * 100); + var photo = data.photos.photo[i]; + next_kitten.img_url = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_z.jpg"; + next_kitten.page_url = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id; + next_kitten.alt = photo.title + " by " + photo.ownername + " (under CC-BY)"; + $("#nextKitten").attr("src", next_kitten.img_url); + } + }); } function change_reward(howmany) { - console.log("rewarding every " + howmany) - words_for_reward = howmany; - kittens_earned = current_word_count / howmany; - kittens_shown = parseInt(kittens_earned); - console.log("kittens_earned = " + kittens_earned); - console.log("kittens_shown = " + kittens_shown); +// console.log("rewarding every " + howmany); + words_for_reward = howmany; + kittens_earned = current_word_count / howmany; + kittens_shown = parseInt(kittens_earned); +// console.log("kittens_earned = " + kittens_earned); +// console.log("kittens_shown = " + kittens_shown); } function getParameterByName(name) { @@ -222,35 +206,34 @@ var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); - if(results == null) + if (results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } - - - - - +

Written? Kitten!

- @@ -260,37 +243,49 @@

Warning!

- Fresh kitten every words + words Current word count: 0 - About + About
- + + - \ No newline at end of file +