PrincePolka / webchat sidebar notifier beta

// ==UserScript==
// @name         webchat sidebar notifier beta
// @version      0.1
// @author       PrincePolka
// @description  enter something useful
// @downloadURL https://openuserjs.org/src/scripts/PrincePolka/webchat_sidebar_notifier_beta.user.js
// @include     http://rocketwerkz.com/*
// @include     http://www.twitch.tv/*/chat*
// @include     http://www.cartoonnetwork.com/games/adventuretime/adventure-time-battle-party/
// @include     http://webchat.esper.net/*
// @include     http://www.this-page-intentionally-left-blank.org/*
// @grant        none
// ==/UserScript==
console.log('you can raise a sign by tying it to a helium-filled balloon whose string gets cut by a pair of scissors that gets him by a bowling ball rolling down a ramp ;) - Wes');
var ischrome;
if(window.chrome){ischrome = true}
else{ischrome = false}
if(document.readyState === "complete"){onload();}
else{window.onload = function(){onload();};}
function onload(){
    var hid = false;
    function createCookie(name,value,days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            expires = "; expires="+date.toGMTString();
        }
        else document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

    function eraseCookie(name) {
        createCookie(name,"",-1);
    }
    function escapeHtml(str) {
        var div = document.createElement('div');
        div.appendChild(document.createTextNode(str));
        return div.innerHTML;
    }
    function hash(key){
        var h    = location.hash.substr(1);
        return h.substr(h.indexOf(key+'=')).split('&')[0].split('=')[1];
    }
    function sethash(key,value){
        var h = location.hash.substr(1),
            l =(h.substr(h.indexOf(key+'=')).split('&')[0].split('=')[1]).length,
            s = h.search(key)+key.length+1;
        location.hash=h.slice(0,s)+value+h.slice(s+l);
    }

    var css = function(foo) {
        if(foo==="reset"){this.style.cssText = this.originalcss; return true;}
        else if(foo){this.style.cssText+=";"+foo; return true;}
        else{return this.style.cssText;}
    };
    function whitelist(node,tag,list){
        node = node.getElementsByTagName(tag);
        for(var child in node){
            if(node[child].hasAttribute)
                atributesWhitelist(node[child],list);
        }
    }
    function atributesWhitelist(node,whitelist) {
        var attributes = node.attributes;
        var i = attributes.length;
        while( i-- ) {
            var attr = attributes[i];
            if( whitelist.indexOf(attr.name ) === -1)
            {node.removeAttributeNode(attr);}
        }
    }
    var $={load:function(){
        var allElements = document.getElementsByTagName("*");
        for (var key in allElements){
            var el = allElements[key];
            if (el.id) {
                $[el.id] = el;
                $[el.id].originalcss = el.style.cssText;
                $[el.id].css =css;
            }
        }
    }
          };

    var site = {twitch:"http://www.twitch.tv/*/chat*", cartoonnetwork:"http://www.cartoonnetwork.com/games/adventuretime/adventure-time-battle-party/", esper:"http://webchat.esper.net/*"};
    var origin ={};
    var blankpage = {chromeblank:"http://www.this-page-intentionally-left-blank.org/", chromeblank2:"http://rocketwerkz.com/"};
    for(var key in site) {
        origin[key] = new RegExp (site[key].replace(/(\W)/g,'\\$1').replace(/\\\*/g,'.*'));
        site[key] = new RegExp (site[key].replace(/(\W)/g,'\\$1').replace(/\\\*/g,'.*')).test(window.location.href);
    }
    site.blankpage = (function(){for(var key in blankpage) {if(blankpage[key] === location.protocol+'//'+location.host+location.pathname) {return blankpage[key];}}return false;})();
    console.log(site.blankpage);

    if(site.blankpage)(function(){
        var snd = new Audio("data:audio/wav;base64,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qJrx4KOQjahZxWbcZgztj2c49nKmkId44S71j0c8eV9yDK6uPRzx5X18eDvjvQ6yKo9ZSS6l//8elePK/Lf//IInrOF/FvDoADYAGBMGb7FtErm5MXMlmPAJQVgWta7Zx2go+8xJ0UiCb8LHHdftWyLJE0QIAIsI+UbXu67dZMjmgDGCGl1H+vpF4NSDckSIkk7Vd+sxEhBQMRU8j/12UIRhzSaUdQ+rQU5kGeFxm+hb1oh6pWWmv3uvmReDl0UnvtapVaIzo1jZbf/pD6ElLqSX+rUmOQNpJFa/r+sa4e/pBlAABoAAAAA3CUgShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=");
        var muted = false;
        function beep() {if(!muted)snd.play();}
        console.log("blank");
        var chromehtml ='';
        //if(ischrome){chromehtml='<div class="switch" id="fullscreen">fullscreen</div>';}

        var gamewidth = Math.ceil(window.innerHeight*1.6);
        var sidebarwidth = window.innerWidth-gamewidth;

        var HTML ='<div id="wrapper"><div id="hider">»</div><nav id="nav"><div id="tNav">Twitch</div><div id="wNav">Webchat</div><div id="settings">settings</div></nav>'+
            '<nav id="set"><div id="beep">beep</div><div class="switch"><div id="tscbutton" class="refresh"></div><input id="tscinput" type="text"/><div class="ticon"></div></div><div class="switch"><div id="wscbutton" class="refresh"></div><input id="wscinput" type="text"/><div class="wicon"></div></div>'+
            chromehtml+
            '<div class="switch" id="reloadatbp">Reload ATBP, it cabbaged!</div>'+
            '</nav></div><div id="div"><span id="popup">sdfsdf</span></div>';
        var CSS ='body{font:14px "Helvetica Neue",Helvetica,Arial,sans-serif;}'+
            '#wrapper{cursor:default;-moz-user-select:none;-webkit-user-select:none;z-index:10;position:fixed;right:0;top:0;font-size:14px;height:100%;width:'+sidebarwidth+'px;}'+
            '#wNav,#tNav,.wicon,.ticon,.refresh,.icon{height:20px;width:20px;background:transparent no-repeat 2px 2px;}'+
            'ul{list-style-type: none;}'+
            '#hider{z-index:100;display:block;color:#333;font-size:16px;box-shadow: inset -20px 0px 20px -20px rgba(0,0,0,0.5);line-height:40px;text-align:center;width:20px;height:40px;background:#ddd;position:absolute;top:calc(50% - 20px);left:-20px;z-index:100;}'+
            '#nav{font-size:10px;line-height:20px;display:block;}'+
            '#nav div{float:left;width:calc(33% - 22px);padding: 0 2px 0 20px;text-align: center;}'+
            '#wView{color:#eee;background:#051530;}'+
            '#tView{color:#333;background:#eee;}'+
            '#wView{display: none;}'+
            '#tMessages,#wMessages{height:calc(100% - 180px);overflow-y:scroll;overflow-wrap:break-word;}'+
            'header{display: inline-block;width: 100%;height: 50px;}'+
            'header p{line-height: 50px;text-align: center;}'+
            'footer{padding: 20px;width: calc(100% - 40px);height:50px;}'+
            'textarea{padding: 7px;width:100%;}'+
            '#settings{background:#aaa url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAABjElEQVQoU11PMUtCYRS9+lKf2pAiT3kpgjSkxBOVorBC1BYFEcHKoSgHKUJwVWprLyQoElqEpmbBIRIiaHlLCf4EcXPzbaebviL6Lnyce86557sf0Z8T7qSRRrhD/4+nFlFdeaLk8AlPSA6JXAcR1VP7lYu4Rwnhbg6PXDmEX0vMFKFbFPUaD2jjHC00uVqM2sxcQVGnBmc+gwYuWLrDDW75bnJXRwbOvP5IqLuPKi5xgtRkRztlVMUeQt2puNRZHSZQwRmOEHgWREEMPB9xV0ECq8OlDsWwj0OkUMbmRBC/RwRxe3LMzCErMZCCIPzw8c5b2o8hru0y42dFAfm6wVEIEjbYIveMolGUe0XuJIQQHPlme3hf/FjgwAKiWlQrMFrgee+7/gdbcQXLIDiRxTGvmmVEzKzAVp4apP4arDBx6DzMLNkZmZhZg9SfJdRljpThUmUYuRi9zRhbXX/E2nAMLBUi99gMC9xjEiwlx8Da0GUSDHZhcW7ZvO74kDje8WmOmyJCwOg0iGT4AupS2afl6WKQAAAAAElFTkSuQmCC) no-repeat 2px 2px;}'+
            'Iframe,#set{position:absolute;top:20px;right:0;width:'+sidebarwidth+'px;height:calc(100% - 20px);border:none;}'+
            '#set{background:#aaa;overflow:hidden;font-size:10px;line-height:22px;}'+
            '#div{pointer-events:none;width:'+gamewidth+'px;height:100%;z-index:2;position:fixed;top:0;left:0;background:transparent;text-align:center;}'+
            '#popup{background:#fff;padding:20px;border-radius:2px;box-shadow:inset 0 0 2px #6441a5;visibility:hidden;font-size:12px;}'+
            '#beep{padding:0 2px 0 20px; width:calc(100% - 22px);background:transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAt1BMVEUAAAAJCQn///9CQkIeHh4mJiYbGxtMTEwAAAAAAAAgICAAAAA6Ojo/Pz8JCQkNDQ0WFhYZGRkbGxsfHx8gICAkJCQnJycpKSkxMTE1NTU6Ojo/Pz9AQEBBQUFCQkJERERFRUVGRkZHR0dKSkpLS0tMTExOTk5QUFBRUVFTU1NVVVVXV1dcXFxhYWFlZWVmZmZoaGdra2ttbW1vb29zc3N3d3d7e3t9fX1+fn6AgICCgoKDg4OOjo7R37o0AAAADnRSTlMAAAAPU4qmpszU3uLl5VXK+TgAAACJSURBVBgZBcFJTsNAEADA6lmQshyCcuHm///OAkQcz0ZVJGDKNR1IALluV0iAXLc7KEDU7blAQbpFfTxaBgXPe3ytQ6iNhHWd7af36RMJ49LbHGOAgnnut79wc6JgvMUQwy8S7Pq+VteRg7Ha9zovcb6Qg3m2vsr7o7+QEME45gAFJNZhQSQAwD8xMz1v1XTpnwAAAABJRU5ErkJggg==) no-repeat 2px 2px;;}'+
            '.switch{clear:right;background:rgba(255,255,255,.5);; margin:2px 0; height: 24px;}'+
            '.switch div,.switch input{float: right; overflow:hidden; margin:2px 0;}'+
            '.switch input{height:20px;width:calc(100% - 40px);background:rgba(255,255,255,.5);border:none;}'+
            '.switch .refresh{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAdVBMVEVmZmb///9mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmYdeygzAAAAJnRSTlMAAAIICgwOEBQcHiAoKkxWaGpscnWEhYqTmZ2fs7vF29/r8/n7/R628k8AAACMSURBVHgBXc5JgoIwFEXRmwhqjE1pqpQ+NNTb/xIdBBhwhu//wcXsYAA4+uslY3N6dpPG9nEgOdfqi1ANei9PuUoH9tboBVgERwBcjB74l1iE+Q7SuuQU+sDvR38/ObDd7nMA1gXwMboUB8ICLzU3C64USfbWUIWiV30mOTzaUVP3PLHJLlef4gxm5wt6owpN+5+svAAAAABJRU5ErkJggg==);}'+
            '#wNav,.wicon{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABj1BMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhsAIVUAI0wBAQEEJ0sGRoUJJk4KDw0LH0cMRX8QOmUSOF0TM1kTSHcVFRUcN1AdHxgfN04gRmQhSHIoZKYpKSkpLCQpU3ErLSEsJgssVH8saa0tLS0tMDEwNisxQUEzbq80NDQ2Zo44MxM5Z5w6Ojo6apc7XX8+X3FAQEBAUVZAb51CQ0ZCaJBEZ45GdKRIbZNKWUBLcplLfKBMSyJMX3dNTU1PanZPdZNRf6tTfJlVeJdVjshajLRcXFxcjcVdXV1kZGRnnMRqhHptkatubm5uj7JwcGFwjqtxhahxhatzjK5zocZ1kbl2dnZ3lLx4kLN5mMF7e3t9fX1+fn5+i2aAkJmEhISEoLSHh4eImnaKioqLi4uOjo6PnoaQoIqRs8yStdyVqLSYsLSYueCampqeweulpaWpqamqqqqrq6u6yL2+vr7FxcXLy8vQ0NDS0tLY2Nje3t7g4ODl5eXt7e292r34AAAADnRSTlMAFCBug4eZt8PJ4+Xn/dR3NAoAAADRSURBVHgBY8AETOx8cMDOBBTgsI5IiCsuiCqNj4l04QQK8OqIaonIOBkGSijr+/ECBfiMpU3d9Bwyg8S9or35QAIhSSZJSSFGziZJ/iZggYp615aKmhzXpsqWZLBAYrlqE1CgMkfX1QAsEFum3phd51uSJZYRCxaobg5oTgtotqhtaNAGC8iqWKrIaqiEyavISoEFQsPzzXNThPKqgq0EQAK8mul2Hu5q/IpFhT5mIAFuBXsbRyVJQWHPVFs5HqAACxfCc1ysQAFGZjY4YGZkAAC+Sy2yabIhbwAAAABJRU5ErkJggg==)}'+
            '#tNav,.ticon{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAFVBMVEX///9kQaVkQaVkQaVkQaVkQaVkQaUu2tx7AAAABnRSTlMAJE5cZHwcqOU7AAAAOklEQVR42p2OOwoAMAjF0u/9j1wcntoOLTSIkCwKzA1oZ7DlXEKfNj/heWUohBdID5oryD2Eo1hJJF/BVAMMJI0pSQAAAABJRU5ErkJggg==)}'+
            '#wNav{color:#fff;background-color:#1a1a1a;}'+
            '#tNav{color:#63a;background-color:#f2f2f2;}'+
            '';
        //#1a1a1a 
        //'#tFrame{position:fixed;top:0;left:0;width:300px;height:400px;}'+
        //'#wFrame{position:fixed;top:0;left:300px;width:300px;height:400px;}'

        //$.popup.parentNode.removeChild($.popup);

        document.getElementsByTagName("html")[0].innerHTML='<head><style>'+ CSS +'</style></head><body>'+HTML+'</body>';
        $.load();
        //this.css("lineheight:"+this.parentNode.clientHeight+"px;");
        if(ischrome){
            $.popup.remove();
            $.hider.remove();
        }
        else{
            $.popup.centerY=function(){this.css("line-height:"+this.parentNode.clientHeight+"px;");};
            $.popup.centerY();
            window.onresize = function() {$.popup.centerY();};
            $.hider.onclick=hide;
        }

        function resize(n){
            if(n>=200 || n<=500){
                sidebarwidth = n;
                gamewidth = window.innerWidth-sidebarwidth;
            } else {
                gamewidth = Math.ceil(window.innerHeight*1.6);
                sidebarwidth = window.innerWidth-gamewidth;
            }
            $.set.css('width:'+sidebarwidth+'px');
            $.wrapper.css('width:'+sidebarwidth+'px');
            tFrame.css('width:'+sidebarwidth+'px');
            wFrame.css('width:'+sidebarwidth+'px');
            $.div.css('width:'+gamewidth+'px');
            cFrame.css('width:'+gamewidth+'px');
        }
        window.addEventListener("resize",resize,true);


        var cookie ={twitchname:{val:"twitchname",or:"blackle13"},
                     nick:{val:"nick",or:''},
                     channel:{val:"channel",or:'atbp'},
                     load:function(){
                         var val, or, newhash='';
                         for(var key in cookie){
                             if(key!=='load'){
                                 val=cookie[key].val;
                                 or=cookie[key].or;
                                 val = hash(val) || readCookie(val) || or;
                                 newhash+=key+'='+val+'&';
                                 cookie[key] = val;
                                 if(val !== or || val !== readCookie(key)){createCookie(key,val);}
                             }
                         }
                         location.hash = newhash.slice(0,-1);
                     }};cookie.load(); delete cookie.load;

        function putFrameIn(site,node){
            var frame = document.createElement("IFRAME");
            if(site !== 'local'){
                frame.origin = site.match(/^(https?:\/\/)?(w?w?w?\.)?([^\/]+)/g)[0];
                frame.src = site;
                //frame.setAttribute("allowtransparecy","true");
                frame.msg=function(message){this.contentWindow.postMessage(message,this.origin);};
                frame.onload=function(){this.msg("ping");};
            }
            frame.css = css;
            node.appendChild(frame);
            return frame;
        }

        var tFrame = 'http://www.twitch.tv/'+cookie.twitchname+'/chat?popout=';
        var wFrame = 'http://webchat.esper.net/?nick='+cookie.nick+'&channels='+cookie.channel;
        var cFrame = 'http://www.cartoonnetwork.com/games/adventuretime/adventure-time-battle-party/';
        tFrame = putFrameIn(tFrame,$.wrapper);
        wFrame = putFrameIn(wFrame,$.wrapper);
        cFrame = putFrameIn(cFrame,document.body);
        cFrame.css('position:absolute;top:0;left:0;width:'+gamewidth+'px;height:100%;border:none;z-index:1;');
        /*var poop ="";
        function lala(){
            poop = putFrameIn('local',document.body);
            poop.css('width:59px;height:58px;display:block;position:fixed;top:300px;left:300px;z-index:1000;filter:none;opacity:1;background:black;');
            //poop.css('overflow:hidden;position:absolute;top:300px;left:700px;width:400px;height:100px;border:none;z-index:2147483647;background:#fff;');
            poop.contentWindow.document.head.innerHTML = '<style>body{overflow:hidden;z-index:10;}</style>';
            poop.contentWindow.document.body.innerHTML = '<h1>Injected from parent frame</h1>';
        }*/

        $.tNav.onclick=function1;
        $.wNav.onclick=function2;
        $.tscbutton.onclick=reloadTwitchChannel;
        $.wscbutton.onclick=reloadIrcChannel;
        $.settings.onclick=function3;
        $.beep.onclick=mute;
        $.reloadatbp.onclick=reloadatbp;
        

        /*function chromefullscreen(){
            if(window.outerHeight === window.innerHeight){document.webkitExitFullscreen();}
            else{document.body.webkitRequestFullscreen();}
        }*/
        function reloadatbp() {
            cFrame.remove();
            cFrame = 'http://www.cartoonnetwork.com/games/adventuretime/adventure-time-battle-party/';
            cFrame = putFrameIn(cFrame,document.body);
            cFrame.css('position:absolute;top:0;left:0;width:'+gamewidth+'px;height:100%;border:none;z-index:1;');
        }

        function reloadTwitchChannel() {
            tFrame.remove();
            cookie.twitchname=$.tscinput.value;
            createCookie("twitchname",cookie.twitchname);
            sethash("twitchname",cookie.twitchname);
            tFrame = 'http://www.twitch.tv/'+cookie.twitchname+'/chat?popout=';
            tFrame = putFrameIn(tFrame,$.wrapper);
        }
        function reloadIrcChannel() {
            wFrame.remove();
            cookie.channel=$.wscinput.value;
            createCookie("channel",cookie.channel);
            sethash("channel",cookie.channel);
            wFrame = 'http://webchat.esper.net/?nick='+cookie.nick+'&channels='+cookie.channel;
            wFrame = putFrameIn(wFrame,$.wrapper);
        }
        function function1() {
            tFrame.css('display:inline-block');
            wFrame.css('display:none');
            if(ischrome){cFrame.msg('hidercss=color:#333;background:#f2f2f2');}
            else{$.hider.css('color:#333;background:#f2f2f2');}
        }
        function function2() {
            tFrame.css('display:none');
            wFrame.css('display:inline-block');
            if(ischrome){cFrame.msg('hidercss=color:#fff;background:#1a1a1a');}
            else{$.hider.css('color:#fff;background:#1a1a1a');}
        }
        function function3() {
            tFrame.css('display:none');
            wFrame.css('display:none');
            if(ischrome){cFrame.msg('hidercss=color:#222;background:#aaa');}
            else{$.hider.css('color:#222;background:#aaa');}
        }

        function hide() {
            if(!hid){
                if(!ischrome){$.hider.textContent = "«";}
                $.wrapper.css('right:-'+sidebarwidth+'px');
                $.div.css('width:100%');
                cFrame.css('width:100%');
                hid = true;
            }
            else{
                $.wrapper.css('right:0');
                if(!ischrome){$.hider.textContent = "»";}
                $.div.css('width:'+gamewidth+'px');
                cFrame.css('width:'+gamewidth+'px');
                hid = false;
            }

        }

        function mute() {
            if(!muted){
                $.beep.css('background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAA7VBMVEUAAAAAAQEBAQADAwQEBAQFBAQFBQUICAgJCQkJCgkNDQ0ODg4SEhMTExT///9CQkIAAAAeHh4mJiZMTEwAAAAAAAAAAAAgICAAAAA6Ojo/Pz8BAgICAgIGBQUGBgYKCgoAAAABAQEFBQUJCQkNDQ0ODg4TExMZGRkbGxsfHx8gICAnJycpKSkxMTE1NTU6Ojo/Pz9AQEBBQUFCQkJERERFRUVGRkZHR0dKSkpLS0tOTk5QUFBTU1NVVVVcXFxhYWFoaGdtbW1vb29zc3N3d3d7e3t9fX1+fn6AgICCgoLq6urr6+vs7Ozz8/P////JHAKeAAAAIHRSTlMAAAAAAAAAAAAAAAAAAAAPLFOKpszU297i5eXo6Ojo6E/mLfQAAACuSURBVBjTXc/ZAkJAAIXhadeGCqWNTKhppVW078m8/+NETBf9d+e7O4BmpWKeSsUYrkoHAVpy21TS3zaKoNB6NYG/TwRymYYnc/bzQSBT6nY85Xa5E0gM15biwtMVVUKID/arG3yrZzQKId2/zo47FWsEsvoBOvOFhvVeCDR04NYwTBnLIIIx3IhTw5KxAL5QhjzPi+YSCVj4QhBTq5sIBBKBLxMEgMD+wBfy9q8Pd3sbwC++hb8AAAAASUVORK5CYIIggg==)');
                $.beep.textContent = "muted";
                muted = true;
            }
            else{
                $.beep.css('background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAt1BMVEUAAAAJCQn///9CQkIeHh4mJiYbGxtMTEwAAAAAAAAgICAAAAA6Ojo/Pz8JCQkNDQ0WFhYZGRkbGxsfHx8gICAkJCQnJycpKSkxMTE1NTU6Ojo/Pz9AQEBBQUFCQkJERERFRUVGRkZHR0dKSkpLS0tMTExOTk5QUFBRUVFTU1NVVVVXV1dcXFxhYWFlZWVmZmZoaGdra2ttbW1vb29zc3N3d3d7e3t9fX1+fn6AgICCgoKDg4OOjo7R37o0AAAADnRSTlMAAAAPU4qmpszU3uLl5VXK+TgAAACJSURBVBgZBcFJTsNAEADA6lmQshyCcuHm///OAkQcz0ZVJGDKNR1IALluV0iAXLc7KEDU7blAQbpFfTxaBgXPe3ytQ6iNhHWd7af36RMJ49LbHGOAgnnut79wc6JgvMUQwy8S7Pq+VteRg7Ha9zovcb6Qg3m2vsr7o7+QEME45gAFJNZhQSQAwD8xMz1v1XTpnwAAAABJRU5ErkJggg==)');
                $.beep.textContent = "beep";
                muted = false;
                beep();
            }

        }


        var timer = "";
        function showandhide(){$.popup.css("visibility:visible");clearTimeout(timer);timer=setTimeout(function(){$.popup.css("visibility:hidden");},3000);}

        window.addEventListener("message", receiveMessage, false);
        function receiveMessage(event){
            if(event.origin === tFrame.origin)
            {
                if(event.data === "pong"){tFrame.msg("time for tinkering!");}
                else if (event.data.substring(0,1)==="<"){
                    beep();
                    if(ischrome){cFrame.msg("you have a popupeee"+event.data);}
                    else{
                        $.popup.css('background:#eee;color:#333;');
                        $.popup.innerHTML=(event.data);
                        showandhide();
                    }
                }
                else{/*var pass_data = JSON.parse(event.data);*/}
            }
            else if (event.origin === wFrame.origin)
            {
                if(event.data === "pong"){wFrame.msg("time for tinkering!");}
                else {
                    beep();
                    if(ischrome){cFrame.msg("you have a popup333"+event.data);}
                    else {
                        $.popup.css('background:#333;color:#eee;');
                        $.popup.innerHTML=(event.data);
                        showandhide();
                    }
                }
            }
            else if (event.origin === cFrame.origin)
            {
                if(event.data === "pong"){cFrame.msg("time for tinkering!");}
                else if(event.data === "hide"){hide();}
            }
        }

    })();

    if(!site.blankpage)(function(){
        var blank ={handle:"", src:"http://rocketwerkz.com",msg:function(message){this.handle.postMessage(message,this.src);}};
        window.addEventListener("message", ping, false);
        function ping(event)
        {
            if (event.origin === blank.src)
            {
                if (event.data === "ping"){
                    blank.handle = event.source;
                    blank.msg("pong");
                }
                else if (event.data === "time for tinkering!"){
                    tinkering();
                }
            }
        }

        function tinkering(){
            window.removeEventListener("message", ping, false);
            if(site.twitch)(function(){
                $.load();
                var _={html:"html",body:"html",head:"head"};
                (function(){for(var key in _){
                    var el = document.getElementsByTagName(_[key])[0];
                    _[key]= el;
                    _[key].originalcss = el.style.cssText;
                    _[key].css =css;
                }})();
                var newcss = '<style type="text/css">'+
                    '#noty_bottomCenter_layout_container,.noty_bar{display:none;}.roomMode{margin:0;}.chat-header{width:calc(100% - 50px);}.tse-scroll-content{padding:0 70px 0 20px;}.ember-chat .chat-interface{width:calc(100% - 50px);}'+
                    '</style>';
                document.head.innerHTML+=newcss;
                var myVar=setInterval(function () {myTimer();},1000);
                var lastText = "";
                var currentText = "";
                var popup = document.createElement('div');
                //_.body.appendChild(popup);
                var oDiv = "";
                var lastLength = 0;
                var currentLength = 0;
                var lastmessager ="";

                function myTimer() {
                    var chatlines = document.getElementsByClassName("ember-view chat-line");
                    currentLength = chatlines.length-1;
                    oDiv = chatlines[currentLength-1] || '';

                    if(oDiv.innerHTML){firstText = oDiv.innerHTML;}
                    if (lastLength != currentLength){
                        while(lastLength < currentLength)
                        {hur(chatlines[++lastLength]);}
                    }
                    function hur(odi) {
                        popup.innerHTML="";
                        if(odi.cloneNode){popup.appendChild(odi.cloneNode(true));}
                        var li = popup.childNodes[0];
                        li.style.cssText = "list-style:none;";
                        var message = "";
                        for (var i = li.childNodes.length - 1; i >= 0; i--){
                            var node = li.childNodes[i];
                            var classname = node.className;
                            if(["from","message"].indexOf(classname) === -1)
                            {
                                node.remove();
                            }
                            else if (classname==="message")
                            {
                                message = node;
                                whitelist(node,"img",["src"]);
                                whitelist(node,"a",["href"]);
                            }


                            else if (classname==="from")
                            {
                                if(node.textContent+": " === lastmessager)
                                {
                                    node.remove();
                                }
                                else
                                {
                                    node.textContent+=": ";
                                    lastmessager=node.textContent;
                                }
                            }
                        }
                        //whitelist(popup,"img",["src"]);
                        //whitelist(popup,"a",["href"]);
                        odi.innerHTML = li.innerHTML;
                        var pass_data = {
                            'from':'Chris',
                            'color':54,
                            'message':'do_logout'
                        };
                        //blank.msg(JSON.stringify(pass_data));
                        blank.msg(li.innerHTML);  
                    }
                }
            })();

            if(site.cartoonnetwork)(function(){

                //var initialCSS = {displayBlock:"", unityPlayer:"", embed:""};
                var unityLoadCheck = setInterval(initialize, 5000);
                function initialize() {
                    if(document.getElementById('unityPlayer').childNodes[0].type === "application/vnd.unity"){
                        document.getElementById('unityPlayer').childNodes[0].id='embededunity';
                        $.load();
                        filloutscreen();
                        clearInterval(unityLoadCheck);
                    }
                }

                function filloutscreen() {
                    //btn.style["background-image"] = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAApCAMAAACfvvDEAAAAG1BMVEWqqqrOzs7x8fHy8vL09PT5+fn9/f3+/v7///87ZNXeAAAATUlEQVR4Ae3KKw7AMAwE0ek/9z9xga2iRJqAEiuPLNhhs2jWV0L/p3RJGpRhspRKlat8LJrFbXFZnBa7xWH9VJL6f5osw7CMrVlavnwBfm8kCSZdxgsAAAAASUVORK5CYII='";
                    for(var key in $){if(key!=='load' && key!=='pappa' && key!=='hider' && $[key].css){
                        $[key].css('visibility:hidden');}}
                    $.displayBlock.css('visibility:visible;position:fixed;top:0;left:0;height:100%;width:100%;');
                    $.unityPlayer.css('visibility:visible;height:100%;width:100%;');
                    $.embededunity.css('visibility:visible;height:100%;width:100%;');
                    $.gameContainer.css('overflow:hidden;');
                    $.embededunity.height="100%";
                    $.embededunity.width="100%";
                }
                function resetscreen(){for(var key in $){if(key!=='load' && key!=='pappa' && key!=='hider' && $[key].css){
                    $[key].css('reset');}}}
                setTimeout(hejja, 7000);
                function hejja(){
                    console.log("hejja");
                    //document.body.innerHTML='<div style="z-index:1;background:#555;position:fixed;top:0;left:0;width:100%;height:100%;"><embed src="http://ht.cdn.turner.com/toon/big/champions/20150413/CNChampions.unity3d" type="application/vnd.unity" width="100%" height="100%" disablecontextmenu="true" backgroundcolor="021E2F" bordercolor="DF2900" textcolor="DF2900" logoimage="logoimage.png" progressbarimage="progressbarimage.png" progressframeimage="progressframeimage.png" pluginspage="http://unity3d.com/unitywebplayer.html" style="display:block;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2;"></div>';
                    //document.getElementById('displayBlock').outerHTML='<div id="displayBlock" style="background: #000;position:relative; width: 960px; height: 600px; z-index:1;display:block; margin: 0 auto; text-align:center;"><div id="unityPlayer" style="margin: 0 auto; text-align: center;"><embed src="http://ht.cdn.turner.com/toon/big/champions/20150413/CNChampions.unity3d" type="application/vnd.unity" width="960" height="600" firstframecallback="UnityObject2.instances[0].firstFrameCallback();" disablecontextmenu="true" backgroundcolor="021E2F" bordercolor="DF2900" textcolor="DF2900" logoimage="logoimage.png" progressbarimage="progressbarimage.png" progressframeimage="progressframeimage.png" pluginspage="http://unity3d.com/unitywebplayer.html" style="display: block; width: 960px; height: 600px;"></div></div>';

                    //$.unityPlayer.innerHTML+='<embed src="http://ht.cdn.turner.com/toon/big/champions/20150413/CNChampions.unity3d" type="application/vnd.unity" width="100%" height="100%" disablecontextmenu="true" backgroundcolor="021E2F" bordercolor="DF2900" textcolor="DF2900" logoimage="logoimage.png" progressbarimage="progressbarimage.png" progressframeimage="progressframeimage.png" pluginspage="http://unity3d.com/unitywebplayer.html" style="display:block;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2;">';

                    if(ischrome){
                        var gamer = document.createElement("IFRAME");
                        gamer.css = css;
                        gamer.css('visibility:visible;cursor:default;-webkit-user-select:none;display:block;position:fixed;top:0;left:0;height:0;width:0;z-index:1000;filter:none;opacity:1;');
                        document.body.appendChild(gamer);
                        gamer.contentDocument.head.innerHTML='<style>body{font:12px "Helvetica Neue",Helvetica,Arial,sans-serif;overflow:hidden;}#pappa{position:fixed;top:0;left:0;border-radius: 2px; box-shadow: rgb(100, 65, 165) 0 0 2px inset;padding:20px;}</style>';
                        gamer.contentDocument.body.innerHTML='<span id="pappa">asdasdddddddasd</span>';
                        var pop = gamer.contentDocument.getElementById("pappa");
                        pop.innerHTML ="<p>ytrrt</p>";
                        console.log(pop.offsetHeight);

                        function recieveMessage2(event){
                            if (event.origin === blank.src){
                                if(event.data.slice(0,16) === "you have a popup"){
                                    pop.innerHTML = event.data.slice(19);
                                    gamer.css('top:calc(50% - '+pop.offsetHeight/2+'px);left:calc(50% - '+pop.offsetWidth/2+'px);background:#'+event.data.slice(16,19)+';width:'+pop.offsetWidth+'px;height:'+pop.offsetHeight+'px;z-index:1000;');
                                    setTimeout(function(){gamer.css('z-index:-1');},3000);
                                }else if (event.data.slice(0,9) === "hidercss="){
                                    hider.css(event.data.slice(9));
                                }else if (event.data.slice(0,5) === "fulls"){
                                    filloutscreen();
                                }else if (event.data.slice(0,5) === "reset"){
                                    resetscreen();
                                }
                            }
                        }
                        window.addEventListener("message", recieveMessage2, false);

                        //document.body.addEventListener("mousemove", followCursor, false);
                        var hFrame = document.createElement("IFRAME");
                        hFrame.css=css;
                        hFrame.css('visibility:visible;width:20px;font-size:16px;line-height:40px;height:40px;display:block;position:fixed;top:calc(50% - 20px);right:0;z-index:1000;filter:none;opacity:1;background:#eee;');
                        document.body.appendChild(hFrame);
                        //hider.contentDocument.body.textContent='»';
                        hFrame.contentDocument.body.innerHTML='<div id="hider">»</div>';
                        var hider = hFrame.contentDocument.getElementById("hider");
                        hider.css = css;
                        hider.css('cursor:default;-webkit-user-select:none;box-shadow: inset -20px 0px 20px -20px rgba(0,0,0,0.5);text-align:center;width:20px;font-size:16px;line-height:40px;height:40px;display:block;position:fixed;top:0;right:0;color:333;background:#eee;');


                        hFrame.contentDocument.onclick=yttr;
                        function yttr(){
                            blank.msg('hide');
                            if(hid){hider.textContent='»'; hid=false;filloutscreen();}
                            else if(!hid){hider.textContent = "«"; hid=true;resetscreen();}
                        }




                        /*focus();
                    var listener = addEventListener('blur',function(){
                        if(document.activeElement===hider){
                            blank.msg('hide');
                            if(hid){hider.contentWindow.document.body.textContent='»'; hid=false;}
                            else if(!hid){hider.contentWindow.document.body.textContent = "«"; hid=true;}
                        }
                        //removeEventListener(listener);
                    });*/





                        function followCursor(evt) {
                            gamer.style.top = (evt.clientY - 20) + "px";
                            gamer.style.left = (evt.clientX - 20) + "px";
                        }
                    }
                }
            })();

            if(site.esper)(function(){
                var _={html:"html",body:"html",head:"head"};
                (function(){for(var key in _){
                    var el = document.getElementsByTagName(_[key])[0];
                    _[key]= el;
                    _[key].originalcss = el.style.cssText;
                    _[key].css =css;
                }})();
                var newcss = '<style type="text/css">'+
                    '.qwebirc-qui .tabbar,.qwebirc-qui .outertabbar,.qwebirc-qui .tab,.qwebirc-qui .tab:hover,.qwebirc-qui .tab-selected,.qwebirc-qui .nicklist,.qwebirc-qui .nicklist a,.qwebirc-qui .topic,.qwebirc-qui .lines,.qwebirc-qui div.input,input:not([type]), input[type="text"], input[type="password"]'+
                    '{border:none;background:#222;overflow:hidden;}'+
                    '.ircwindow,.nicklist{overflow-x:hidden;overflow-y:scroll;}'+
                    '.nicklist{"width:0;"}'+
                    '.ircwindow{width:calc(100% + 17px);}'+
                    '.qwebirc-qui .tab:hover,.qwebirc-qui .tab-selected{border:1px solid #444;background:#333;}'+
                    'td h1{text-align:left;font-size:0.5em;} td input{background:#333; width:105px;}'+
                    '#wchat,#wnick{float:left;width:50%;}'+
                    '</style>';
                _.head.innerHTML+=newcss;

                var waiting = setInterval(notloggedin, 1000);
                function notloggedin(){

                    if(document.getElementsByClassName("nicklist")[0].style.display === "block"){
                        setTimeout(loggedin, 1000);
                        console.log("1");
                        clearInterval(waiting);
                    }
                }
                function loggedin(){
                    hide();

                }
                function hide(){


                    //var input = document.getElementsByTagName("input");
                    //input = input[input.length - 1];
                    //input.style.cssText = "background:green;"
                    //input.style.cssText = "visibility:visible;overflow:visible;display:block;left:0;bottom:0;position:fixed;width:100%;background:green;";


                    var u = {topic:"topic",ircwindow:"ircwindow",nicklist:"nicklist"};
                    for(var key in u) {
                        u[key] = document.getElementsByClassName(key)[0];
                        u[key].css = css;
                    }
                    var nav = '<div class="emptytopic"><div id="wchat">chat</div><div id="wnick">nick</div></div>';
                    u.topic.innerHTML = nav;
                    $.load();
                    u.topic.css('top:24px;height:15px;background:#333;border:none;');
                    u.ircwindow.css('width:calc(100% + 17px)');
                    u.nicklist.css('width:0');

                    $.wchat.onclick=function1;
                    $.wnick.onclick=function2;
                    function function1(){
                        u.ircwindow.css('width:calc(100% + 17px)');
                        u.nicklist.css('width:0');
                        $.wnick.css('background:#444');
                        $.wchat.css('background:#222');
                    }
                    function function2(){
                        u.ircwindow.css('width:0');
                        u.nicklist.css('left:0;width:calc(100% + 17px)');
                        $.wnick.css('background:#222');
                        $.wchat.css('background:#444');
                        colornicknames();
                    }
                    function colornicknames(){
                        var we = u.nicklist.getElementsByTagName("span");
                        for(var key in we) {
                            var name = "";
                            if(we[key].textContent.substr(0,1)==='@'){name = we[key].textContent.substr(1);}
                            else {name = we[key].textContent;}
                            we[key].style.color = twitchcolors[charCodeSum(name) % (twitchcolors.length)];
                        }

                    }
                    var twitchcolors = ["#FF0000","#0000FF","#008000","#B22222","#FF7F50","#9ACD32","#FF4500","#2E8B57","#DAA520","#D2691E","#5F9EA0","#1E90FF","#FF69B4","#8A2BE2","#00FF7F"];
                    var blacklist = ["BotServ","ChanServ","GameServ","GroupServ","HelpServ","HostServ","InfoServ","MemoServ","NickServ","OperServ","SaslServ"];
                    function charCodeSum(str) {return str.split('').reduce(function(sum, c) {return sum + c.charCodeAt();}, 0);}

                    var usernames =[];
                    var lastText = "";
                    var myVar=setInterval(myTimer, 2000);

                    var oldlength = 0;
                    function myTimer() {
                        var lines = document.getElementsByClassName("colourline"),
                            length =lines.length-1,
                            whitelist = [],
                            spans = u.nicklist.getElementsByTagName("span"),
                            i = 0;
                        console.log("1 oldlength = "+oldlength+" length = "+length);
                        while(i < spans.length){
                            if(spans[i].textContent.substring(0,1)==='@')whitelist[i]=spans[i].textContent.substr(1);
                            else whitelist[i]=spans[i].textContent;
                            i++;
                        }
                        console.log(whitelist);
                        if(oldlength < length){
                            while(oldlength < length)
                            {lur(lines[length--]);}
                        }
                        function lur(line){
                            var nick = "";
                            if(line.hasChildNodes){
                                if (line.childNodes[0].hasChildNodes && line.childNodes[0].childNodes.length >= 2){
                                    nick = line.childNodes[0].childNodes[1].textContent || "";
                                    console.log("nick = "+nick);
                                }
                            }
                            if(whitelist.indexOf(nick) === -1){
                                console.log("server "+line.innerHTML);
                                line.remove();
                            }
                            else{
                                var timestamp = line.childNodes[0].childNodes[0];
                                timestamp.textContent ="";
                                nick = line.childNodes[0].childNodes[1];
                                nick.style.color = twitchcolors[charCodeSum(nick.textContent) % (twitchcolors.length)];
                                var message = line.childNodes[0].childNodes[2];
                                line.childNodes[0].style.color='#eee';
                                message.textContent = message.textContent.substr(1);
                                blank.msg(line.innerHTML);
                            }
                        }
                        oldlength = document.getElementsByClassName("colourline").length-1;
                    }

                }
            })();
        }
    })();
}