// ==UserScript==
// @name Youtube Center Aligned
// @description Center aligns the Youtube page
// @grant none
// @version 1.5
// ==/UserScript==
// Delay between player width checks. Higher value = checks less frequently. Increase if you have a slow computer.
var monitordelay = 0;
// Centering style for large video player {1, 2}
var largestyle = 1;
// This should work as long as Youtube keeps the "site-center-aligned" class in their CSS
document.body.className = document.body.className.replace('site-left-aligned', 'site-center-aligned');
// Fix for search results (from tezcan34)
// If you apply this to pages other than the search results page, it breaks the script
if (window.location.pathname == ('/results')) {
document.getElementById('page') ? document.getElementById('page').style.width = '1003px' : '';
}
// The guide-container div gets hidden behind videos when the page content is centered because the div is absolute positioned
document.getElementById("guide-container") ? document.getElementById("guide-container").style.left = '-100px' : '';
// Subnav when viewing your own videos
if (document.getElementById('masthead-subnav')) {
document.getElementById('masthead-subnav').setAttribute('style', 'margin:0 auto !important');
document.getElementById("guide-container") ? document.getElementById("guide-container").style.top = '40px' : '';
}
var playerwidth = 0;
function monitorPlayer() {
// Get current player width
var currentwidth = parseInt(window.getComputedStyle(document.getElementById('movie_player')).getPropertyValue('width'));
// Check if player width has changed
if (currentwidth != playerwidth) {
// Set margin based on new width
if (largestyle == 1) {
if (currentwidth <= 945) {
document.getElementById('watch7-video').style.left = '30px';
}
else {
var margin = Math.round((945 - currentwidth) / 2);
document.getElementById('watch7-video').style.left = (margin + 30) + 'px';
}
}
else if (largestyle == 2) {
if (currentwidth <= 640) {
document.getElementById('page').style.left = 0;
}
else {
var margin = Math.round((945 - currentwidth) / 2);
margin > 0 ? document.getElementById('page').style.left = 0 : document.getElementById('page').style.left = margin + 'px';
}
}
// Update playerwidth
playerwidth = currentwidth;
}
setTimeout(function() {
monitorPlayer();
}, monitordelay);
}
monitorPlayer();
Con este código, al menos se consigue centrar youtube. Hay que guardarlo como .js (por ejemplo "centrar youtube.js") y añadirlo a google chrome como extensión.