Skip to content

Instantly share code, notes, and snippets.

@xtranophilist
Last active April 12, 2017 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtranophilist/4636655 to your computer and use it in GitHub Desktop.
Save xtranophilist/4636655 to your computer and use it in GitHub Desktop.
Opens up relative GetGlue Page for the current IMDB page
slugify=function(str){
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/-+/g, ' ') // replace dash with whitespace
.replace(/\s+/g, '_'); // collapse whitespace and replace by -
return str;
};
var genre, title, director = '';
if ($("[class=infobar]").html().split('&nbsp;')[0]=="\n\nTV Series")
genre = 'tv_shows';
else
genre = 'movies';
title = slugify($("[itemprop=name]").html().split('\n')[0]);
if (genre=='movies'){
director = slugify($("[itemprop=name]", $("[itemprop=director]")).text());
//only use first and last name for director
names = director.split('_');
director = names[0]+'_'+names[names.length-1];
}
//strip 'the_'
title = title.replace(/the_/g,'');
var link = 'http://getglue.com/'+genre+'/'+title+'/'+director;
window.open(link);
slugify=function(str){
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/-+/g, ' ') // replace dash with whitespace
.replace(/\s+/g, '_'); // collapse whitespace and replace by -
return str;
};
var genre, title, director = '';
if ($("[class=infobar]").html().split('&nbsp;')[0]=="\n\nTV Series")
genre = 'tv_shows';
else
genre = 'movies';
title = slugify($("[itemprop=name]").html().split('\n')[0]);
if (genre=='movies'){
director = slugify($("[itemprop=name]", $("[itemprop=director]")).text());
//only use first and last name for director
names = director.split('_');
director = names[0]+'_'+names[names.length-1];
}
//strip 'the_'
title = title.replace(/the_/g,'');
var link = 'http://o.getglue.com/'+genre+'/'+title+'/'+director;
window.open(link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment