Skip to content

Instantly share code, notes, and snippets.

@ekosz
Created February 22, 2012 14:19
Show Gist options
  • Save ekosz/1885319 to your computer and use it in GitHub Desktop.
Save ekosz/1885319 to your computer and use it in GitHub Desktop.
OK Cupid Enhanced Source
// Setup
var userHTML = function(data) {
},
createUser = function(name) {
localStorage[name] = JSON.stringify({name: name, stars: null, notes: '', lastViewed: null});
},
getUser = function(name) {
if(localStorage[name]) {
} else { createUser(name); }
return JSON.parse(localStorage[name]);
},
saveUser = function(user) {
localStorage[user.name] = JSON.stringify(user);
},
safeViewedHTML = function(user) {
if(user.lastViewed) {
text = $.timeago(user.lastViewed);
} else {
text = "Never";
}
return "<div class='last-viewed'><span>Last Viewed</span>"+text+"</div>"
},
safeNotesHTML = function(user) {
var $div = $('<div class="notes">'),
$text = $('<div class="text">"'+user.notes+'"</div>');
$text.dblclick(function() {
var self = this;
$input = $('<textarea style="height: 50px">'+user.notes+'</textarea>').blur(function(e) {
user.notes = $(this).val();
$(self).text('"'+user.notes+'"');
saveUser(user);
$(self).show();
$(this).remove();
});
$(this).before($input);
$(this).hide();
$input.focus();
});
$div.prepend($("<span>Notes</span>"));
$div.append($text);
return $div;
},
safeRatingHTML = function(user) {
var $ul = $("<ul id='personality-rating' class='safe-rating star-rating profile_rating'>");
$ul.append($("<li class='current-rating'>").css({width: (user.stars || 0)/5*100+'%'}));
$ul.append($("<li><a class='one-star' href='#'>1</a></li>"));
$ul.append($("<li><a class='two-stars' href='#'>2</a></li>"));
$ul.append($("<li><a class='three-stars' href='#'>3</a></li>"));
$ul.append($("<li><a class='four-stars' href='#'>4</a></li>"));
$ul.append($("<li><a class='five-stars' href='#'>5</a></li>"));
$ul.find("li:not(.current-rating) a").click(function(e) {
e.preventDefault();
var num = parseInt($(this).text(), 10);
$ul.find('.current-rating').css({width: num*100/5+'%'});
user.stars = num;
saveUser(user);
return false;
});
var $div = $("<div class='rating'>");
$div.prepend($("<span>Your SafeRating</span>"));
$div.append($ul);
return $div;
},
findUsers = function() {
$('.match_row:not([data-enhanced])').each(function(e) {
var user = getUser($(this).find('.username').text());
$(this).find(".actions").prepend(safeRatingHTML(user));
$(this).find(".actions").prepend(safeNotesHTML(user));
$(this).find(".actions").prepend(safeViewedHTML(user));
$(this).attr('data-enhanced', true);
$(this).css({height: $(this).find('.actions').height() + 100});
});
},
matchRegex = /\/match/,
profileRegex = /\/profile\/(\w+)/;
// Main
$(function() {
if(location.pathname.match(profileRegex)) {
var name = location.pathname.match(profileRegex)[1];
var user = getUser(name),
$rating = $("#rating");
$rating.prepend(safeRatingHTML(user));
$rating.prepend(safeNotesHTML(user));
$rating.prepend(safeViewedHTML(user));
user.lastViewed = new Date();
saveUser(user);
} else if(location.pathname.match(matchRegex)) {
findUsers();
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 2000) {
findUsers();
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment