Skip to content

Instantly share code, notes, and snippets.

@chauek
Last active August 29, 2015 14:08
Show Gist options
  • Save chauek/b8c24fe9d0e7b5d0a275 to your computer and use it in GitHub Desktop.
Save chauek/b8c24fe9d0e7b5d0a275 to your computer and use it in GitHub Desktop.
Skrypt poprawia wyświetlanie widoku programu na weeb.tv
// ==UserScript==
// @name Panel weeb.tv
// @namespace weeb.tv
// @version 0.1
// @description Skrypt poprawia wyświetlanie widoku programu na weeb.tv
// @author Chauek
// @match http://weeb.tv/online/*
// @match http://weeb.tv/channel/*
// @grant none
// ==/UserScript==
//
// Skrypt zmienia widok strony podgladu telewizji na bardziej uzyteczna wersje.
//
// UWAGA!
// Strona Weeb.tv utrzymuje się z reklam bądź kont premium.
// Ten skrypt przykrywa reklamy dlatego powinni go używać tylko użytkownicy premium.
//
// Skrypt zostal przetestowany na Chrome z pluginem Tempermonkey oraz na
// Firefox z pluginem Greasemonkey. Aby go użyć należy zainstalować plugin
// i wejść na stronę weeb.tv i dodać skrypt do pluginu.
//
$( document ).ready(function() {
console.log('Start');
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var originalWidth = 550;
var originalHeight = 390;
var contentWidth = windowWidth - 20;
var contentHeight = windowHeight - 20;
var newWidth = contentWidth;
var newHeight = contentHeight;
if (newHeight > (newWidth*originalHeight)/originalWidth) {
newHeight = Math.floor((newWidth*originalHeight)/originalWidth);
}
else {
newWidth = Math.floor((newHeight*originalWidth)/originalHeight);
}
var playlistWidth = contentWidth - newWidth; // 60 na marginesy i bordery
var playlistHeight = newHeight;
init_overlay_mode(newWidth, newHeight, playlistWidth, playlistHeight);
var playlist = [];
var channels = [];
var channelsNames = [];
var search = '';
resetPlaylist(channels, playlist, channelsNames);
rewritePlaylist(channels, playlist, channelsNames, search);
$( "#search_box" ).keyup(function() {
searchPlaylist( $( "#search_box" ).val() );
});
});
function init_overlay_mode(newWidth, newHeight, playlistWidth, playlistHeight)
{
var player_video = $("#player_video").html();
var playlist = $("#playlist").html();
$("#player_video").remove();
$("#playlist").remove();
$("body").append('<div id="video_popup" style="display: block; width: 100%;height: 700;position: absolute;top: 0;left: 0;z-index: 100;background-color: #efefef;">'+
'<div id="player_video">'+player_video+'</div>'+
'<div id="playlist_container" style="display:block; float:left;">'+
'<div ><input id="search_box" style="width:100%;margin-top: 7px;color:#aaa;" type="text" value="Szukaj..." /> </div>'+
'<div id="playlist" style="width:100%;border: ">'+playlist+'</div>'+
'</div></div>');
$("#player_video").css('width', newWidth);
$("#player_video").css('height', newHeight);
resize_embedded($('#player_object'), newWidth, newHeight);
$("#playlist_container").width(playlistWidth);
$("#playlist_container").height(playlistHeight);
$("#playlist").height(playlistHeight-30);
$("#playlist a").css('float', 'left');
$("#playlist a").css('margin-right', '5px');
$(window).scrollTop($('#player_video').offset().top);
$("#container").remove();
$('#search_box').focus(function() {
if ($('#search_box').css('color') == 'rgb(170, 170, 170)') {
$('#search_box').css('color', '#000');
$('#search_box').unbind( "focus" );
$('#search_box').val( "" );
}
});
}
function resize_embedded(object, width, height)
{
var html = $(object).html();
var regex = /(width=")[0-9]+(")/;
html = html.replace(regex, "$1"+width+"$2");
var matches = html.match(regex)
var regex = /(height=")[0-9]+(")/;
html = html.replace(regex, "$1"+height+"$2");
$(object).html(html);
}
function resetPlaylist(channels, playlist, channelsNames)
{
$('#playlist').children().each(function( index, element ) {
var name = $(this).find('strong').first().text();
var slag = name.replace(/[ ,\(\)\*\^]/g, '').toLowerCase();
channels[slag] = $(this);
playlist[index] = slag;
channelsNames[slag] = name;
});
playlist.sort();
}
function rewritePlaylist(channels, playlist, channelsNames, search)
{
$('#playlist').html('');
for (var i=0; i<playlist.length; i++) {
$('#playlist').append(channels[playlist[i]]);
}
}
function searchPlaylist(searchString)
{
var re = new RegExp(searchString, "i");
$('#playlist').children().each(function( index, element ) {
var name = $(this).find('strong').first().text();
if (re.test(name)) {
$(this).show();
}
else {
$(this).hide();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment