|
// ==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); |
|
}); |