taratuna4 / Chaturbate Clean

// ==UserScript==
// @name           Chaturbate Clean
// @description    Just M3u8 extraction added to ladroop's version all credit goes to ladroop
// @version 2.3
// @updateURL	   https://openuserjs.org/meta/taratuna4/Chaturbate_Clean.meta.js
// @namespace      chaturbate_goes_ladroop
// @include        https://chaturbate.com/*
// @include        https://*.chaturbate.com/*
// @noframes
// @grant          none
// @run-at         document-start
// ==/UserScript==


function do_script() {

	version = 2.3;


// use unused add space
	ad = document.getElementsByClassName('ad');
	verstr='<strong>Chaturbate Clean V'+version.toFixed(1)+' Made by Ladroop.</strong> <br>';
	if (ad[0]){ad[0].innerHTML=verstr}

// advert options on menu bars - only save "login", "main", "broadcast", "tags" and "my collection"
	bar=document.getElementById("nav");
	if (bar){
		barl=bar.getElementsByTagName('li');
		i=barl.length-1;
		while (i != -1){
			d=barl[i].innerHTML;
			if ((d.indexOf('/login') != -1)||(d.indexOf('href="/"') != -1)||(d.indexOf('href="/b/') != -1)||(d.indexOf('/my_') != -1)||(d.indexOf('/tags') != -1)){i--}
			else{barl[i].parentNode.removeChild(barl[i]);i--}
	}	}

// blog spam
	ad = document.getElementsByClassName('featured_blog_posts')[0];
	if (ad){ad.parentNode.removeChild(ad)}

// footer spam
	ad = document.getElementsByClassName('featured_text')[0];
	if (ad){ad.parentNode.removeChild(ad)}

// announcement banner (if present)
	ad = document.getElementsByClassName('top-section')[0];
	if (ad){
		ad = ad.getElementsByTagName('img')[0];
		if (ad){ad.parentNode.removeChild(ad)}
	}

// advanced search
	if((document.location.href.indexOf("spy-on-cams")==-1)&&(document.location.href.indexOf("followed-cams")==-1)&&(document.location.href.indexOf("/tag")==-1)){
	if (document.getElementsByClassName('c-1 endless_page_template')[0]){
		if (document.getElementsByClassName('sub-nav')[0]){
		newli=document.createElement('li');
		data='<form><select onchange=\'loc=document.location.href.split("/");pos=loc[0]+"/"+loc[1]+"/"+loc[2]+this.options[this.selectedIndex].value;document.location.href=pos;\' style="margin: 0px 0px 0px 0px; background: #DDE9F5; color:#5E81A4; border-radius: 4px 4px 0px 0px;padding: 3px 1px 4px 12px; font-weight: 400; font-size: 13px; font-family: \'UbuntuMedium\',Arial,Helvetica,sans-serif;" >'
		+'<option value="/XX-cams">ALL CAMS IN CATEGORY</option>'
		+'<option value="/exhibitionist-cams/XX">EXHIBITIONIST CAMS</option>'
		+'<option value="/hd-cams/XX">HD CAMS</option>'
		+'<option value="/new-cams/XX">NEW CAMS</option>'
		+'<option value="/teen-cams/XX">TEEN CAMS (18+)</option>'
		+'<option value="/18to21-cams/XX">18 TO 21 CAMS</option>'
		+'<option value="/21to35-cams/XX">21 TO 35 CAMS</option>'
		+'<option value="/30to50-cams/XX">30 TO 50 CAMS</option>'
		+'<option value="/mature-cams/XX">MATURE CAMS (50+)</option>'
		+'<option value="/north-american-cams/XX">NORTH AMERICAN CAMS</option>'
		+'<option value="/euro-russian-cams/XX">EURO RUSSIAN CAMS</option>'
		+'<option value="/south-american-cams/XX">SOUTH AMERICAN CAMS</option>'
		+'<option value="/philippines-cams/XX">PHILIPPINES CAMS</option>'
		+'<option value="/asian-cams/XX">ASIAN CAMS</option>'
		+'<option value="/other-region-cams/XX">OTHER REGION CAMS</option>'
		+'<option value="/6-tokens-per-minute-private-cams/XX">6 TOKENS PER MINUTE</option>'
		+'<option value="/12-tokens-per-minute-private-cams/XX">12 TOKENS PER MINUTE</option>'
		+'<option value="/18-tokens-per-minute-private-cams/XX">18 TOKENS PER MINUTE</option>'
		+'<option value="/30-tokens-per-minute-private-cams/XX">30 TOKENS PER MINUTE</option>'
		+'<option value="/60-tokens-per-minute-private-cams/XX">60 TOKENS PER MINUTE</option>'
		+'<option value="/90-tokens-per-minute-private-cams/XX">90 TOKENS PER MINUTE</option>'
		+'</select></form>';
		uloc=document.location.href+"//////";
		loc=uloc.split("/");
		check=loc[3]+loc[4];
		gen="";
		if(check.indexOf("male") != -1){gen="male"}
		if(check.indexOf("female") != -1){gen="female"}
		if(check.indexOf("couple") != -1){gen="couple"}
		if(check.indexOf("trans") != -1){gen="trans"}
		re=/XX/gi;
		data=data.replace(re,gen);
		if (gen === ""){data=data.replace("-cams","")}
		data=data.replace('<option value="/'+loc[3],'<option selected value="/'+loc[3]);
		newli.innerHTML=data;
		tabs=document.getElementsByClassName('sub-nav')[0].getElementsByTagName("li");
		if (loc[4]!==""){
			for (n=0; n<tabs.length-1; n++){
				tabs[n].className="";
				if (tabs[n].getElementsByTagName("a")[0].href.indexOf("/"+loc[4])!=-1){
					tabs[n].className="active";
				}
			}
		}
		document.getElementsByClassName('sub-nav')[0].appendChild(newli);
	}}}

// remove out of position images on profiles
	container = document.getElementById("tabs_content_container");
	if (container){
		bar=document.getElementById("nav");
		newli=document.createElement('li');
		newli.innerHTML='<a href=# id="clean"></a>';
		bar.appendChild(newli);
		document.getElementById("clean").addEventListener("click", cleancookie);
		cleanup();
	}

// remove lock pictures from thumbs on profiles
	pictures = document.getElementsByClassName('preview');
	if (pictures){
		for (i=0; i<pictures.length; i++){
			if(pictures[i].getAttribute("alt") =="Locked"){
				pictures[i].parentNode.removeChild(pictures[i]);
	}	}	}

//fix external links redirection
	var link = document.getElementsByTagName('a');
	for (i=0; i<link.length; i++){
		if (link[i].href.indexOf('?url=') != -1){
			linkhref=unescape(link[i].href);
			newlinkhref=linkhref.substring(linkhref.indexOf("?url=")+5,linkhref.indexOf("&domain"));
			link[i].href=newlinkhref;
	}	}

    // Get M3U8
    var newli2 = document.createElement('li');
    newli2.innerHTML="<div class='button_share'><a href=#>M3U8</a></div>";        
    newli2.addEventListener('click',function(){copyToClipboard();}, false);
    document.getElementsByClassName("socials")[0].appendChild(newli2);
	
//check if there is video and make settings
	video=document.getElementById("xmovie");
	if (video){

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'> <a href=#>FULL SCREEN WITH CHAT</a></div>";
	newli.addEventListener('click',function(){fullscreenapi();}, false);
	document.getElementsByClassName("socials")[0].appendChild(newli);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'> <a href=#>VIDEO CONTROLS</a></div>";
	newli.addEventListener('click',function(){vcont();}, false);
	document.getElementsByClassName("socials")[0].appendChild(newli);

	newul = document.createElement('ul');
	newul.id="vcont";
	newul.style.display="none";
	newul.style.width = "300px";
	newul.className="socials";
	document.getElementsByClassName("headline")[0].appendChild(newul);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'> <a href=#>MIRROR VIDEO</a></div>";
	newli.addEventListener('click',function(){mirror();}, false);
	newul.appendChild(newli);
	mir=0;

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'> <a href=#>INVERT VIDEO</a></div>";
	newli.addEventListener('click',function(){invert();}, false);
	newul.appendChild(newli);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'><a href=#>BRIGHTNESS</a><input type='range' id='myRange' value=50 style='width: 150px;'><a href=# style='float:right;'></a></div>";
	newli.addEventListener("change",function(){badjust();}, false);
	newul.appendChild(newli);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'><a href=#>CONTRAST&nbsp;&nbsp;&nbsp;&nbsp;</a><input type='range' id='myRange2' value=50 style='width: 150px;' ><a href=# style='float:right;'></a></div>";
	newli.addEventListener("change",function(){cadjust();}, false);
	newul.appendChild(newli);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'><a href=#>SATURATION</a><input type='range' id='myRange3' value=50 style='width: 150px;' ><a href=# style='float:right;'></a></div>";
	newli.addEventListener("change",function(){sadjust();}, false);
	newul.appendChild(newli);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'><a href=#>HUE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a><input type='range' id='myRange4' value=360  min=180 max=540 style='width: 150px;'><a href=# style='float:right;'></a></div>";
	newli.addEventListener("change",function(){hadjust();}, false);
	newul.appendChild(newli);

	newli = document.createElement('li');
	newli.innerHTML="<div class='button_share'><a href=#>RESET ALL</a></div>";
	newli.addEventListener("click",function(){vreset();}, false);
	newul.appendChild(newli);


	document.getElementById("xmovie").style.filter="brightness(100%) contrast(100%) invert(0%) saturate(100%) hue-rotate(0deg)";


// fix app area bug
	apparea=document.getElementsByClassName("tip_shell")[0];
	apparea.style.width="100%";

// add full screen enter/exit handler
    document.addEventListener('webkitfullscreenchange', exitHandler, false);
    document.addEventListener('mozfullscreenchange', exitHandler, false);
    document.addEventListener('fullscreenchange', exitHandler, false);

	}// end if video

// wait one second and check if you have no access, if not create a new video box and kill all timers 
	setTimeout(function(){
	area = document.getElementsByClassName('block')[0];
	if (area){
		if (area.innerHTML.length < 700){
			splits = document.location.href.split("/");
			bname=splits[3];
			if (bname!="roomlogin"){
				if (bname=="p"){bname=splits[4]}
					newvid=document.createElement('div');
					newvid.setAttribute("style","clear:both;float:left;margin-left:10px;margin-top:10px;margin-bottom:10px;margin-right:200px;border-width:5px;border-style:double;resize:both;overflow:hidden;width: 640px; height: 480px;")
					newvid.innerHTML="<img id='vidimg' src='https://ssl-ccstatic.highwebmedia.com/images/cam_notice_background.jpg' height=100% width=100%></img>";
					area.appendChild(newvid);
						errcnt=1;
						cimg = new Image();

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

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

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

						newscript=document.createElement('script');
						newscript.textContent="for (var i = 1; i < 99999; i++){window.clearInterval(i)}";
						document.getElementsByTagName('body')[0].appendChild(newscript);
		}	}	}
	}, 1000);

}//end main

// video adjust functions
	function vcont(){
		if (document.getElementById("vcont").style.display=="none"){
			document.getElementById("vcont").style.display="block";
		}else{
			document.getElementById("vcont").style.display="none";
		}
	}

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

	function cadjust(){
		br=document.getElementById("myRange2").value*2;
		ofil=document.getElementById("xmovie").style.filter;
		ofils=ofil.split(" ");
		document.getElementById("xmovie").style.filter=ofils[0]+" contrast("+br+"%) "+ofils[2]+" "+ofils[3]+" "+ofils[4];
	}

	function invert(){
		ofil=document.getElementById("xmovie").style.filter;
		ofils=ofil.split(" ");
		inv=" invert(100%) ";
		if (ofils[2]=="invert(100%)"){inv=" invert(0%) "}
		document.getElementById("xmovie").style.filter=ofils[0]+" "+ofils[1]+inv+ofils[3]+" "+ofils[4];
	}

	function sadjust(){
		br=document.getElementById("myRange3").value*2;
		ofil=document.getElementById("xmovie").style.filter;
		ofils=ofil.split(" ");
		document.getElementById("xmovie").style.filter=ofils[0]+" "+ofils[1]+" "+ofils[2]+" saturate("+br+"%) "+ofils[4];
	}

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

	function mirror(){
		if (mir===0){
			document.getElementById("xmovie").style.transform="matrix(-1, 0, 0, 1, 0, 0)";
			mir=1;
		}else{
			document.getElementById("xmovie").style.transform="none";
			mir=0;
		}
	}

	function vreset(){
		document.getElementById("xmovie").style.filter="brightness(100%) contrast(100%) invert(0%) saturate(100%) hue-rotate(0deg)";
		document.getElementById("xmovie").style.transform="none";mir=0;
		document.getElementById("myRange").value=50;
		document.getElementById("myRange2").value=50;
		document.getElementById("myRange3").value=50;
		document.getElementById("myRange4").value=360;
	}

// to remove or restore floating images on a profile according to cookie
	function cleanup(){
		var taglist=new Array("a","p","i","strong","b","u","ul","ol","li","h1","h2","h3","img","font","br");
		claction=readCookie("pclean");
		if (!claction){
			document.getElementById("clean").innerHTML= "CLEAN PROFILE = <font color=#00AA00>ON</font>";
		}else{
			document.getElementById("clean").innerHTML= "CLEAN PROFILE = <font color=#DC5500>OFF</font>";
		}
		for (n=0; n<taglist.length-1; n++){
			if (!claction){
				blockelm (taglist[n]);
			}else{
				unblockelm (taglist[n]);
	}	}	}

	function blockelm(tag){
		image = container.getElementsByTagName(tag);
		for (i=0; i<image.length; i++){
			if (image[i].style.position){
				if ((image[i].style.position.indexOf("absolute")!=-1)||(image[i].style.position.indexOf("fixed")!=-1)){
					image[i].setAttribute("ostyle", "1");
					image[i].style.display="none";
	}	}	}	}

	function unblockelm(tag){
		image = container.getElementsByTagName(tag);
		for (i=0; i<image.length; i++){
			if (image[i].style.position){
				if (image[i].getAttribute("ostyle")){
					image[i].style.display="block";
	}	}	}	}


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

// full screen function
	function fullscreenapi(){
		eraseCookie("isfullscreen"); // just in case
		elem = document.getElementById("defchat").getElementsByClassName("section")[0];
		if (elem.requestFullscreen) {
			elem.requestFullscreen();
		} else if (elem.mozRequestFullScreen) {
			elem.mozRequestFullScreen();
		} else if (elem.webkitRequestFullscreen) {
			elem.webkitRequestFullscreen();
		}
	}

	function copyToClipboard() {
    //window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
    var scripts = document.getElementsByTagName('script');
    var index = scripts.length - 1;
    var src;
    for (i=0; i<scripts.length; i++){
        var str =scripts[i].innerHTML;
        var regex = /src='(.*?)'/;
        while ( m=regex.exec( str ) ) {
           // m=regex.exec( str );
            src=m[1];    
            console.log(src);
            break
        }
     
    }
    window.prompt("Copy to clipboard: Ctrl+C, Enter", src);
    //console.log(src);
    //console.log(scripts);
    //var myScript = scripts[index];
    //console.log(myScript.innerHTML);

}

//full screen enter/exit handler
	function exitHandler(){
	    if (readCookie("isfullscreen")){ //exit
			eraseCookie("isfullscreen");
			document.getElementById("player").style.width=orgplayerw+"px";
            document.getElementById("player").style.height=orgplayerh+"px";
            elem.style.width="";
			createCookie("player_width",orgplayerw,1);
       		sizeadj();
		}
		else{ //enter
			createCookie("isfullscreen","1",1);
			orgplayerw=parseInt(document.getElementById("player").style.width);
    		orgplayerh=parseInt(document.getElementById("player").style.height);
 			fsplheight=screen.height-110;
			zoom=fsplheight/orgplayerh;
			document.getElementById("player").style.width=Math.round(orgplayerw*zoom)+"px";
			document.getElementById("player").style.height=fsplheight+"px";
			createCookie("player_width",Math.round(orgplayerw*zoom),1);
            elem.style.width=screen.width+"px";
			sizeadj();
		}
	}

//player resize
	function sizeadj() {
		resizable_player.update_sizes();
	}


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

	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,domain){
	createCookie(name,"",-1,domain);
	}

window.addEventListener("DOMContentLoaded", function() { do_script() }, false);

// to skip agree screen
	createCookie("agreeterms","1",30);
// this cookie removes most add's
	if (!readCookie("noads")){createCookie("noads","1",30);window.location.reload(true)}
// notice and rotating add
	createCookie("np3","0",1);
	createCookie("dism_msg18","1",1);
	createCookie("dism_msg19","1",1);
	createCookie("dism_msg20","1",1);
	createCookie("dism_msg21","1",1);
	createCookie("dism_msg22","1",1);
	createCookie("dism_msg23","1",1);
//.user.js