Skip to content

Instantly share code, notes, and snippets.

@cheapsteak
Last active December 19, 2015 01:18
Show Gist options
  • Save cheapsteak/5874339 to your computer and use it in GitHub Desktop.
Save cheapsteak/5874339 to your computer and use it in GitHub Desktop.
For fun
/**
* A shamefully unintuitive/unreadable/unmaintainable but fun solution to this problem...or is it?
* http://stackoverflow.com/questions/17334688/how-can-i-abstract-generalize-functions-that-perform-similar-but-just-slightly/17335053?noredirect=1#17335053
*/
json = [
{target: '.FFEC-Display', title : 'h3', actions : [{action: 'find', target: '.movie-link'}, 'prepend']},
{target: '.MovieItemsRotator .item', title: '.Title', actions: ['prepend']}
];
$.each(json, function(index, j){
$(j.target).each(function(i, el){
var title = $(el).find(j.title).text().replace(blacklistRegexp, '').trim();
/* you can ignore the code in here
var tomato = findTomato(title, tomatoes);
var classes = ["poster-width", "overlay"];
var templateData = tomato ? prepareData(tomato, classes) : { query: title, classes: namespaceClasses(classes) };
*/
var abomination = $(el);
$.each(j.actions, function(k, action){
if(typeof action === "string") {
abomination = abomination[action]();
} else {
abomination = abomination[action.action](action.target);
}
});
abomination(Handlebars.templates.ratings(templateData));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment