Last active
July 17, 2016 22:35
-
-
Save felipeochoa/b6e99a919edba10ca0ab5f911c601434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Check Netflix availability from you IMDB watchlist | |
// @namespace https://github.com/felipeochoa | |
// @description Filter your IMDB watchlist based on Netflix availability | |
// @author https://github.com/felipeochoa | |
// @include http://www.imdb.com/user/*/watchlist | |
// @include http://www.imdb.com/user/*/watchlist?* | |
// @include https://www.imdb.com/user/*/watchlist | |
// @include https://www.imdb.com/user/*/watchlist?* | |
// @version 1.0 | |
// @grant | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Based on https://greasyfork.org/en/scripts/10290-netflix-us-availability-on-imdb-com/code | |
var yearRe = /^(?:\(I\) )?\(([0-9]{4})\)$/, | |
onlyNetflix = false; | |
$('<button id="filter-netflix">Only show titles available on Netflix (GreaseMonkey)</button>') | |
.css({ | |
display: "block", | |
padding: ".25em 2em", | |
textAlign: "center", | |
background: "#bbb", | |
color: "white", | |
borderRadius: ".5em", | |
fontWeight: "bold", | |
fontSize: "1em", | |
border: "none", | |
outline: "none" | |
}) | |
.appendTo(".faceter-fieldset.watch_options") | |
.click(function() { | |
if (onlyNetflix) { | |
$(".lister-list > .lister-item").show(); | |
$(this).html("Only show titles available on Netflix (GreaseMonkey)"); | |
} else { | |
$(this).html("Show all titles (GreaseMonkey)"); | |
$(".lister-list > .lister-item").each(function (ix, item) { | |
var $item = $(item), | |
title = $item.find(".lister-item-header > a").text(), | |
year = $item.find(".lister-item-year").text().match(yearRe), | |
url; | |
if (year === null) { | |
url = 'http://netflixroulette.net/api/api.php?title=' + title; | |
} else { | |
url = 'http://netflixroulette.net/api/api.php?title=' + title + '&year=' + year[1]; | |
} | |
console.log([title, year]); | |
$.ajax({ | |
url: url | |
}).error(function(err) { | |
$item.hide(); | |
}).done(function(data) { | |
if ($item.find(".lister-item-header > .on-netflix").length === 0) { | |
$('<img class="on-netflix" src="http://i.imgur.com/LwcTA6Q.png">') | |
.appendTo($item.find(".lister-item-header")) | |
.css({ | |
display: "inline-block", | |
maxHeight: "1em", | |
verticalAlign: "middle", | |
paddingLeft: "1em" | |
}); | |
} | |
}); | |
}); | |
} | |
onlyNetflix = !onlyNetflix; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment