Skip to content

Instantly share code, notes, and snippets.

@rampion
Created November 13, 2012 03:59
Show Gist options
  • Save rampion/4063843 to your computer and use it in GitHub Desktop.
Save rampion/4063843 to your computer and use it in GitHub Desktop.
A greasemonkey script to add queue buttons to Hulu's "Watch [...] online" pages. Click the "raw" link to install (if you have greasemonkey).
// ==UserScript==
// @name HuluQueueButtons
// @namespace rampion.github.com
// @description Add buttons to Hulu's "Watch [...] online" pages to let you queue/dequeue videos
// @include http://www.hulu.com/watch/*
// @version 1
// @grant none
// ==/UserScript==
$(function(){
// make our queue/dequeue button mimic the style of the native queue/dequeue
// buttons we see in other pages
$('<style>').
html(
'.queue-button {'+
' background: url("http://static.huluim.com/huluguru/masthead-s9e77b704d9.png") no-repeat scroll 0 0 transparent;'+
' height: 21px;'+
' width: 76px;'+
'}'+
'.queue-button {'+
' background-position: 0 -523px !important;'+
'}'+
'.queue-button:hover {'+
' background-position: 0 -319px !important;'+
'}'+
'.queue-button.added {'+
' background-position: 0 -384px !important;'+
'}'+
'.queue-button.added:hover {'+
' background-position: 0 -384px !important;'+
'}'
).
appendTo(document.head)
;
// find the id of this video
var id = +(document.location.toString().match(/\d+/)[0]);
// see whether this video is already in the queue
$.get('http://www.hulu.com/api/2.0/queued_video_ids', function(data){
if (data.indexOf(id) >= 0){
// and make the UI reflect this
$queueButton.addClass('added');
}
});
(function(t){
// wait for the functional bar to be loaded into the page
var $functionalBar = $('.functional-bar');
if ($functionalBar.length == 0){
setTimeout( arguments.callee, t, [2*t] ); // retry after a(n exponentially growing) delay
} else {
// then add our queue/dequeue button
var $queueButton = $('<a class="beacon beacon-click queue-button"/>').
appendTo( $functionalBar ).
click(function(){
// add or remove to queue, as appropriate
$.post(
$queueButton.hasClass('added') ?
'http://www.hulu.com/api/2.0/remove_from_queue' :
'http://www.hulu.com/api/2.0/add_to_queue',
{ id: id },
function(data){
// after add/remove, update UI
$queueButton.toggleClass('added');
}
);
})
;
}
})(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment