flipperbw / Twitch Crunch

// ==UserScript==
// @name           Twitch Crunch
// @author		   Flipperbw
// @version        1.1
// @include        /^https?://(www\.|beta\.)?twitch\.tv/
// @grant		   none
// ==/UserScript==

///^https?://(www\.|beta\.)?twitch\.tv\/[a-zA-Z0-9]\w{2,24}/

var cs;

function minimizeit() {
    $('#left_col').hide();

    $('#channel').css('padding', '0px');

    cs = $('.channel-stats').detach();
    cs.css({'margin': '5px 70px 5px 0', 'position': 'relative'});
    $('#broadcast-meta').append(cs);
    $('#broadcast-meta').css({'margin': '0px', 'height': '38px'});
    
    $('.profile-photo img').css({'width': '38px', 'height': '38px'});
    $('.profile-photo .goto').hide();

    $('#channel_panels_contain').hide();
    $('.stats-and-actions').css({'border-bottom': 'none', 'padding': 0, 'height': 0});
    $('.stats-and-actions').hide();

    $('.info').css({'padding-left': '50px', 'padding-right': '300px'});
    $('.info .title').css('line-height', '38px');
    $('.info .channel').css({'line-height': '38px', 'position': 'relative', 'display': 'inline-block'});

    $('span.over').hide();
    
    $('#main_col').css({'margin-left': '0px'});

    $('#player').resize();
    
    return;
}

function resetit() {
    $('#main_col').attr('style', '');
    $('#channel').attr('style', '');
    $('.channel-stats').attr('style', '');
    $('#broadcast-meta').attr('style', '');
    $('.profile-photo img').attr('style', '');
    $('.info').attr('style', '');
    $('.info .title').attr('style', '');
    $('.info .channel').attr('style', '');
    $('.stats-and-actions').attr('style', '');
    
    $('#left_col').show();
    $('.stats-and-actions').show();
    $('.stats-and-actions').append(cs);
    $('#channel_panels_contain').show();
    $('span.over').show();
    
    $('#player').resize();
    
    return;
}

function addExpando() {
    if (($('#expando').length === 0) && ($('#right_close').length > 0)) {
        $('#right_close').before('<div id="expando" class="openo">&lt;&gt;</div>');
        $('#expando').css({'right': '33px', 'position': 'absolute', 'font-size': '18px', 'z-index': '10'});

        $('#expando').click(function(event) {
            event.preventDefault();
            if ($('#expando').hasClass('openo')) {
                $('#expando').html('&gt;&lt;').attr('class', 'closedo');
                return minimizeit();
            }
            else {
                $('#expando').html('&lt;&gt;').attr('class', 'openo');
                return resetit();
            }
        });
    }
}

var observ_id = 'main_col';
var target_observe = document.querySelector('#' + observ_id);

var observerConfig = {
    childList: true,
    characterData: false,
    subtree: true
};

var observer = new MutationObserver(function (mutations) {
    if (mutations.length > 0) {
        addExpando();
    }
});

if (target_observe) {
    observer.observe(target_observe, observerConfig);
}