www.xvideos.com

UI-Redesigned, keyboard change to different design, full browser player

2014-12-08 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

//// ==UserScript==
// @name		www.xvideos.com
// @namespace		http://use.i.E.your.homepage/
// @version		0.2
// @description         UI-Redesigned, keyboard change to different design, full browser player

// @match		http://www.xvideos.com/*
// @require		http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

// @grant           	GM_getValue
// @grant           	GM_setValue
// @grant           	GM_deleteValue

// @created		2014-10-16
// @released		2014-00-00
// @updated		2014-00-00
// @history         	@version 0.1 - first version: @released - 2014-10-18
// @history         	@version 0.2 - sec version: @updated - 2014-12-06

// @compatible		Greasemonkey, Tampermonkey
// @license         	GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html) 
// @copyright		2014+, Magnus Fohlström
// ==/UserScript==


/*global $, jQuery*/
/*jshint -W014*/
// -W014, laxbreak, Bad line breaking before '+'


//-------------------------------------------------------------------------------------
String.prototype.formatString = function(){
    return this.toString()
                .split(/\s+/g).join(' ')
                .split('{').join('{\n\t')
                .split('; ').join(';')
                .split(';').join(';\n\t')
                .split('*/').join('*/\n')
                .split('}').join('}\n');
};

function l(name,fn){ console.log( name, fn !== undefined ? fn : '' ); }
//-------------------------------------------------------------------------------------

$( '<style id="CssBasic"></style><style id="InsertCssVideo"></style><style id="fullplayer"></style>' ).appendTo('head');

function InsertCssBasic()
{
    var loc = window.location.href,
        ok, CssBasic,thumbBlock_height,thumbBlock_img_width;
    
    ok = ( (loc === 'http://www.xvideos.com/') || (loc.search('/tags/') > 0) || (loc.search('/best/') > 0) ) ? 'y':'n';
    thumbBlock_height = ok == 'y' ? 280:240,
    thumbBlock_img_width = ok == 'y' ? 1.6:1.3;
    
    CssBasic = 
        '#page {'
    +		'width: 1200px;'
    +		'}'
    +	'#player {'
    +		'width: calc(100% - 0px) !important;'
    +		'}'
    
    +	'.thumbBlock .thumb img {'
    +		'width: calc(180px * ' + thumbBlock_img_width + ');'
    +		'}'
    +	'.thumbBlock {'
    +		' height: ' + thumbBlock_height + 'px;'
    +		'}'
    +	'.thumbBlock .thumbInside p a {'
    +		'height: 32px;'
    +		'display: inline-block;'
    +		'}'
    +	'#relatedVideosWithMore {'
    +		'height: calc(390px * 1.25);'
    +		'}'
    
    +	'.profilesGalleries.videoThumbs .thumb, .profilesGalleries.videoThumbs .vcenter {'
    +		'height: initial;'
    +		'}'
    
    +	'#mv_min_title:hover{'
    +		'cursor: pointer;'
    +		'color: white;'
    +		'}';
 
    $( '#CssBasic' ).html( CssBasic.formatString() );
}

function playerAPI()
{
    var preDetWidth = $('#page').width(),
 	 	thisHeight = 486 * ( preDetWidth / 588 ),
        InsertCssVideo = '#player, embed { width: '+preDetWidth+'px !important; height:'+ thisHeight +'px !important; }';
    
    $( '#InsertCssVideo' ).empty().html( InsertCssVideo.formatString() );
}

InsertCssBasic();
playerAPI();

function fullplayer()
{
    var fullplayer =
		'header, h2, ul#video-tags, ul.tags_list, #videoTabs, '
    +	'#relatedVideosWithMore, #relatedVideosMoreLink, footer {'
    +		'display: none;'
    +		'}'
    +	'html, body {'
    +		'overflow: hidden;'
    +		'}'
    +	'#page {'
    +		'width: calc(100% - 30px);'
    +		'}';
    
    $( '#fullplayer' ).empty().html( fullplayer.formatString() );
}

$( window ).resize(function()
{
    if( $('html').hasClass('fullplayer') )
    {
        playerAPI();
    }
});

document.addEventListener('keydown', function(e) {
    
    if (e.keyCode == 27) { //esc
        if( $('html').hasClass('fullplayer') === false ) return false;
        $('html').removeClass('fullplayer');
        $("style#fullplayer").empty();
        
        playerAPI();
    }
    else if (e.keyCode == 66) { //b
        if( $('html').hasClass('fullplayer') ) return false;
        $('html').addClass('fullplayer');
        
        fullplayer();
        setTimeout( playerAPI, 75);
    }
    else if (e.keyCode == 78) { //n
        InsertCssBasic();
		playerAPI();
    }
    else if (e.keyCode == 79) { //O
        $('html').removeClass('fullplayer');
        $("style#fullplayer, style#CssBasic, style#InsertCssVideo").empty();
    }
}, false);