Skip to content

Commit

Permalink
Added features we came up with in the workshop.
Browse files Browse the repository at this point in the history
  • Loading branch information
greysonp committed Apr 3, 2014
1 parent 73a798e commit 5e11c57
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html, body {
font-family: "Comic Sans MS" !important
}
35 changes: 33 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
replacements = {
'the' : 'teh',
'lose' : 'loose',
'there' : 'their',
'their' : 'there',
'too' : 'to',
'weird' : 'wierd',
'its' : 'it\'s',
Expand All @@ -14,17 +14,48 @@ replacements = {
'four' : 'for'
}

// A list of urls of images of David Hasslehoff pics
hasslehoffs = [
'http://cdn3.sportsmockery.com/wp-content/uploads/2013/04/hasselhoff.jpg',
'http://static.comicvine.com/uploads/original/0/40/749134-david_hasselhoff.jpg',
'http://scm-l3.technorati.com/glosslip/2009/05/230441-thehoff_super.jpg',
'http://img.blesk.cz/img/1/full/1408174-img-david-hasselhoff.jpg'
];

// We look for whenever the contents of text inputs and textareas change
$('input[type="text"], textarea').on('change keyup paste', function() {
// Grab the contents of the text area
var contents = $(this).val();

// We only want to do a text substitution if the last input was the user pressing the spacebar
if (contents.charAt(contents.length - 1) != ' ')
return;

// We go through all of the words in our replacements dictionary
for (key in replacements) {
// Then, replace the word with with its substitute by building a regular expression
var regex = new RegExp(key);
// The '\\b' part is a special regex character that says we only want to match whole words,
// not substrings of words
var regex = new RegExp('\\b' + key + '\\b');
contents = contents.replace(regex, replacements[key]);
}
// Finally, set the content string with all of the replacements made
// as the contents of the text input/text area
$(this).val(contents);
});

// This event fires when the page is finished loading
$(document).ready(function() {
// Go through each image on the page...
$('img').each(function() {
// ...and replace it with a picture of David Hasslehoff
var index = Math.floor(Math.random() * hasslehoffs.length);
$(this).attr('src', hasslehoffs[index]);
});

// If you ever go to facebook...
if (window.location.href.indexOf('facebook') > -1) {
// ...redirect to myspace
window.location.href = 'http://myspace.com';
}
});
4 changes: 4 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"js/main.js"
],

"css": [
"css/main.css"
],

// This tells Chrome to run these scripts on every page
"matches": [
"http://*/*",
Expand Down

0 comments on commit 5e11c57

Please sign in to comment.