Goodgy / Enchant monstercat Twitch ( Beta )

// ==UserScript==
// @name         Enchant monstercat Twitch ( Beta )
// @namespace    https://openuserjs.org/users/Goodgy
// @version      0.7
// @updateURL    https://openuserjs.org/meta/Goodgy/Enchant_monstercat_Twitch_(_Beta_).meta.js
// @description  Removes the video from player, and places a now playing in the shortbar
// @author       Goodgy
// @include      https://www.twitch.tv/monstercat
// @include      http://www.twitch.tv/monstercat
// @include      *twitch.tv/monstercat
// @grant        none
// ==/UserScript==

(function() {


    /*
Globals,
keep_player_controls => Indicates if the video still has controls ( Volume / play / pause / options )
remove_cheers        => This removes the "sticky" cheers
hide_player_totally  => Hides all elements of the player
*/
    var keep_player_controls = true;
    var remove_cheers = true;
    var hide_player_totally = false;

    /*
End globals
*/
    /* Global functions */
    /* End Global functions */

    function remove_pinned_cheers(){
        $('div[class="ember-view sticky-message sticky-message--pinned-cheers pinned-cheers showModIcons showTimestamps"]').remove();
        $('div.pinned-cheers').remove();
    }

    function change_nowplaying(){
        var nowplaying = $("span.message:contains('Now Playing')").last().html();
        var newplaying = nowplaying.replace(/ - Listen now: <a href=".*" target="_blank">.*<\/a> Tweet it: <a href=".*" target="_blank">.*<\/a>/g, "");
        var mcat_check = $("span.message:contains('Now Playing')").last().siblings()[2];
        newplaying.replace(/ - Listen now: <a href=".*" target="_blank">.*<\/a>/g, "");
        newplaying.replace(/ - Listen on Spotify: <a href=".*" target="_blank">.*<\/a>/g, "");
        newplaying.replace(/ Tweet it: <a href=".*" target="_blank">.*<\/a>/g, "");
        if(mcat_check.innerText === "Monstercat"){
            $('.js-cn-bar').html('<dd class="cn-tabs__item js-cn-tab-following "><span class="flex flex--verticalCenter flex--nowrap cn-scrollTrigger"><span class="cn-tabs__title" id="current_playing">'+newplaying+'</span></span></dd>');
        }
    }

    function remove_player_clutter(){
        if(keep_player_controls !== true){
            $('video').attr('style','visibility:hidden');
        }else if(keep_player_controls === false){
            $('.player-controls-bottom').attr('style','visibility:hidden');
        }else if(hide_player_totally === true){
            $('video').attr('style','visibility:hidden');
            $('.player-controls-bottom').attr('style','visibility:hidden');
        }else{
            $('video').attr('style','visibility:visible');
            console.log("Nothing to hide");
        }
    }

    function move_subbutton(){
        var src = $('dl[class="cn-tabs cn-tabs--2 js-cn-tabs--2"] dd').eq(1).html();
        $('div.js-share-box').after('<div class="inline-block">'+src+'</div>');
        $('button[class="button button--hollow button--icon cn-bar__button--subscribed balloon-wrapper"]').eq(1).attr('id','subbutton');
        $('#subbutton').attr('class','qa-share-box__button share-box__button button button--hollow mg-l-1');
    }

    function remove_line(){
        $('.chat-container').attr('style','border-left: 0px solid !important;');
        // Remove new layout top bar:
        $('.js-top-nav').remove();
    }


    function do_stuff(){
        // Adds random subhype function to the body of page
        //$('head').append("<script>Array.prototype.random = function() {    return this[Math.floor((Math.random() * this.length))];}function random_subhype() {    var a = '',        r = Math.floor(10 * Math.random()) + 10;    for (i = 0; i < r; i++) a += ' mcatSub mcatHype';    return a;}function random_hype() {  var a = '', r = Math.floor(1 * Math.random()) + 5;  var emotes =[' (ditto) ',' SourPls ','  \\ VisLaud / ',' DraperPls ', ' mcatDance '];  for (i = 0; i < r; i++) a += emotes.random();  return a;}</script>");
        // Remove the header banner
        //$('.cn-cover-wrap').attr('style','display:none!important;');
        $('.cn-cover-wrap').remove();
        // Move the content up to the top
        $('.app-main.has-sc').attr('style','top:0!important;');
        $('.has-sc .cn-bar-fixed').attr('style','top:0!important;');
        //Execute the remaining functions
        remove_line();
        remove_player_clutter();
        change_nowplaying();

        if(remove_cheers === true){
            setInterval(remove_pinned_cheers, 500);
        }
    }

    Array.prototype.random = function() {
        return this[Math.floor((Math.random() * this.length))];
    }

    function random_subhype() {
        var a = '',
            r = Math.floor(10 * Math.random()) + 10;
        for (i = 0; i < r; i++) a += ' mcatSub mcatHype';
        return a;
    }

    function random_hype() {
        var a = '',
            r = Math.floor(1 * Math.random()) + 5;
        var emotes = [' (ditto) ', ' SourPls ', '  \\ VisLaud / ', ' DraperPls ', ' mcatDance '];
        for (i = 0; i < r; i++) a += emotes.random();
        return a;
    }

    function chat_input_check(){
        if(($('.chat_text_input[tabindex="1"]').val().indexOf("~dp") > -1) || ($('.chat_text_input[tabindex="1"]').val().indexOf("~draperpls") > -1) || ($('.chat_text_input[tabindex="1"]').val().indexOf("~DraperPls") > -1)){
            $('textarea[placeholder="Een bericht sturen"]').val("mcatFire DraperPls DraperPls DraperPls DraperPls DraperPls mcatFire ");
        }

        if(($('.chat_text_input[tabindex="1"]').val().indexOf("~subhype") > -1) || ($('.chat_text_input[tabindex="1"]').val().indexOf("~sh") > -1)){
            $('textarea[placeholder="Een bericht sturen"]').val(random_subhype());
        }

        if(($('.chat_text_input[tabindex="1"]').val().indexOf("~hype") > -1) || ($('.chat_text_input[tabindex="1"]').val().indexOf("~h") > -1)){
            $('textarea[placeholder="Een bericht sturen"]').val(random_hype());
        }
    }

    function set_timers(){
        setInterval(change_nowplaying,1500);
        setInterval(chat_input_check,1500);
    }

    setTimeout(do_stuff, 3000);
    setTimeout(set_timers, 1500);
})();