Skip to content

Instantly share code, notes, and snippets.

@esneider
Last active October 11, 2015 21:30
Show Gist options
  • Save esneider/0a0cc075f4962baf95f9 to your computer and use it in GitHub Desktop.
Save esneider/0a0cc075f4962baf95f9 to your computer and use it in GitHub Desktop.
Bookmarklet to color-rank 8tracks search results
function parse(str){
return parseInt(str.replace(/,/g, ""));
};
function cap(num, min, max) {
return Math.max(min, Math.min(num, max));
};
$(".card").each(function(){
var plays = $(this).find(".plays_count").text();
var likes = $(this).find(".likes_count").text();
var ratio = parse(likes) * 10.0 / parse(plays);
var value = cap(1.3 - ratio, 0, 1);
var color = Math.floor(255 * value);
var chars = "rgb(255," + color + "," + color + ")";
$(this).find(".reason").css("background-color", chars);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment