Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2016 19:31
Show Gist options
  • Save anonymous/637e1547666f9f6b1b771a1f260c3cc0 to your computer and use it in GitHub Desktop.
Save anonymous/637e1547666f9f6b1b771a1f260c3cc0 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Buttons Watchlist 0.1.1
// @namespace TVMaze
// @version 0.1.1
// @description Adding buttons for status
// @author cicelle
// @include http://www.tvmaze.com/watchlist*
// @downloadURL https://raw.githubusercontent.com/cicelle/tvmaze/master/watchlist-buttons.user.js
// @license The MIT License (MIT)
// ==/UserScript==
(function() {
//gets the number from end of url, sets the page offset
try {
$("html, body").scrollTop(window.location.href.match(/[\?&]page_y=(\d+)/)[1]);
} catch (e) {
}
$('head').append('<style>'+
'.buttons{padding:0 5px; cursor:pointer;}'+
'th:nth-child(4),th:nth-child(5),th:nth-child(6),th:nth-child(7){text-align:center;}'+
'td:nth-child(4),td:nth-child(5),td:nth-child(6),td:nth-child(7){text-align:center;}'+
'.checked{background:#ccc;}'+
'</style>');
$('thead tr').each(function(){
$(this).append('<th>S</th><th>U</th><th>A</th><th>W</th>');
});
$('tbody tr').each(function(){
$(this).append('<td><span data-type="2" class="buttons"><i class="fa fa-ban fa-lg"></i></span></td>'+
'<td><span data-type="" class="buttons"><i class="fa fa-eye-slash fa-lg"></i></span></td>'+
'<td><span data-type="1" class="buttons"><i class="fa fa-cloud fa-lg"></i></span></td>'+
'<td><span data-type="0" class="buttons"><i class="fa fa-eye fa-lg"></i></span></td>');
});
$('.buttons').click(function(){
var key = $($(this).parent().parent()[0]).attr('data-key');
var type = $(this).attr('data-type');
var select = $(this).parent().parent().find('td:nth-child(3)').find('select');
select.val(type);
$(select).trigger('change');
var url = window.location.href.replace(/[\?&]page_y=\d+/, "").replace(/\?$/, "") ;
window.location.href = url + (url.indexOf("?") < 0 ? "?" : "&") + 'page_y=' + $(document).scrollTop();
});
$('tbody select').each(function(){
var val = $(this).val();
if(val == 1){
$(this).parent().next().next().next().addClass('checked');
}else if(val == ''){
$(this).parent().next().next().addClass('checked');
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment