cb theatermode clean

profile clean up and video settings

As of 2019-01-26. See the latest version.

// ==UserScript==
// @name         cb theatermode clean
// @namespace    chaturbate_theater_goes_ladroop
// @version      1.04
// @description  profile clean up and video settings
// @license	     MIT
// @copyright      2018, ladroop (https://sleazyfork.org/nl/users/7390-ladroop)
// @match        https://*.chaturbate.com/*
// @exclude      https://*.chaturbate.com/accounts/*
// @noframes
// @grant        none
// @run-at       document-end
// ==/UserScript==




(function() {
    'use strict';

//prevents the script from throwing errors to CB's own error logger and maybe some part of the script keeps working if they make changes again
window.onerror=function(){return true;};

// this cookie removes most add's
if (!readCookie("noads")){createCookie("noads","1",30);window.location.reload(true);}

var varea=""; // video area- getvid()
var container="";// bio area- main()
var tadd=""; // top area- main()
var topbar=""; // menu top bar- main()
var buttons=""; // buttons area- main()
var loggedin=false; // login status- cleanoptions()
var observer = new MutationObserver(refreshed); // to be called if page is refreshed
var observerConfig = {characterData: true, childList: true}; // changes if pages is refreshed
var observenode="";// node to observe if page is refreshed (will be title)- main()
var roomname="";//broadcasters name- getroomname()
var muteb="";//mute button- main()
var cblogo="";// logo in video- main()
var p=0;// running promises- info(), also used in cleaninit()

// temporary used in multiple functions
var n=0;
var i=0;
var url="";
var br="";
var ofils=[];
var tags=[];

// used by drag slider window
var pos1=0, pos2=0, pos3=0, pos4=0, x=0, y=0;

// things to remember from the broadcaster all set by info()
var allow_group_shows=false;
var allow_private_shows=false;
var room_status="";
var hls_source="";
var spyonpvt=-1;// remember from last fetch and use if broadcaster is not in pvt anymore, -1=don't know, 0=disabled

test();

// test if bio container is created , give up after 10 seconds , not a theater mode page
function test(){
    if(document.getElementsByClassName("bio-container")[0]){n=0;test2();}
    else{
        n++;
        if (n==100){return;}
        setTimeout(function(){test();}, 100);
    }
}

// check if data is written in the bio conatiner
function test2(){
    if(document.getElementsByClassName("bio-container")[0].getElementsByTagName("span").length >= 2){test3();}
    else{
        n++;
        if (n==50){
            if (document.getElementsByClassName("bio-container")[0].innerHTML.indexOf("Loading room, please wait")==-1){
                checkban();// no bio - banned ??
                return;
            }
        }
        setTimeout(function(){test2();}, 100);
    }
}

// wait till bio is ready
function test3(){
    var biocont=document.getElementsByClassName("bio-container")[0].innerHTML;
    setTimeout(function(){
        if (biocont == document.getElementsByClassName("bio-container")[0].innerHTML){
            main();
        }else{
            test3();
        }
    }, 100);
}

function main(){
//first get some locations
    tadd=document.getElementsByTagName("div")[0];
    tags=tadd.childNodes;

    tags=tags[0].childNodes;
    for (n=0; n<tags.length; n++){
        if(tags[n].innerHTML.indexOf("/tags/")!=-1){
            topbar=tags[n];
            break;
        }
    }
    container=document.getElementsByClassName("bio-container")[0];
    observenode=document.getElementsByTagName("title")[0];
    tags=document.getElementsByTagName("span");
    for (n=0; n<tags.length; n++){
        if(tags[n].innerHTML.indexOf("+ ")!=-1){
            buttons=tags[n].parentNode.parentNode;
            break;
        }
    }
    getvid();
    getroomname();
    tags=varea.parentNode.getElementsByTagName("img");

    for (n=0; n<tags.length; n++){
        if (tags[n].src.indexOf("/theatermodeassets/logo.svg") !=-1){
            cblogo=tags[n];
        }
        if (tags[n].src.indexOf("/theatermodeassets/volume-") !=-1){
            muteb=tags[n];
            break;
        }
    }

 // do some actions
    removeadds();
    cleanoptions();
    makebutton();
    linkfix();
    imgfix();
    cleaninit();
    info();
    observer.observe(observenode, observerConfig);
    nobio();
}

//-----------------functions in random order
// set version and remove logo
    function removeadds(){
        var newelem=document.createElement('div');
        newelem.style.position="absolute";
        newelem.style.top="10px";
        newelem.style.left="255px";
        newelem.style.fontSize="12px";
        newelem.style.color="#0b5d81";
        newelem.style.fontWeight="bold";
        newelem.id="update";
        newelem.innerHTML="Chaturbate Theater Mode Clean V"+GM_info.script.version+" Made By Ladroop";
        tadd.appendChild(newelem);

        if (cblogo!==""){
            cblogo.style.display="none";
        }
    }

// get the name of the broadcaster
    function getroomname(){
        roomname=document.location.href.split("/")[3];
        if (roomname=="theatermode"){
            roomname=document.location.href.split("?b=")[1];
        }
        // a weird bug that appears if you go from theatermode userlist to a no access room
        if (roomname.indexOf("/")!=-1){
            roomname=roomname.split("/")[0];
        }
    }

// get the video area
    function getvid(){
        if (document.getElementById("xmovie")){
            varea=document.getElementById("xmovie");
        }else{
                varea=document.getElementsByTagName("video")[0];
        }
    }

//if a user is not verified and got no tokens the user bio does not show and images are not clickable, this function creates a link to the image center if there are images
    function nobio(){
        tags=container.getElementsByTagName("span");
        if (tags.length !== 0){
            if (tags[tags.length-1].innerHTML == "User has no available bio"){
                if(container.getElementsByTagName("img").length!==0){
                    tags[tags.length-1].innerHTML= "User has no available bio<br><a href='https://"+location.hostname+"/photo_videos/photoset/list_popup/"+roomname+"/' target=_blank >Open user uploads center</a>";
                }
            }
        }
    }

//if you can not enter the room make a jpg player. this function is very stand alone and rare if ever called bc CB redirects to the old page
    function checkban(){
        getroomname();
        getvid();
        var newvid = document.createElement('img');
        newvid.src="https://chaturbate.com/static/theatermodeassets/cam_notice_background.jpg";
        newvid.style.width="100%";
        newvid.style.height="100%";
        newvid.id="update";
        var vidpar=varea.parentNode;
        vidpar.insertBefore(newvid,vidpar.childNodes[0]);
        varea=document.getElementById("update");
        var errcnt=1;
        var wtime=0;
        var cimg = new Image();

        cimg.onload = function(){
            document.getElementById("update").src=cimg.src;
            setTimeout(function(){ cimg.src = 'https://cbjpeg-serve.stream.highwebmedia.com/stream?room='+roomname+'&f='+ new Date().getTime();errcnt=1;}, 100);
        };

        cimg.onerror = function(){
            errcnt++;
            wtime=100*errcnt;
            if (wtime>10000){wtime=10000;}
            setTimeout(function(){ cimg.src = 'https://cbjpeg-serve.stream.highwebmedia.com/stream?room='+roomname+'&f='+ new Date().getTime();}, wtime);
        };

        cimg.src = 'https://cbjpeg-serve.stream.highwebmedia.com/stream?room='+roomname+'&'+ new Date().getTime();

        // in case the site was that slow that it ended on a no access page while still loading
        setInterval(function(){
            if(document.getElementsByClassName("bio-container")[0].innerHTML!==""){
                location.reload();
            }
        }, 10000);
     }

// called by mutationobserver if page is refreshed
    function refreshed(){
        observer.disconnect();
        getvid();
        getroomname();
        spyonpvt=-1;
        n=0;
        document.getElementById("clean").style.display="none";
        document.getElementById("controls").style.display="none";
        document.getElementById("controls").style.marginTop="30px";
        document.getElementById("controls").style.right="320px";
        // fix wrong location bug , only with flash
        flashstart();
        vreset();
        // here check if bio is ready again
        retest2();
    }

// recheck if data is written in the bio container - part of refreshed()
    function retest2(){
        if(container.getElementsByTagName("span").length >= 2){
            retest3();
        }else{
            n++;
            if (n==50){
                if (container.innerHTML.indexOf("Loading room, please wait")==-1){
                    checkban();// no bio , banned ?
                }
            }
            setTimeout(function(){retest2();}, 100);
        }
    }

// wait if bio is ready - part of refreshed()
    function retest3(){
        var biocont=container.innerHTML;
        setTimeout(function(){
            if (biocont == container.innerHTML){
                reclean();
            }else{
                retest3();
            }
        }, 100);
    }

// clean only bio and topbar after refesh - part of refreshed()
    function reclean(){
        linkfix();
        imgfix();
        cleaninit();
        cleanoptions();
        info();
        observer.observe(observenode, observerConfig);
        nobio();
    }

// clean the option bar and see if you're logged in make back button if cookie is set
    function cleanoptions(){
        tags=topbar.getElementsByTagName("a");
        for (n=2; n<tags.length; n++){
            if (tags[n].href.indexOf('/login') != -1){
                if(tags[n].style.display=="none"){
                    loggedin=true;
                }
            }
            if (tags[n].href.split("/")[3]=="b"){
                tags[n].target="_blank";
            }else{
                if (tags[n].href.indexOf('/login') == -1){
                    tags[n].style.display="none";
                }
            }
            if ((tags[n].href.split("/")[3]=='tags')||(tags[n].innerHTML=="BACK")){
                if (readCookie("selected")){
                    tags[n].style.display="initial";
                    tags[n].href=readCookie("selected");
                    tags[n].innerHTML="BACK";
                    tags[n].addEventListener('click',function(){eraseCookie("selected")});
                }
            }
        }
    }

// make all new buttons and sliders and set the video filter
    function makebutton(){
        var butstyle="margin-right: 10px;color: rgb(255, 255, 255); background: rgba(0, 0, 0, 0) linear-gradient(rgb(255, 151, 53) 0%, rgb(255, 158, 54) 50%, rgb(255, 112, 2) 60%) repeat scroll 0% 0%; font-family: UbuntuMedium, Helvetica, Arial, sans-serif; font-size: 12px; text-shadow: rgb(241, 129, 18) 1px 1px 0px; padding: 4px 10px 3px; position: relative; top: -4px; right: 1px; float: right; border-radius: 4px; cursor: pointer; display: inline;";
        var slistyle="text-align: left; width: 310px;margin-right: 10px;color: rgb(255, 255, 255); background: rgba(0, 0, 0, 0) linear-gradient(rgb(255, 151, 53) 0%, rgb(255, 158, 54) 50%, rgb(255, 112, 2) 60%) repeat scroll 0% 0%; font-family: UbuntuMedium, Helvetica, Arial, sans-serif; font-size: 12px; text-shadow: rgb(241, 129, 18) 1px 1px 0px; padding: 4px 10px 3px; position: relative; top: -4px; right: 1px; float: right; border-radius: 4px; display: inline;";

        var newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="CLEAN PROFILE = ON";
        newelem.style.width="125px";
        newelem.style.display="none";
        newelem.id="clean";
        newelem.addEventListener("click", cleancookie);
        buttons.appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="VIDEO CONTROLS ON/OFF";
        newelem.addEventListener("click", vcontrol);
        newelem.id="vcontr";
        buttons.appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="RELOAD INFO";
        newelem.addEventListener("click", newinfo);
        newelem.id="infore";
        buttons.appendChild(newelem);

        newelem=document.createElement('div');
        newelem.id="controls";
        newelem.style.display="none";
        newelem.style.position="absolute";
        newelem.style.backgroundColor="rgb(255, 255, 211)";
        newelem.style.border="2px solid rgb(244, 115, 33)";
        newelem.style.borderRadius="6px";
        newelem.style.width="350px";
        newelem.style.padding="12px";
        newelem.style.marginTop="30px";
        newelem.style.right="320px";
        newelem.style.zIndex="999";
        buttons.appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="MIRROR VIDEO";
        newelem.addEventListener("click",mirror);
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="INVERT VIDEO";
        newelem.addEventListener("click",invert);
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="DRAG";
        newelem.style.cursor="move";
        newelem.addEventListener("mousedown",dragMouseDown);
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.innerHTML="BRIGHTNESS : <input type='range' id='myRange' min=0 max=200 value=100 style='width: 200px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("controls").appendChild(newelem);
        document.getElementById("myRange").addEventListener("input",badjust);

        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.innerHTML="CONTRAST : <input type='range' id='myRange1' min=0 max=200 value=100 style='width: 200px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("controls").appendChild(newelem);
        document.getElementById("myRange1").addEventListener("input",cadjust);

        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.innerHTML="SATURATION : <input type='range' id='myRange2' min=0 max=200 value=100 style='width: 200px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("controls").appendChild(newelem);
        document.getElementById("myRange2").addEventListener("input",sadjust);

        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.innerHTML="HUE : <input type='range' id='myRange3' min=180 max=540 value=360 style='width: 200px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("controls").appendChild(newelem);
        document.getElementById("myRange3").addEventListener("input",hadjust);

        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('br');
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="HIDE CONTROL PANEL";
        newelem.addEventListener("click",vcontrol);
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="RESET ALL";
        newelem.addEventListener("click",vreset);
        document.getElementById("controls").appendChild(newelem);

        newelem=document.createElement('input');
        newelem.id="copytext";
        newelem.type="text";
        newelem.style.display="none";
        buttons.appendChild(newelem);

        vreset();
     }

// fix the redirection links in the profile
     function linkfix(){
         tags = container.getElementsByTagName('a');
         for (i=0; i<tags.length; i++){
             if (tags[i].href.indexOf('?url=') != -1){
                  tags[i].href=decodeURIComponent(tags[i].href).split("?url=")[1];
             }
         }
     }

// hide the lock on paid profile pictures
     function imgfix(){
         tags = container.getElementsByTagName('img');
         for (i=0; i<tags.length; i++){
             if (tags[i].src.indexOf('theatermodeassets/locked_rectangle') != -1){
                  tags[i].style.display="none";
             }
         }
     }

// get basic info, hide video controls in an offline room
     function info(){
         url="https://"+location.hostname+"/api/chatvideocontext/"+roomname+"/";
         p++;
         fetch(url,{ credentials: "same-origin"}).then(
             function(response) {
                 if (response.status !== 200) {
                     p--;
                     return;
                 }
                 response.json().then(function(data) {
                     allow_group_shows=data.allow_group_shows;
                     allow_private_shows=data.allow_private_shows;

                     if ((room_status == "")&&(data.room_status == "offline")){
                         document.getElementById("vcontr").style.display="none";
                     }

                     room_status=data.room_status;
                     hls_source=data.hls_source.split("?")[0];

                     if (data.low_satisfaction_score===true){
                         wprof("Satisfaction score:","<font color=#CC0000>LOW !!!</font>");
                     }
                     if (data.is_moderator===true){
                         wprof("Moderator","Yes, don't silence me");
                     }
                     if (room_status=="offline"){
                         wprof("Video:","Offline");
                     }
                     if (data.is_age_verified===false){
                         wprof("Status:","Exhibitionist");
                         p--;
                         return;
                     }
                     p--;
                     // next can only be done if logged in
                     if (loggedin){
                         lasttip();
                         getpvt();
                         getgrp();
                         getspy();
                     }
                 });
             });
     }

// get private costs info - part of info()
     function getpvt(){
         if (allow_private_shows){
             url="https://"+location.hostname+"/tipping/private_show_tokens_per_minute/"+roomname+"/";
             p++;
             fetch(url,{ credentials: "same-origin"}).then(
                 function(response) {
                     if (response.status !== 200) {
                         p--;
                         return;
                     }
                     response.json().then(function(data) {
                         wprof("Minimum private:",data.private_show_minimum_minutes+" Minutes");
                         wprof("Private recording:",data.recordings_allowed ? "Yes":"No");
                         wprof("Privateshow:",data.price+" Tk/min");
                         p--;
                     });
                 });
         }else{
             wprof("Privateshow:","Disabled");
         }
     }

// get goupshow costs info - part of info()
     function getgrp(){
         if (allow_group_shows){
             url="https://"+location.hostname+"/tipping/group_show_tokens_per_minute/"+roomname+"/";
             p++;
             fetch(url,{ credentials: "same-origin"}).then(
                 function(response) {
                     if (response.status !== 200) {
                         p--;
                         return;
                     }
                     response.text().then(function(data) {
                         wprof("Groupshow:",data+" Tk/min");
                         p--;
                     });
                 });
         }else{
             wprof("Groupshow:","Disabled");
         }
     }

// get spy costs info, if the room is out of private use the value of last fetch (if it's there) - part of info()
     function getspy(){
         if (room_status=="private"){
             url="https://"+location.hostname+"/tipping/spy_on_private_show_tokens_per_minute/"+roomname+"/";
             p++;
             fetch(url,{ credentials: "same-origin"}).then(
                 function(response) {
                     if (response.status !== 200) {
                         p--;
                         return;
                     }
                     response.text().then(function(data) {
                         spyonpvt = data;
                         if (data!="0"){
                             wprof("Spy on private:",data+" Tk/min");
                         }else{
                             wprof("Spy on private:","Disabled");
                         }
                         p--;
                     });
                 });
         }else{
             if (spyonpvt !=-1){
                 if (spyonpvt!="0"){
                     wprof("Spy on private:",spyonpvt+" Tk/min");
                 }else{
                     wprof("Spy on private:","Disabled");
                 }
             }
         }
     }

// get how many you tipped the last 24 hours - part of info()
     function lasttip(){
         url="https://"+location.hostname+"/tipping/tips_in_last_24/"+roomname+"/";
         p++;
         fetch(url,{ credentials: "same-origin"}).then(
             function(response) {
                 if (response.status !== 200) {
                     p--;
                     return;
                 }
                 response.json().then(function(data) {
                     if (data.tipped_performer_last_24hrs!="0"){
                         wprof("You tipped:",data.tipped_performer_last_24hrs+" Tk/24h");
                     }
                     p--;
                 });
             });
     }

//mark elements that can be hidden in the profile and call cleanup()
    function cleaninit(){
        var taglist=["a","p","i","strong","b","u","ul","ol","li","h1","h2","h3","img","font","br"];
        for (i=0; i<taglist.length; i++){
            tags = container.getElementsByTagName(taglist[i]);
            for (n=0; n<tags.length; n++){
                if (tags[n].style.position){
                    if ((tags[n].style.position.indexOf("absolute")!=-1)||(tags[n].style.position.indexOf("fixed")!=-1)){
                        if (tags[n].getAttribute("rel")){
                            tags[n].setAttribute("name", "clean");
                            p++;
                        }
                    }
                }
            }
        }
        if (p!==0){
            document.getElementById("clean").style.display="block";
            cleanup();
            p=0;
        }
    }

//-------------- later called functions

// brightness adjust
	function badjust(){
		br=document.getElementById("myRange").value;
		ofils=varea.style.filter.split(" ");
		varea.style.filter="brightness("+br+"%) "+ofils[1]+" "+ofils[2]+" "+ofils[3]+" "+ofils[4];
	}

// contrast adjust
	function cadjust(){
		br=document.getElementById("myRange1").value;
		ofils=varea.style.filter.split(" ");
		varea.style.filter=ofils[0]+" contrast("+br+"%) "+ofils[2]+" "+ofils[3]+" "+ofils[4];
      	}

// saturation adjust
	function sadjust(){
		br=document.getElementById("myRange2").value;
		ofils=varea.style.filter.split(" ");
		varea.style.filter=ofils[0]+" "+ofils[1]+" "+ofils[2]+" saturate("+br+"%) "+ofils[4];
	}

// hue adjust
	function hadjust(){
		br=document.getElementById("myRange3").value;
		if (br > 359){br=br-360;}
		ofils=varea.style.filter.split(" ");
		varea.style.filter=ofils[0]+" "+ofils[1]+" "+ofils[2]+" "+ofils[3]+" hue-rotate("+br+"deg)";
	}

// invert video
	function invert(){
		ofils=varea.style.filter.split(" ");
		br=" invert(100%) ";
		if (ofils[2]=="invert(100%)"){br=" invert(0%) ";}
		varea.style.filter=ofils[0]+" "+ofils[1]+br+ofils[3]+" "+ofils[4];
	}

// mirror video
	function mirror(){
		if (varea.style.transform=="none"){
			varea.style.transform="matrix(-1, 0, 0, 1, 0, 0)";
		}else{
			varea.style.transform="none";
		}
	}

// reset all video adjustments
	function vreset(){
  		varea.style.filter="brightness(100%) contrast(100%) invert(0%) saturate(100%) hue-rotate(0deg)";
		varea.style.transform="none";
 		document.getElementById("myRange").value=100;
		document.getElementById("myRange1").value=100;
		document.getElementById("myRange2").value=100;
		document.getElementById("myRange3").value=360;
	}

// video controls on/off
    function vcontrol(){
        if (document.getElementById("controls").style.display=="block"){
            document.getElementById("controls").style.display="none";
        }else{
            document.getElementById("controls").style.display="block";
        }
    }

// pull and drag functions
// when clicked
    function dragMouseDown(e) {
        e = e || window.event;
        e.preventDefault();
        pos3 = e.clientX;
        pos4 = e.clientY;
        document.onmouseup = closeDragElement;
        document.onmousemove = elementDrag;
    }

// when moved while clicked- part of dragMouseDown()
    function elementDrag(e) {
        e = e || window.event;
        e.preventDefault();
        pos1 = pos3 - e.clientX;
        pos2 = pos4 - e.clientY;
        pos3 = e.clientX;
        pos4 = e.clientY;
        x =parseInt(document.getElementById("controls").style.right);
        y =parseInt(document.getElementById("controls").style.marginTop);
        if ((pos3>=110)&&(pos3<=window.innerWidth-324)){
            document.getElementById("controls").style.right = (x + pos1) + "px";
        }
        if ((pos4>=20)&&(pos4<=window.innerHeight-20)){
            document.getElementById("controls").style.marginTop = (y - pos2) + "px";
        }
    }

// stop moving when mouse button is released- part of dragMouseDown()
    function closeDragElement() {
        document.onmouseup = null;
        document.onmousemove = null;
    }

// swap profile cleanup cookie and call cleanup()
	function cleancookie(){
		if (readCookie("pclean")){
			eraseCookie("pclean");
		}else{
			createCookie("pclean",1,30);
        }
		cleanup();
	}

// hide or unhide marked elements in profile according to cookie
    function cleanup(){
        var claction=!readCookie("pclean");
        if (claction){
            document.getElementById("clean").innerHTML= "CLEAN PROFILE = ON";
        }else{
            document.getElementById("clean").innerHTML= "CLEAN PROFILE = OFF";
        }
        tags=document.getElementsByName("clean");
        for (i=0; i<tags.length; i++){
            if (claction){
				tags[i].style.display="none";
			}else{
				tags[i].style.display="block";
            }
        }
    }

// write a line in the profile at the top
    function wprof(col1,col2){
        var newdiv=document.createElement('div');
        newdiv.style.fontWeight="normal";
        newdiv.style.margin="9px 0px";
        newdiv.setAttribute("name", "info");
        var newspan=document.createElement('span');
        newspan.style.display="inline-block";
        newspan.style.color="rgb(0, 0, 139)";
        newspan.style.fontFamily="UbuntuMedium, Helvetica, Arial, sans-serif";
        newspan.style.fontSize="14px";
        newspan.style.width="150px";
        newspan.innerHTML=col1;
        newdiv.appendChild(newspan);
        newspan=document.createElement('span');
        newspan.style.color="rgb(51, 51, 51)";
        newspan.style.fontSize="14px";
        newspan.style.width="87.5%";
        newspan.innerHTML=col2;
        newdiv.appendChild(newspan);
        var firstcolp=container.getElementsByTagName("span")[0].parentNode;
        firstcolp.parentNode.insertBefore(newdiv, firstcolp);
    }

// removes the extra info in the profile and gets it again , calls flashstart , copy hls to clipboard
    function newinfo(){
        if (p!==0){alert("Slow down !");return;}
        copyclipboard(hls_source);
        tags=document.getElementsByName("info");
  		for(i=tags.length-1;i>=0;i--){
            tags[i].parentNode.removeChild(tags[i]);
        }
        flashstart();
        info();
    }

// copy cdata to clipboard (only works after user interaction)
    function copyclipboard(cdata){
        document.getElementById("copytext").value=cdata;
        document.getElementById("copytext").style.display="block";
        document.getElementById("copytext").select();
        document.execCommand("copy");
        document.getElementById("copytext").style.display="none";
    }

// restarts flash video and puts it back as 2nd element, reset private status and click mute 2 times
    function flashstart(){
        if (document.getElementById("xmovie")){
            var vidpar=varea.parentNode;
            var vid=varea.cloneNode(true);
            n=0;
            if (vidpar.childNodes[0].style.display=="block"){
                n=1;
            }
            vidpar.removeChild(varea);
            vidpar.insertBefore(vid,vidpar.childNodes[1]);
            if (n==1){
                setTimeout(function(){vidpar.childNodes[0].style.display="block";},1500);
            }
            varea=document.getElementById("xmovie");
            muteb.dispatchEvent(new Event('click'));
            muteb.dispatchEvent(new Event('click'));
        }
    }

// cookie functions
	function createCookie(name,value,days,domain){
        var expires="";
        if (domain){
            domain=";domain=."+domain;
        }else{
            domain = "";
        }
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            expires = "; expires="+date.toGMTString();
        }
        document.cookie = name+"="+value+expires+"; path=/"+domain;
	}

	function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(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,domain){
        createCookie(name,"",-1,domain);
	}

})();