Skip to content

Instantly share code, notes, and snippets.

@ayan4m1
Last active January 1, 2016 14:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayan4m1/8157128 to your computer and use it in GitHub Desktop.
Save ayan4m1/8157128 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name random-flix
// @namespace http://thekreml.in
// @version 0.4.1
// @grant none
// @description Add a 'Random Episode' button to Netflix Watch Instantly pages.
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @match http://movies.netflix.com/WiMovie/*
// ==/UserScript==
jQuery(function($) {
// define a list of page types that we want to match on / insert into
var handlers = [
{
'selector': '.episodeList li',
'insert': function() {
var elem = $('<span class="mltBtn" style="float:right"><a class="svf-button svfb-silver evo-btn svf-button-inq"><span class="inr">Random Episode</span></a></span>');
elem.on('click', function() {
var idx = randomIdx($('.episodeList li').length);
$('#e' + idx).trigger('click');
});
$('#seasonSelector, .episodeHeading').after(elem);
}
},
{
'selector': '.currentSeason .videoRow',
'insert': function() {
var elem = $('<span class="mltBtn" style="position:relative;top:35px;float:right"><a class="svf-button svfb-silver evo-btn svf-button-inq"><span class="inr">Random Episode</span></a></span>');
elem.on('click', function() {
var idx = randomIdx($('.currentSeason .videoRow').length);
$('.currentSeason .videoRow:nth-child(' + idx + ')').trigger('click');
});
$('.video-controls').css('height', '70px');
$('.video-controls .video-tabs').after(elem);
},
'buttonHtml': '<div class="write-btn-wrap"><div class="dp-btn-wrap"><a class="dp-btn">Random Episode</a></div></div>'
}
];
// utility function to select a random link
function randomIdx(max) {
return Math.ceil(Math.random() * max);
}
// search the page for each handler and insert if applicable
$.each(handlers, function(i, v) {
if ($(v.selector).length > 0) {
v.insert()
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment