☰

Chaturbate reloaded V2

For chaturbate New Look • See cam without being in chat • Write notes in thumbnails • See models on other camsites • Cam recording • Live thumbnail previews • Region and many more info in bio • Chat and bio cleanup • Status alert • Save media to disk • See who is broadcasting • Video controls • Ban/ignore rooms

您需要先安裝使用者腳本管理器擴展,如 Tampermonkey、Greasemonkey 或 Violentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 Tampermonkey 或 Violentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 Tampermonkey或 Violentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 Tampermonkey或 Userscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Chaturbate reloaded V2
// @name:de        Chaturbate reloaded V2
// @name:es        Chaturbate reloaded V2
// @name:it        Chaturbate reloaded V2
// @name:fr        Chaturbate reloaded V2
// @name:ua        Chaturbate reloaded V2
// @name:ro        Chaturbate reloaded V2
// @name:nl        Chaturbate reloaded V2
// @name:pl        Chaturbate reloaded V2
// @name:ja        Chaturbate reloaded V2
// @name:ko        Chaturbate reloaded V2
// @name:pt-PT     Chaturbate reloaded V2
// @name:zh        Chaturbate reloaded V2
// @description    For chaturbate New Look • See cam without being in chat • Write notes in thumbnails • See models on other camsites  •  Cam recording • Live thumbnail previews • Region and many more info in bio • Chat and bio cleanup • Status alert • Save media to disk • See who is broadcasting • Video controls • Ban/ignore rooms
// @description:de  Fur Chaturbate im neuen Look • Cam ansehen, ohne im Chat zu sein • Notizen in Vorschaubilder schreiben • Models auf anderen Cam-Seiten finden • Cam-Aufnahme • Live-Vorschau der Thumbnails • Region und weitere Infos in der Bio • Bereinigung von Chat und Bio • Status-Benachrichtigung • Medien lokal speichern • Sehen, wer gerade streamt • Videosteuerung • Räume sperren/ignorieren
// @description:es  Para Chaturbate Nuevo aspecto • Ver la cámara sin estar en el chat • Escribir notas en las miniaturas • Ver modelos en otros sitios de cámaras • Grabación de la cámara • Vistas previas de miniaturas en vivo • Región y mucha más información en la biografía • Limpieza de chat y biografía • Alerta de estado • Guardar contenido multimedia en el disco • Ver quién está transmitiendo • Controles de video • Salas bloqueadas/ignoradas
// @description:it  Per Chaturbate Nuovo look • Guarda la webcam senza essere in chat • Scrivi note nelle miniature • Guarda le modelle su altri siti di webcam • Registrazione webcam • Anteprime in diretta delle miniature • Regione e molte altre informazioni nella biografia • Pulizia chat e biografia • Avviso di stato • Salva i contenuti multimediali su disco • Guarda chi sta trasmettendo • Controlli video • Blocca/ignora le stanze
// @description:fr  Pour Chaturbate Nouveau look • Voir la webcam sans être dans le chat • Écrire des notes sur les miniatures • Voir les modèles sur d’autres sites de webcam • Enregistrement de la webcam • Aperçus en direct des miniatures • Région et bien plus d’infos dans la bio • Nettoyage du chat et de la bio • Alerte de statut • Enregistrer les médias sur le disque • Voir qui diffuse • Commandes vidéo • Bannir/ignorer les salons
// @description:ua  Новий вигляд для chaturbate • Перегляд камери без чату • Створення нотаток у мініатюрах • Перегляд моделей на інших сайтах з камерами • Запис з камери • Попередній перегляд мініатюр у реальному часі • Регіон та багато іншої інформації в біографії • Очищення чату та біографії • Сповіщення про статус • Збереження медіафайлів на диск • Перегляд того, хто транслює • Керування відео • Блокування/ігнорування кімнат
// @description:ro  Pentru Chaturbate New Look • Vezi camera fără a fi în chat • Scrie note în miniaturi • Vezi modele pe alte site-uri de camere • Înregistrare cameră • Previzualizări live ale miniaturilor • Regiune și multe alte informații în bio • Curățare chat și bio • Alertă de stare • Salvează fișiere media pe disc • Vezi cine transmite • Comenzi video • Interzice/ignorează camerele
// @description:nl  Voor Chaturbate New Look • Bekijk de webcam zonder in de chat te zijn • Schrijf notities in miniaturen • Bekijk modellen op andere camsites • Webcam opnemen • Live miniatuurvoorbeelden • Regio en nog veel meer informatie in de bio • Chat en bio opruimen • Statusmelding • Media opslaan op schijf • Zien wie er uitzendt • Videobediening • Kamers blokkeren/negeren
// @description:pl  Dla Chaturbate Nowy wygląd • Oglądanie kamery bez bycia na czacie • Pisanie notatek w miniaturach • Oglądanie modelek na innych stronach z kamerkami • Nagrywanie kamery • Podgląd miniatur na żywo • Region i wiele innych informacji w biografii • Czyszczenie czatu i biografii • Alert statusu • Zapisywanie multimediów na dysku • Zobacz, kto nadaje • Sterowanie wideo • Blokowanie/ignorowanie pokoi
// @description:ja  Chaturbate の新ルック • チャットに参加せずにカメラを見る • サムネイルにメモを書き込む • 他のカムサイトのモデルを見る • カメラ録画 • ライブサムネイルプレビュー • プロフィールに地域情報など多数 • チャットとプロフィールの整理 • ステータスアラート • メディアをディスクに保存 • 誰が配信しているかを確認 • ビデオコントロール • ルームの禁止/無視
// @description:ko  Chaturbate 새 디자인 • 채팅 참여 없이 캠 보기 • 썸네일에 메모 작성 • 다른 캠 사이트에서 활동하는 모델 보기 • 캠 녹화 • 실시간 썸네일 미리보기 • 프로필에 지역 및 더 많은 정보 추가 • 채팅 및 프로필 정리 • 상태 알림 • 미디어 저장 • 방송 중인 사람 보기 • 비디오 제어 • 방 차단/무시
// @description:pt-PT Para o novo visual do Chaturbate • Veja a transmissão sem estar no chat • Escreva notas nas miniaturas • Veja modelos noutros sites de webcam • Gravação de webcam • Pré-visualizações ao vivo das miniaturas • Região e muito mais informações na bio • Limpeza do chat e da bio • Alerta de estado • Guardar media no disco • Veja quem está a transmitir • Controlos de vídeo • Banir/ignorar salas
// @description:zh  Chaturbate 新界面 • 无需进入聊天室即可查看摄像头 • 在缩略图上添加备注 • 查看其他直播平台上的主播 • 摄像头录制 • 实时缩略图预览 • 个人简介中可显示地区等更多信息 • 清理聊天记录和个人简介 • 状态提醒 • 将媒体文件保存到磁盘 • 查看正在直播的主播 • 视频控制 • 屏蔽/忽略房间
// @version        1.1.0
// @namespace      chaturbate_goes_Ladroop
// @match          https://*chaturbate.com/*
// @match          https://*.chaturbate.com/*
// @exclude        https://secure.chaturbate.com/*
// @exclude        https://*chaturbate.com/security/*
// @exclude        https://*chaturbate.com/auth/*
// @exclude        https://*chaturbate.com/apps/*
// @exclude        https://*chaturbate.com/api/*
// @exclude        https://*chaturbate.com/b/*
// @exclude        https://*chaturbate.com/fullvideo/*
// @exclude        https://*chaturbate.com/accounts/followers/*
// @require        https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js
// @grant          window.focus
// @grant          GM_xmlhttpRequest
// @grant          GM_download
// @connect        translate.googleapis.com
// @connect        www.camsoda.com
// @connect        stripchat.com
// @connect        bongacams.com
// @connect        webchat.cam4.com
// @connect        cam4.com
// @connect        manifest-server.naiadsystems.com
// @connect        api-edge.myfreecams.com
// @connect        edgevideo.myfreecams.com
// @run-at         document-end
// @license	       MIT
// @copyright      2026 Ladroop
// ==/UserScript==

(function() {
    'use strict';
    if (!readCookie("AG_Key")){
        if (document.getElementById("age_gate_overlay")){return;}
    }
    document.body.setAttribute("usc","V2");
    var currpage=document.location.href;
    var roomname= currpage.split("/")[3];
    if (!readCookie("ssession")){
        localStorage.removeItem("regloaded");
        localStorage.removeItem("region_southamerica");
        localStorage.removeItem("region_other");
        localStorage.removeItem("region_northamerica");
        localStorage.removeItem("region_europe_russia");
        localStorage.removeItem("region_asia");
        createCookie("ssession","foo");
    }
    if (roomname=="messages"){
        if(window.opener){
            if (window.opener.innerWidth!=window.innerWidth){
                setTimeout(function(){
                    document.getElementById("desktop-spa-header").style.display="none";
                    document.getElementById("sidebar-holder").style.display="none";
                    document.getElementById("base").style.paddingLeft="0px";
                    document.getElementById("base").style.paddingTop="0px";
                },200);
                return;
            }
        }
    }
    if (roomname=="my_collection"){
        if (currpage.split("/")[4]=="detail"){
            if (document.getElementsByTagName("video").length>0){
                savedprvdownload();
            }
            return;
        }
    }
    setgenstyle();
    if (roomname=="photo_videos"){
        collectiondownload();
        return;
    }
    if (!document.getElementById("sidebar-holder")){return;}
    if (!document.getElementById("desktop-spa-header")){return;}
    var version=GM_info.script.version;
    var scriptname=GM_info.script.name;
    var i=0;
    var n=0;
    var stor="greg44609";
    var domain="https://"+window.location.hostname+"/";
    var thisfap="";
    var fapbr="";
    var cimg=new Image();
    var lt2=0;
    var usernoteslist = "";
    if (currpage.indexOf(stor)!=-1){document.location.href=domain;}
    var note='<svg style="height: 2.0em; width: 2.0em;" viewBox="0 0 12 12" xmlns="https://www.w3.org/2000/svg"><path fill="hsla(0, 100%, 50%, 0.8)" d="M5.5 2.00002H2C1.73478 2.00002 1.48043 2.10537 1.29289 2.29291C1.10536 2.48044 1 2.7348 1 3.00002V10C1 10.2652 1.10536 10.5196 1.29289 10.7071C1.48043 10.8947 1.73478 11 2 11H9C9.26522 11 9.51957 10.8947 9.70711 10.7071C9.89464 10.5196 10 10.2652 10 10V6.50002" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M9.25 1.24985C9.44891 1.05094 9.7187 0.939194 10 0.939194C10.2813 0.939194 10.5511 1.05094 10.75 1.24985C10.9489 1.44877 11.0607 1.71855 11.0607 1.99985C11.0607 2.28116 10.9489 2.55094 10.75 2.74985L6 7.49985L4 7.99985L4.5 5.99985L9.25 1.24985Z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>';
    var nonote='<svg style="height: 2.0em; width: 2.0em;" viewBox="0 0 12 12" xmlns="https://www.w3.org/2000/svg"><path fill="hsla(197, 10%, 98%, 0.3)" d="M5.5 2.00002H2C1.73478 2.00002 1.48043 2.10537 1.29289 2.29291C1.10536 2.48044 1 2.7348 1 3.00002V10C1 10.2652 1.10536 10.5196 1.29289 10.7071C1.48043 10.8947 1.73478 11 2 11H9C9.26522 11 9.51957 10.8947 9.70711 10.7071C9.89464 10.5196 10 10.2652 10 10V6.50002" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M9.25 1.24985C9.44891 1.05094 9.7187 0.939194 10 0.939194C10.2813 0.939194 10.5511 1.05094 10.75 1.24985C10.9489 1.44877 11.0607 1.71855 11.0607 1.99985C11.0607 2.28116 10.9489 2.55094 10.75 2.74985L6 7.49985L4 7.99985L4.5 5.99985L9.25 1.24985Z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>';
    var notegrey='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 12 12" role="img"><path stroke="#48484E" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M5.5 2H2a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V6.5"></path><path stroke="#48484E" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.25 1.25a1.06 1.06 0 0 1 1.5 1.5L6 7.5 4 8l.5-2z"></path></svg>';
    var xlogo='<svg class="svg" width="30" height="30" fill="none" viewBox="0 0 30 30"><path d="M9.47 6.77 15.3 0h-1.4L8.85 5.88 4.81 0H.15l6.11 8.9L.15 16h1.38l5.35-6.21L11.14 16h4.67L9.47 6.77Zm-1.9 2.2-.61-.88-4.93-7.05h2.12l3.98 5.69.62.88 5.17 7.4h-2.13L7.58 8.97Z" fill-rule="nonzero" fill-opacity="1" fill="black" stroke="none"></path></svg>';
    var sitelocation="";
    var username="anonymous";
    var supporter=false;
    var login=false;
    var pageType="whatever";
    var banusers=[];
    var noaccess=false;
    var hidurl=domain+"api/ts/roomlist/room-list/?&hidden=true&limit=90&offset=";
    var hprom=false;
    var hidoffset=0;
    var hiddenarray=[];
    var tr2="https://www.chaturbate.com/translate_a/";
    var observer3 = new MutationObserver(varea);
    var observerConfig3 = {attributes : true, attributeFilter : ['src'] };
    var region=["asia","europe_russia","northamerica","southamerica","other"];
    var niceregion=["Asia","Europe/Russia","North America","South America","Other (Australia, Africa, etc.)"];
    var rcount=0;
    var regoffset=0;
    var regioarray=[];
    var regiofetch=true;
    var biodata="";
    var openthumbname="";
    var fetching=0;
    var hlsfetching=false;
    var br="";
    var vfilter="brightness(100%) contrast(100%) invert(0%) saturate(100%) hue-rotate(0deg)";
    var ofils="";
    var vmirror="none";
    var pos1=0;
    var pos2=0;
    var pos3=0;
    var pos4=0;
    var pageobserver=new MutationObserver(pageevent);
    var pageobserverConfig ={attributes : true, attributeFilter : ['class'] };
    var thumbobserver1=new MutationObserver(addevent2);
    var thumbobserverConfig={subtree:true,childList:true, attributeFilter : ['alt']};
    var ctitle=document.title;
    var opennote="";
    var data="";
    var room_status="";
    var videoSrc="foo";
    var stream;
    var vidwidth=854;
    var hls = new Hls();
    var vidpausetime=0;
    var vidonpause=false;
    var gojpg=false;
    var fatalerror=0;
    var restarts=0;
    var pimg = new Image();
    var recording=false;
    var recpause=false;
    var mediaRecorder;
    var recordedBlobs=[];
    var blob = new Blob([]);
    var url = URL.createObjectURL(blob);
    var recname="";
    var stoppressed=false;
    var timerrecstop=false;
    var savetime=20;
    var rectime=0;
    var recparts=1;
    var recTimeoutID=0;
    var zeroData=0;
    var recwait=false;
    var prectime=0;
    var bitrate=2500000;
    var mimeTypes=['video/mp4; codecs="av01.0.04M.08, mp4a.40.2"',
                   'video/mp4; codecs="avc3.64001F, mp4a.40.2"',
                   'video/webm',
                   'video/webm'];
    var extentions=['.mp4',
                    '.mp4',
                    '.webm',
                    '.webm'];
    var vidcontainers=['video/mp4',
                       'video/mp4',
                       'video/webm',
                       'video/webm'];
    var mimeType=0;
    for(mimeType=0;mimeType < mimeTypes.length-1;mimeType++) {
        if (MediaRecorder.isTypeSupported(mimeTypes[mimeType])){break;}
    }
    var c1=0;
    var c2=0;
    var c3=0;
    var c4=0;
    var c5=0;
    var c6=0;
    var c7=0;
    var c7a=100;
    var c8=0;
    var c10=0;
    var firstentry=true;
    var twaiting=false;
    var chatrules="";
    var tabblink=false;
    var alarmrun=false;
    var roomstatus="";
    var oldroomstatus="";
    var roomthumbs="";
    var followstar="";
    var nrt=0;
    var scBusy=false;
    var csBusy=false;
    var bcBusy=false;
    var c4Busy=false;
    var smBusy=false;
    var mfcBusy=false;
    var zoomvalue=100;
    var vidposX=0;
    var vidposY=0;
    var hpos=50;
    var vpos=50;
    if (document.querySelector('[data-testid="close-entrance-terms"]')){
        document.querySelector('[data-testid="close-entrance-terms"]').click();
    }
    if (document.getElementsByClassName("dismiss_notice_tfa_and_email").length>0){
        document.getElementsByClassName("dismiss_notice_tfa_and_email")[0].click();
    }
    if (document.getElementsByClassName("siteNotice").length>0){
        var links = document.getElementsByClassName("siteNotice")[0].getElementsByTagName("a");
        for (n=0; n<links.length; n++){
            if (!links[n].hasAttribute("href")){
                links[n].click();
            }
        }
        n=0;
    }
    if (!document.hasFocus()){
        document.addEventListener("visibilitychange",headerReady);
        return;
    }
    headerReady();
    return;

    function headerReady(){
        document.removeEventListener("visibilitychange",headerReady);
        if (document.querySelector('[data-testid="header-top-row"]')){
            getUserinfo();
            return;
        }
        n++;
        if(n==100){return;}
        setTimeout(headerReady,100);
    }

    function getUserinfo(){
        refresher();
        var scripts=document.getElementsByTagName("script");
        for (n=0; n<scripts.length; n++){
            if(!scripts[n].hasAttribute("scr")){
                if (scripts[n].innerHTML.includes("Minimal extend implementation")){
                    var userinfo=scripts[n].innerHTML.split("logged_in_user: JSON.parse('")[1].split("')")[0];
                    if(userinfo=="null"){
                        break;
                    }
                    login=true;
                    var userinfojson=JSON.parse('"'+userinfo+'"').replaceAll('"','');
                    username=userinfojson.split('username: ')[1].split(',')[0];
                    if (userinfojson.split('is_supporter: ')[1].split(',')[0]=="true"){
                        supporter=true;
                    }
                    if (userinfojson.split('is_staff: ')[1].split(',')[0]=="true"){
                        alert("Please be nice Mr. Chaturbate staff. 😳");
                    }
                    break;
                }
            }
        }
        getsaving();
        makeScriptMenu();
    }

    function makeScriptMenu(){
        var newdiv=document.createElement('div');
        newdiv.id="holdpage";
        newdiv.className="holdpage";
        newdiv.style.display="block";
        document.getElementById("base").prepend(newdiv);
        var top="";
        if (login){
            top=document.querySelector('[data-testid="user-header-menu"]');
        }else{
            top=document.getElementsByClassName("HeaderTopRow__anon-buttons")[0];
        }
        newdiv=document.createElement('div');
        newdiv.id="scriptsettings";
        newdiv.className="HeaderUserProfileIconContainer";
        newdiv.title="Script menu";
        newdiv.innerHTML='<div class="HeaderUserProfileIcon" style="border-radius:25%;background:#a84808"><span class="HeaderUserProfileIcon__letter">&#128128</span></div>';
        newdiv.addEventListener("click",togglescriptMenu);
        top.prepend(newdiv);
        newdiv=document.createElement('div');
        newdiv.className="HeaderUserProfileIconContainer";
        newdiv.innerHTML='<div class="HeaderUserProfileIcon" style="border-radius:25%;background:#ffffff"><a title="Follow me on X" style="margin-top:19px;margin-left:13px" href="https://x.com/cbuserscript" target=_blank class="HeaderUserProfileIcon__letter">'+xlogo+'</a></div>';
        top.prepend(newdiv);
        makeunlock();
        moreoptions();
        getignorelist();
        modsidebar();
        bottomlinks();
        setTimeout(getPagetype,100);
    }

    function makeunlock(){
        var locicon=document.getElementById("desktop-spa-header").getElementsByTagName("button")[0].cloneNode(true);
        locicon.id="toplockicon";
        locicon.addEventListener("click",toggletopbarlock);
        locicon.style.transform="rotate(90deg)";
        document.getElementsByClassName("HeaderTopRow__home-link-container")[0].style.display="flex";
        document.getElementsByClassName("HeaderTopRow__home-link-container")[0].prepend(locicon);
        if (readCookie("topLock")){
           topbarlock();
        }
    }

    function toggletopbarlock(){
        if (readCookie("topLock")){
            topbarunlock();
            eraseCookie("topLock");
        }else{
            topbarlock();
            createCookie("topLock","foo");
        }
    }

    function topbarlock(){
        document.getElementById("desktop-spa-header").style.position="absolute";
        document.getElementById("desktop-spa-header").getElementsByTagName("button")[0].style.position="fixed";
        document.getElementsByClassName("HeaderTopRow__home-link-container")[0].style.marginLeft="48px";
        document.getElementById("toplockicon").style.transform="rotate(-90deg)";
    }
    function topbarunlock(){
        document.getElementById("desktop-spa-header").style.position="fixed";
        document.getElementById("desktop-spa-header").getElementsByTagName("button")[0].style.position="relative";
        document.getElementsByClassName("HeaderTopRow__home-link-container")[0].style.marginLeft="0px";
        document.getElementById("toplockicon").style.transform="rotate(90deg)";
    }

    function bottomlinks(){
        var statusrow=document.querySelector('[data-testid="status-cams"]');
        if (statusrow){
            var newelem=document.createElement('dd');
            newelem.innerHTML='<a href="/exhibitionist-cams/">Exhibitionist Cams</a>';
            statusrow.getElementsByTagName("dl")[0].appendChild(newelem);
        }
    }

    function togglescriptMenu(){
        if(document.getElementById("scriptcontrols").style.display=="none"){
            document.getElementById("scriptcontrols").style.display="block";
            document.getElementById("main").addEventListener("click",togglescriptMenu);
        }else{
            document.getElementById("scriptcontrols").style.display="none";
            document.getElementById("main").removeEventListener("click",togglescriptMenu);
        }
    }

    function modsidebar(){
        if (document.getElementById("SidebarNavButton__following")){
            document.getElementById("SidebarNavButton__following").style.cursor="pointer";
            document.getElementById("SidebarNavButton__following").addEventListener("click",function(){
                if (roomname != "followed-cams"){return;}
                document.location.reload();
            });
        }
    }

    function pageevent(){
        if (sitelocation==document.location.href.split("/")[3]){return;}
        document.getElementById("holdpage").style.display="block";
        pageobserver.disconnect();
        cleanuppage();
        getPagetype();
    }

    function getPagetype(){
        setTimeout(getPagetype2,100);
    }

    function getPagetype2(){
        currpage=document.location.href;
        roomname= currpage.split("/")[3];
        sitelocation=roomname;
        var newpageType="whatever";
        if ((document.getElementsByClassName("ExpandedGenderNav").length >0)||(document.getElementsByClassName("GenderNavigationDropdown").length >0)){
            newpageType="thumbs";
        }
        if (document.getElementById("main")){
            var mainClass=document.getElementById("main").classList;
            if (mainClass.contains("chat_followed_cams")){newpageType="thumbs";}
            if (mainClass.contains("chat_followed_cams_offline")){newpageType="thumbs";}
            if (mainClass.contains("chat_watch_history")){newpageType="thumbs";}
            if (mainClass.contains("roomPage")){newpageType="profile";}
            if (mainClass.contains("tags")){newpageType="tags";}
            if (mainClass.contains("chat_roomlogin")){newpageType="password";}
            if (mainClass.contains("chat_profile")){newpageType="ppage";}
            pageobserver.observe(document.getElementById("main"),pageobserverConfig);
        }
        if (document.querySelector('[ts="RoomDeniedMessageWrapper"]')){newpageType="noaccess";}
        if ((pageType=="thumbs")&&(newpageType=="thumbs")){return;}
        pageType=newpageType;
        thumbobserver1.disconnect();
        if (login){
            document.getElementById("ignore").style.display="none";
            if ((pageType=="profile")||(pageType=="password")||(pageType=="ppage")||(pageType=="noaccess")){
                document.getElementById("ignore").style.display="block";
            }
        }
        if (pageType!="thumbs"){
            document.getElementById("holdpage").style.display="none";
        }
        if (pageType=="thumbs"){
            setTimeout(function(){document.getElementById("holdpage").style.display="none";},4000);//!
            setTimeout(thumbpageset,500);
        }
        if (pageType=="profile"){
            profilepageset();
        }
        if (pageType=="ppage"){
            profilepageset();
        }
        if (pageType=="password"){
            roomname=currpage.split("/")[4];
            passwordfollow();
        }
        if (pageType=="noaccess"){
            bannedroom();
        }
    }

    function thumbpageset(){
        buildnotepop();
        getnoteslist();
    }

    function profilepageset(){
        n=0;
        bioreadytest();
    }

    function bioreadytest(){
        if (document.getElementsByClassName('BioTabContentDesktop__title').length>0){
            if(document.getElementsByClassName('BioTabContentDesktop__title')[0].innerHTML.toLowerCase().includes(roomname)){
                setTimeout(dobiothings, 800);
                n=0;
                return;
            }
        }
        n++;
        if(n==200){return;}
        setTimeout(bioreadytest, 100);
    }

    function reloadoption(){
        if (document.getElementById("reloadoption")){return;}
        var loc=document.getElementsByClassName("EvolveGenderNavButton")[0];
        if (!loc){
            loc=document.getElementsByClassName("ButtonTabs")[0];
        }
        if (!loc){return;}
        var newelem=document.createElement('span');
        newelem.className="ButtonTabs";
        newelem.style.marginLeft="8px";
        newelem.innerHTML='<a id="reloadoption">⟳</a><a id="reloadp1option">1⇐</a>';
        loc.style.display="flex";
        loc.appendChild(newelem);
        document.getElementById("reloadoption").addEventListener("click", function(){window.location.reload();});
        document.getElementById("reloadp1option").addEventListener("click", function(){
            if (document.getElementsByClassName("Pagination__page").length !=0){
                document.getElementsByClassName("Pagination__page")[0].click();
            }else{
                if (document.getElementsByClassName("Pagination__list").length !=0){
                    document.getElementsByClassName("Pagination__list").getElementsByTagName("li")[1].click();
                }
            }
        });
    }

    function cleanuppage(){
        observer3.disconnect();
        if (document.getElementById("notepop")){
            document.getElementById("notepop").remove();
        }
        if (document.getElementById("vcontr")){
            document.getElementById("vcontr").remove();
        }
        if (document.getElementById("ccontr")){
            document.getElementById("ccontr").remove();
        }
        if (document.getElementById("clean")){
            document.getElementById("clean").remove();
        }
        if (document.getElementById("infore")){
            document.getElementById("infore").remove();
        }
        if (document.getElementById("controls")){
            document.getElementById("controls").remove();
        }
        if (document.getElementById("chatcontrols")){
            document.getElementById("chatcontrols").remove();
        }
        if (document.getElementById("rulespop")){
            document.getElementById("rulespop").remove();
        }
        if (document.getElementById("vup")){
            document.getElementById("vup").remove();
        }
        if (document.getElementById("vdown")){
            document.getElementById("vdown").remove();
        }
    }

    function moreoptions(){
        var newelem=document.createElement('div');
        newelem.id="scriptcontrols";
        newelem.style.display="none";
        newelem.className="scriptset";
        document.querySelector('[data-testid="header-top-row"]').appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="scriptinfo";
        newelem.innerHTML=scriptname+" Version:"+version;
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.innerHTML="--Script settings--<div style='float:right'>Off ↔ On</div>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h1";
        newelem.innerHTML="Thumbnail zoom : <input type='range' id='a1' min=0 max=1 value=1 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h2";
        newelem.innerHTML="Preview rooms : <input type='range' id='a2' min=0 max=1 value=1 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        if (supporter){
            newelem.style.display="none";
        }
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h3";
        newelem.innerHTML="Open rooms in new tab : <input type='range' id='a3' min=0 max=1 value=1 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h4";
        if (!login){
            newelem.style.display="none";
        }
        newelem.innerHTML="Auto refresh followed : <input type='range' id='a4' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h6";
        newelem.innerHTML="Big thumbnails : <input type='range' id='a6' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h5";
        newelem.innerHTML="Hide male/trans : <input type='range' id='a5' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h9";
        newelem.innerHTML="480px snapshots : <input type='range' id='a9' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h7";
        newelem.innerHTML="Auto save recordings every 20 mins : <input type='range' id='a7' min=0 max=1 value=1 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.id="h8";
        newelem.style.display="none";
        if (mimeType==0){
            newelem.style.display="block";
        }
        newelem.innerHTML="Video codec for recording, av01 <-> avc3 : <input type='range' id='a8' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;accent-color: #f47321;'>";
        document.getElementById("scriptcontrols").appendChild(newelem);
        if(login){
            newelem=document.createElement('span');
            newelem.id="saved";
            newelem.style.cursor="pointer";
            newelem.innerHTML="Save all settings.";
            newelem.addEventListener("click", savesetting );
            document.getElementById("scriptcontrols").appendChild(newelem);
            newelem=document.createElement('span');
            newelem.id="clear";
            newelem.style.cursor="pointer";
            newelem.innerHTML="Clear all saved settings.";
            newelem.addEventListener("click", clearsettings );
            document.getElementById("scriptcontrols").appendChild(newelem);
            newelem=document.createElement('span');
            newelem.id="clear";
            newelem.style.cursor="pointer";
            newelem.innerHTML="Manage ban's.";
            newelem.addEventListener("click", bantoggle );
            document.getElementById("scriptcontrols").appendChild(newelem);
            newelem=document.createElement('span');
            newelem.innerHTML="<select id='banusers' class='darkselect' style='width:220px'></select><br><input id='unbanbut' type='button' value='Unban' style='margin:8px 0px 0px 0px'><input id='permbut' type='button' value='Make permanent' style='margin:8px 15px 0px 8px'>";
            newelem.id="banlist";
            newelem.style.display="none";
            document.getElementById("scriptcontrols").appendChild(newelem);
            newelem=document.createElement('span');
            newelem.innerHTML="Ban/ignore this room.";
            newelem.id="ignore";
            newelem.style.cursor="pointer";
            newelem.addEventListener("click", banignore );
            document.getElementById("scriptcontrols").appendChild(newelem);
        }
        document.getElementById("a1").addEventListener("change",zoomoff);
        document.getElementById("a2").addEventListener("change",anionoff);
        document.getElementById("a3").addEventListener("change",newtabon);
        document.getElementById("a4").addEventListener("change",refreshoff);
        document.getElementById("a5").addEventListener("change",hidemt);
        document.getElementById("a6").addEventListener("change",bigthumb);
        document.getElementById("a7").addEventListener("change",recautosave);
        document.getElementById("a8").addEventListener("change",recvp9);
        document.getElementById("a9").addEventListener("change",smallsnap);
        setsw();
    }

    function setsw(){
        if (localStorage.getItem("smallsnap")){
            document.getElementById("a9").value=1;
        }else{
            document.getElementById("a9").value=0;
        }
        if (localStorage.getItem("recvp9")){
            document.getElementById("a8").value=1;
        }else{
            document.getElementById("a8").value=0;
        }
        if (localStorage.getItem("recautosave")){
            document.getElementById("a7").value=0;
        }else{
            document.getElementById("a7").value=1;
        }
        if (localStorage.getItem("bigthumb")){
            document.getElementById("a6").value=1;
        }else{
            document.getElementById("a6").value=0;
        }
        if (localStorage.getItem("hidemt")){
            document.getElementById("a5").value=1;
        }else{
            document.getElementById("a5").value=0;
        }
        if (localStorage.getItem("refreshoff")){
            document.getElementById("a4").value=1;
        }else{
            document.getElementById("a4").value=0;
        }
        if (localStorage.getItem("newtabon")){
            document.getElementById("a3").value=0;
        }else{
            document.getElementById("a3").value=1;
        }
        if (localStorage.getItem("animationoff")){
            document.getElementById("a2").value=0;
        }else{
            document.getElementById("a2").value=1;
        }
        if (localStorage.getItem("zoomoff")){
            document.getElementById("a1").value=0;
        }else{
            document.getElementById("a1").value=1;
        }
        setclass();
    }

    function setclass(){
        document.body.classList.remove("zoom");
        document.body.classList.remove("bigThumb");
        document.body.classList.remove("hidemt");
        if(localStorage.getItem("bigthumb")){
            document.body.classList.add("bigThumb");
        }
        if(localStorage.getItem("hidemt")){
            document.body.classList.add("hidemt");
        }
        if(!localStorage.getItem("zoomoff")){
            document.body.classList.add("zoom");
        }
    }

    function smallsnap(){
        if (document.getElementById("a9").value==1){
            localStorage.setItem("smallsnap","foo");
        }else{
            localStorage.removeItem("smallsnap");
        }
    }
    function recvp9(){
        if (document.getElementById("a8").value==1){
            localStorage.setItem("recvp9","foo");
            mimeType=1;
        }else{
            localStorage.removeItem("recvp9");
            mimeType=1;
        }
    }
    function recautosave(){
        if (document.getElementById("a7").value==0){
            localStorage.setItem("recautosave","foo");
            savetime=200000;
        }else{
            localStorage.removeItem("recautosave");
            savetime=20;
        }
    }
    function bigthumb(){
        if (document.getElementById("a6").value==1){
             localStorage.setItem("bigthumb","foo");
        }else{
            localStorage.removeItem("bigthumb");
        }
        setclass();
    }
    function zoomoff(){
        if (document.getElementById("a1").value==0){
            localStorage.setItem("zoomoff","foo");
        }else{
            localStorage.removeItem("zoomoff");
        }
        setclass();
    }
    function hidemt(){
        if (document.getElementById("a5").value==1){
            localStorage.setItem("hidemt","foo");
        }else{
            localStorage.removeItem("hidemt");
        }
        chkmtpage();
        setclass();
    }
    function refreshoff(){
        if (document.getElementById("a4").value==1){
            localStorage.setItem("refreshoff","foo");
        }else{
            localStorage.removeItem("refreshoff");
        }
    }
    function newtabon(){
        if (document.getElementById("a3").value==0){
             localStorage.setItem("newtabon","foo");
        }else{
            localStorage.removeItem("newtabon");
        }
    }
    function anionoff(){
        if (document.getElementById("a2").value==0){
            localStorage.setItem("animationoff","foo");
        }else{
            localStorage.removeItem("animationoff");
        }
    }

    function savesetting(){
        document.getElementById("saved").removeEventListener("click", savesetting );
        var theme_name="lightmode";
        if (readCookie("theme_name")){
            theme_name=readCookie("theme_name");
        }
        var bigthumb=0;
        if (localStorage.getItem("bigthumb")){
            bigthumb=1;
        }
        var hidemt=0;
        if (localStorage.getItem("hidemt")){
            hidemt=1;
        }
        var newtabon=0;
        if (localStorage.getItem("newtabon")){
            newtabon=1;
        }
        var refreshoff=0;
        if (localStorage.getItem("refreshoff")){
            refreshoff=1;
        }
        var zoomoff=0;
        if (localStorage.getItem("zoomoff")){
            zoomoff=1;
        }
        var animationoff=0;
        if (localStorage.getItem("animationoff")){
            animationoff=1;
        }
        var cleanprof=0;
        if (localStorage.getItem("pclean")){
            cleanprof=1;
        }
        var recautosave=0;
        if (localStorage.getItem("recautosave")){
            recautosave=1;
        }
        var recvp9=0;
        if (localStorage.getItem("recvp9")){
            recvp9=1;
        }
        var smallsnap=0;
        if (localStorage.getItem("smallsnap")){
            smallsnap=1;
        }
        var isTheaterMode=localStorage.getItem("isTheaterMode");
        var defaultVideoWidth =localStorage.getItem("defaultVideoWidth");
        var videoControls =localStorage.getItem("videoControls");
        var hpfltopen=localStorage.getItem("hpfltopen");
        var allstring="good boy#refreshoff#"+refreshoff+
            "#bigthumb#"+bigthumb+
            "#hidemt#"+hidemt+
            "#newtabon#"+newtabon+
            "#zoomoff#"+zoomoff+
            "#animationoff#"+animationoff+
            "#cleanprof#"+cleanprof+
            "#recautosave#"+recautosave+
            "#recvp9#"+recvp9+
            "#smallsnap#"+smallsnap+
            "#isTheaterMode#"+isTheaterMode+
            "#defaultVideoWidth#"+defaultVideoWidth+
            "#videoControls#"+videoControls+
            "#theme_name#"+theme_name+
            "#hpfltopen#"+hpfltopen;
        var url=domain+"api/notes/for_user/"+stor+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "text", allstring );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            body: data
        }).then(function(){document.getElementById("saved").innerHTML="Settings saved";setTimeout(function(){document.getElementById("saved").innerHTML="Save all settings.";document.getElementById("saved").addEventListener("click", savesetting );},2000);});
    }

    function clearsettings(){
        document.getElementById("clear").removeEventListener("click", clearsettings );
        var url=domain+"api/notes/for_user/"+stor+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "text", "" );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            body: data
        }).then(function(){document.getElementById("clear").innerHTML="Saved settings removed.";setTimeout(function(){document.getElementById("clear").innerHTML="Clear all saved settings.";document.getElementById("clear").addEventListener("click", clearsettings );},2000);});
    }

    function getsaving(){
        if (!login){
            localStorage.removeItem("login");
            return;
        }else{
            if (localStorage.getItem("login")){
                return;
            }
        }
        localStorage.setItem("login","foo");
        var url=domain+"api/notes/for_user/"+stor+"/";
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    return;
                }
                response.json().then(function(data) {
                    if (data.text == null){return;}
                    restoresettings(data.text);
                });
            });
    }

    function restoresettings(data){
        var resave=false;
        if (data.indexOf("good boy")!=0){return;}
        if (data.indexOf("refreshoff#")!=-1){
            var refreshoff=data.split("refreshoff#")[1].split("#")[0];
            localStorage.setItem("refreshoff","foo");
            if (refreshoff==0){localStorage.removeItem("refreshoff");}
        }
        if (data.indexOf("newtabon#")!=-1){
            var newtabon=data.split("newtabon#")[1].split("#")[0];
            localStorage.setItem("newtabon","foo");
            if (newtabon==0){localStorage.removeItem("newtabon");}
        }
        if (data.indexOf("hidemt#")!=-1){
            var hidemt=data.split("hidemt#")[1].split("#")[0];
            localStorage.setItem("hidemt","foo");
            if (hidemt==0){localStorage.removeItem("hidemt");}
        }
        if (data.indexOf("bigthumb#")!=-1){
            var bigthumb=data.split("bigthumb#")[1].split("#")[0];
            localStorage.setItem("bigthumb","foo");
            if (bigthumb==0){localStorage.removeItem("bigthumb");}
        }
        if (data.indexOf("zoomoff#")!=-1){
            var zoomoff=data.split("zoomoff#")[1].split("#")[0];
            localStorage.setItem("zoomoff","foo");
            if (zoomoff==0){localStorage.removeItem("zoomoff");}
        }
        if (data.indexOf("animationoff#")!=-1){
            var animationoff=data.split("animationoff#")[1].split("#")[0];
            localStorage.setItem("animationoff","foo");
            if (animationoff==0){localStorage.removeItem("animationoff");}
        }
        if (supporter){
            localStorage.removeItem("animationoff");
        }
        if (data.indexOf("cleanprof#")!=-1){
            var cleanprof=data.split("cleanprof#")[1].split("#")[0];
            localStorage.setItem("pclean","foo");
            if (cleanprof==0){localStorage.removeItem("pclean");}
        }
        if (data.indexOf("recautosave#")!=-1){
            var recautosave=data.split("recautosave#")[1].split("#")[0];
            localStorage.setItem("recautosave","foo");
            if (recautosave==0){localStorage.removeItem("recautosave");}
        }
        if (data.indexOf("recvp9#")!=-1){
            var recvp9=data.split("recvp9#")[1].split("#")[0];
            localStorage.setItem("recvp9","foo");
            if (recvp9==0){localStorage.removeItem("recvp9");}
        }
        if (data.indexOf("smallsnap#")!=-1){
            var smallsnap=data.split("smallsnap#")[1].split("#")[0];
            localStorage.setItem("smallsnap","foo");
            if (smallsnap==0){localStorage.removeItem("smallsnap");}
        }
        if (data.indexOf("isTheaterMode#")!=-1){ /// {"isTheaterMode":false}
            var isTheaterMode=data.split("isTheaterMode#")[1].split("#")[0];
            if (!jsontest(isTheaterMode)){resave=true;isTheaterMode='{"isTheaterMode":false}';}
            localStorage.setItem("isTheaterMode",isTheaterMode);
        }
        if (data.indexOf("defaultVideoWidth#")!=-1){
            var defaultVideoWidth=data.split("defaultVideoWidth#")[1].split("#")[0];
            if (!jsontest(defaultVideoWidth)){resave=true;defaultVideoWidth='{"videoWidth":893,"videoHeight":502.3125,"lastChosenVideoWidth":902,"lastChosenChatWidth":962}';}
            localStorage.setItem("defaultVideoWidth",defaultVideoWidth);
        }
        if (data.indexOf("videoControls#")!=-1){
            var videoControls=data.split("videoControls#")[1].split("#")[0];
            if (!jsontest(videoControls)){resave=true;videoControls='{"volume":60,"isMuted":false}';}
            localStorage.setItem("videoControls",videoControls);
        }
        var exp=new Date().getTime()+86400000;
        if (data.indexOf("hpfltopen#")!=-1){
            var hpfltopen=data.split("hpfltopen#")[1].split("#")[0];
            hpfltopen=hpfltopen.split('expiration":')[0]+'expiration":'+exp+'}';
            if (!jsontest(hpfltopen)){resave=true;hpfltopen='{"value":"true","expiration":2780331592470}';}
            localStorage.setItem("hpfltopen",hpfltopen);
        }
        if (data.indexOf("theme_name#")!=-1){
            var theme_name=data.split("theme_name#")[1].split("#")[0];
            createCookie("theme_name",theme_name,2,"chaturbate.com");
        }
        var outtime=500;
        if (resave){
            outtime=1000;
            savesetting();
        }
        setTimeout(function(){document.location.reload();},outtime);
    }

    function jsontest(jsonstr){
        if (jsonstr==""){return false;}
        if (jsonstr==null){return false;}
        try {
            JSON.parse(jsonstr);
            return true;
        } catch(e) {
            return false;
        }
    }

    function dobiothings(){
        if(pageType=="ppage"){
            if (currpage.split("model=").length==1){return;}
            roomname=currpage.split("model=")[1].split("&")[0];
            if (roomname==username){return;}
            rebuildbio();
        }else{
            afterrebuild();
        }
    }

    function afterrebuild(){
        if (login){
            if((pageType=="ppage")){
                document.getElementsByClassName("BioTabContentDesktop__title")[0].innerHTML="<a href='"+domain+roomname+"?tab=bio' id=biotop>"+tocap(roomname)+"'s Bio (Go to the cam page)</a>";
            }else{
                document.getElementsByClassName("BioTabContentDesktop__title")[0].innerHTML="<a href='"+domain+"p/"+username+"?tab=bio&model="+roomname+"' id=biotop>"+tocap(roomname)+"'s Bio and Webcam (Go to the bio)</a>";
                setTimeout(function(){document.title=tocap(roomname) + "'s Campage";},3000);
            }
            document.getElementById("biotop").addEventListener("click", function(event){window.location.replace(this.href);event.stopPropagation();event.preventDefault();return false;});
            document.getElementById("biotop").style.position="relative";
            document.getElementById("biotop").style.zIndex="9999";
        }
        makevidcontrol();
        cleaninit();
        linkfix();
        info(true);
        buildnotepop();
        if (pageType=="profile"){
            getnoteslist();
        }
        if (document.getElementsByTagName("video").length>0){
            getvid();
            vreset();
            iagree();
        }
    }

    function iagree(){
        triggerMouseEvent (document.getElementsByClassName("inputDiv")[0], "mousedown");
        if (document.getElementsByClassName("acceptRulesButton").length>0){
            document.getElementsByClassName("acceptRulesButton")[0].click();
        }
        if (document.querySelector('[data-testid="dismissible-message-dismiss"]')){
            document.querySelector('[data-testid="dismissible-message-dismiss"]').click();
        }
    }

    function triggerMouseEvent (node, eventType) {
        var clickEvent = new Event(eventType, { bubbles: true, cancelable: true });
        node.dispatchEvent (clickEvent);
    }

    function setgenstyle(){
        var style = document.createElement('style');
        style.setAttribute('type', 'text/css');
        style.textContent =
            ".BioContents{position:relative !important}"+
            ".cbLogo {display:none !important}"+
            ".overlay {display:none !important;}"+
            "#TheaterModeRoomContents {cursor:default !important;}"+
            ".PhotosetThumbnail__overlay:after {background-color:rgba(0, 0, 0, 0) !important;}"+
            ".PhotosetThumbnail__overlay:before {background-color:rgba(0, 0, 0, 0) !important;filter:blur(0px)!important;inset:0}"+
            ".photoVideoDetailSection img{filter: blur(0px) !important;}"+
            ".lockOverlayBg.rgba {background-color:rgba(0, 0, 0, 0) !important;}"+
            ".lockOverlay img {z-index:5 !important;}"+
            ".lockOverlay div {z-index:6 !important;}"+
            "#room_follow_button {cursor:pointer !important}"+
            ".SatisfactionScore__voteButton {padding:4px !important}"+
            ".profplayer{z-index:3;position:absolute;top:10px;right:10px;border:1px solid rgb(221, 221, 221);border-radius:4px;box-shadow:0px 0px 32px rgba(0, 0, 0, 0.32)}"+
            ".darkMode .profplayer{z-index:3;position:absolute;top:10px;right:10px;border:1px solid rgb(29, 29, 29);border-radius:4px;box-shadow:0px 0px 32px rgba(255, 255, 255, 0.22)}"+
            ".profdivplayer{position:absolute;top:10px;right:10px;overflow:hidden;resize:horizontal;direction:rtl;border:1px solid rgb(221, 221, 221);border-radius:4px;box-shadow:0px 0px 32px rgba(0, 0, 0, 0.32);background-color:rgba(0, 0, 0, 0.32)}"+
            ".rulespop {cursor:pointer;z-index:3;top:10px;left:10px;box-shadow:0px 0px 32px rgba(0, 0, 0, 0.32);border-radius:4px;border:1px solid rgb(221, 221, 221);background-color:rgb(200, 200, 200);position:absolute; display:none; white-space: pre-line; text-align: left; line-height: 1.4; height: auto; width:500px; padding: 10px 10px 10px 10px; box-sizing: border-box; overflow-wrap: break-word; word-break: break-word; padding: 15px}"+
            ".darkMode .profdivplayer{position:absolute;top:10px;right:10px;overflow:hidden;resize:horizontal;direction:rtl;border:1px solid rgb(29, 29, 29);border-radius:4px;box-shadow:0px 0px 32px rgba(255, 255, 255, 0.22);background-color:rgba(255, 255, 255, 0.22)}"+
            ".darkMode .darkselect{background-color: #202c39 !important; color:#b3b3b3 !important; border-color:#2d3e50 !important}"+
            ".tinput {background-color: #dde9f5 !important; color:#5e81a4 !important; border-color:#8bb3da !important}"+
            ".darkMode .tinput {background-color: #202c39 !important; color:#b3b3b3 !important; border-color:#2d3e50 !important}"+
            ".proftext {width: 350px; height: 45px; line-height: 14px; border-width: 1px; border-style: solid; border-color: #acacac; border-radius: 4px; padding: 7px 8px; overflow: auto;background-color: rgb(230, 230, 230);color:#000;min-width:200px;min-height:45px}"+
            ".darkMode .proftext{width: 350px; height: 45px; line-height: 14px; border-width: 1px; border-style: solid; border-color: #2d3e50; border-radius: 4px; padding: 7px 8px; overflow: auto;background-color: rgb(20,20,20);color:#fff;min-width:200px;min-height:45px}"+
            ".profbutton {border-width: 1px; border-style: solid; border-color: #acacac; border-radius: 4px;background-color: rgb(230, 230, 230);color:#000;cursor: pointer;}"+
            ".darkMode .profbutton {border-color: #dddddd; border-radius: 4px;background-color: rgb(20,20,20);color:#fff;}"+
            ".profbutton:hover:active {transform: scale(0.92)}"+
            ".cleanprof .profpos {display:none !important}"+
            ".cleanprof .profmar {margin-top:0px !important;}"+
            ".cleanprof .profcur{cursor:default !important }"+
            ".translated {background-color:#FFFFE0;color:red;margin-left:10px;padding:0px 5px 0px 5px;text-shadow:0px 0px !important}"+
            ".darkMode .translated {background-color:#000020;color:red;margin-left:10px;padding:0px 5px 0px 5px;text-shadow:0px 0px !important}"+
            ".popclass {background-color:rgb(255, 255, 211)}"+
            ".darkMode .popclass {background-color:rgb(30, 30, 10)}"+
            ".smallemo img.emoticonImage {max-height:22px !important;}"+
            ".tabBar {overflow:visible !important}"+
            ".zoom .MoreRoomsLikeThis__grid {margin-left:17px}"+
            ".MoreRooms{overflow:visible !important}"+
            ".RoomCardGrid {overflow:visible}"+
            ".RoomCardGrid{--room-card-grid-column-width: 200px}"+
            ".bigThumb .RoomCardGrid{--room-card-grid-column-width: 302px}"+
            ".HomepagePaginatedRoomlist__searchResultsGrid{--room-card-grid-column-width: 200px !important}"+
            ".bigThumb .HomepagePaginatedRoomlist__searchResultsGrid{--room-card-grid-column-width: 302px !important}"+
            ".FYPViewAll__header{z-index:25;}"+
            ".RoomCard{border-radius:var(--spacing-md) !important;z-index:0;transition: .7s}"+
            ".content{overflow: visible; !important}"+
            ".GenderNavigationDropdown {z-index:21}"+
            "#desktop-spa-header{z-index:40 !important;}"+
            ".zoom:not(.nozoom) .CategoryHeaderEvolve {margin-right:24px}"+
            ".zoom:not(.nozoom) .RoomCardGrid {margin-right:24px}"+
            ".zoom:not(.nozoom) .homepageFilterPanel:not(.inactive) {margin-left:-24px}"+
            ".zoom:not(.nozoom):not(.bigThumb) .RoomCard:hover {transform: scale(1.37);z-index:20}"+
            ".zoom:not(.nozoom).bigThumb .RoomCard:hover {transform: scale(1.23);z-index:20}"+
            ".V2UShidden_pill {color:#0000FF !important}"+
            ".darkMode .V2UShidden_pill {color:#5555FF !important}"+
            ".hidemt dd .sub_category:nth-of-type(3){display:none !important}"+
            ".hidemt dd .sub_category:nth-of-type(5){display:none !important}"+
            ".hidemt .col5 dd:nth-of-type(3){display:none !important}"+
            ".hidemt .col5 dd:nth-of-type(5){display:none !important}"+
            ".hidemt .ExpandedGenderNav button:nth-of-type(3){display:none !important}"+
            ".hidemt .ExpandedGenderNav button:nth-of-type(5){display:none !important}"+
            ".hidemt .GenderNavigationDropdown div:nth-of-type(3){display:none !important}"+
            ".hidemt .GenderNavigationDropdown div:nth-of-type(5){display:none !important}"+
            ".hidemt .hidThumb {display:none !important}"+
            ".NoResultsFoundMessage div:nth-of-type(2){display:none !important}"+
            ".FollowRecommendedRoomlist{display:none !important}"+
            ".HomepageFallbackRoomlist{display:none !important}"+
            ".DesktopRoomlistRoot__separator{display:none !important}"+
            ".notepop {display:none;position:absolute;overflow:hidden;color:rgb(100, 100, 100);background-color:rgb(255, 255, 255);border: 1px solid rgb(221, 221, 221);border-radius:9px;width:188px;height:170px;z-index:999;box-shadow:0px 0px 32px rgba(0, 0, 0, 0.32)}"+
            ".darkMode .notepop {background-color:rgb(180, 180, 180);border: 1px solid rgb(100, 100, 100);box-shadow:0px 0px 32px rgba(255, 255, 255, 0.42)}"+
            ".notepopb1 {background-color:rgb(221, 221, 221);font-weight:bold;height:15px;font-size:15px;padding:8px;text-align:left}"+
            ".noteinput {height:60px;font-size:12px;border:1px solid rgb(172, 172, 172);border-radius:10px;background-color:rgb(255, 255, 255);resize:none;padding:5px;width:85%;}"+
            ".darkMode .noteinput {background-color:rgb(0, 0, 0);color:rgb(200, 200, 200);border:1px solid rgb(200, 200, 200)}"+
            ".scriptset {position:absolute;width:340px;padding:12px;top:80px;right:10px;z-index:9999;background-color:#fff;border:1px solid #efefef; border-radius:8px; box-shadow:0 0 8px 0 rgba(0,0,0,.2);z-index:105}"+
            ".darkMode .scriptset {position:absolute;width:340px;padding:12px;top:80px;right:10px;z-index:9999;background-color:#17202a;border:1px solid #2d3e50; border-radius:8px; box-shadow:0px 4px 16px rgba(0,0,0,.24);}"+
            ".scriptset span{text-align: left; width: 310px;color: #fff; background-color: #0c6a93;padding: 4px 10px 3px;  position: relative;  border-radius: 10px; float: right;margin: 2px;}"+
            ".HeaderUserProfileMenu {z-index:104 !important}"+
            ".holdpage {position: fixed;  display: block; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0); z-index: 200; cursor: wait;}"+
            ".InChatMessage {display:none}";
        document.getElementsByTagName('head')[0].appendChild(style);
    }

    function getnoteslist(){
        if(!login){usernoteslist="";addevent2();return;}
        var url=domain+"api/notes/usernames/";
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200){
                    return;
                }
                response.json().then(function(data) {
                    usernoteslist=data;
                }).then(addevent2());
            });
    }

    function searchenable(){
        if (!document.querySelector('[ts="CountryFilterWrapper"]')){return;}
        document.getElementsByClassName("homepageFilterPanel")[0].removeEventListener("click",searchenable);
        var regiocheck=document.querySelector('[ts="CountryFilterWrapper"]').querySelectorAll('[data-testid="region-dropdown-checkbox"]');
        for (n=0; n<regiocheck.length; n++){
            regiocheck[n].removeAttribute("disabled");
        }
        var disableclass=document.querySelector('[ts="CountryFilterWrapper"]').getElementsByClassName("Checkbox__label-container");
        for (n=0; n<disableclass.length; n++){
            disableclass[n].classList.remove("Checkbox__disabled");
        }
        document.getElementsByClassName("homepageFilterPanel")[0].addEventListener("click",searchenable);
    }

    function addevent2(){
        if(document.querySelectorAll('[scriptName="camslut"]').length != 0){
            if(document.querySelectorAll('[scriptName="camslut"]').length == document.querySelectorAll('[data-testid="room-card"]').length){
                return;
            }
        }
        document.getElementById("holdpage").style.display="block";
        currpage=document.location.href;
        roomname= currpage.split("/")[3];
        thumbobserver1.disconnect();
        setTimeout(addevent2a,200);
    }

    function chkmtpage(){
        if (!localStorage.getItem("hidemt")){return;}
        var gen1=document.location.href.split("/")[3];
        if (gen1=="followed-cams"){return;}
        var gen2=document.location.href.split("/")[4];
        if ((gen1=="male-cams")||(gen2=="male")||(gen1=="trans-cams")||(gen2=="trans")){
            sessionStorage.removeItem("genderFilter");
            document.location.href=domain;
        }
    }

    function addevent2a(){
        chkmtpage();
        reloadoption();
        if(document.getElementById("reloadoption")){
            document.getElementById("reloadp1option").style.display="none";
            if (document.location.search.includes("page=")){
                document.getElementById("reloadp1option").style.display="inline-flex";
            }
        }
        var newelem="";
        if (document.getElementById("unfollowit")){
            document.getElementById("unfollowit").remove();
        }
        if (document.location.href.split("/")[4]=="offline"){
            newelem=document.createElement('a');
            newelem.id="unfollowit";
            newelem.innerHTML="Unfollow all";
            newelem.addEventListener("click",unfollowthispage);
            document.getElementsByClassName("ButtonTabs")[0].appendChild(newelem);
        }
        if (currpage!=document.location.href){
            notepopclose();
        }
        currpage=document.location.href;
        document.body.classList.remove("nozoom");
        if (currpage.split("/")[3]=="foryou"){
            document.body.classList.add("nozoom");
        }
        var tags=document.querySelectorAll('[data-testid="room-card"]');
        if (localStorage.getItem("ignoredusers")){
            banusers=localStorage.getItem("ignoredusers").split(",");
        }
        for (n=0; n<tags.length; n++){
            var thumbroomname=tags[n].getElementsByClassName("RoomCardUserDetails__username")[0].innerHTML;
            if (banusers.indexOf(thumbroomname)!=-1){
                tags[n].style.display="none";
            }
            if (roomname!="followed-cams"){
                var gender=tags[n].getElementsByClassName("RoomCardUserDetails__gender")[0].getElementsByTagName("path")[0].getAttribute("fill");
                if ((gender.includes("trans"))||(gender.includes("#0199CB"))){
                    tags[n].classList.add("hidThumb");
                }
            }
            if(!tags[n].getAttribute("scriptName")){
                tags[n].setAttribute("scriptName", "camslut");
                if (!supporter){
                    tags[n].querySelector('[data-testid="room-card-image-anchor"]').addEventListener("mouseenter", moveimg);
                    tags[n].querySelector('[data-testid="room-card-image-anchor"]').addEventListener("mouseleave", moveimgstop);
                }
                if (login){
                    tags[n].querySelector('[data-testid="room-card-image-anchor"]').title="Visit "+thumbroomname+"'s chatroom.";
                    tags[n].getElementsByClassName("RoomCardThumbnail__image")[0].addEventListener("click", function(event){
                        if (localStorage.getItem("newtabon")){
                            return;
                        }
                        event.stopPropagation();
                        event.preventDefault();
                        openInNewTab(this.parentNode.href,"_blank");
                    });
                    tags[n].getElementsByClassName("RoomCardPillContainer")[0].addEventListener("click", function(event){event.preventDefault();});
                    tags[n].getElementsByClassName("cardTitle")[0].addEventListener("click", function(event){event.stopPropagation();});
                    tags[n].getElementsByClassName("cardTitle")[0].style.cursor="default";

                    tags[n].getElementsByClassName("RoomCardUserDetails")[0].name=domain+"p/"+username+"/?tab=bio&model="+thumbroomname;
                    tags[n].getElementsByClassName("RoomCardUserDetails")[0].title="Visit "+thumbroomname+"'s bio.";
                    tags[n].getElementsByClassName("RoomCardUserDetails")[0].addEventListener("click", function(event){
                        event.stopPropagation();
                        event.preventDefault();
                        var target="_self";
                        if (!localStorage.getItem("newtabon")){
                            target="_blank";
                        }
                        openInNewTab(this.name, target);
                    });
                }else{
                    tags[n].addEventListener("click", function(event){
                        if (localStorage.getItem("newtabon")){
                            return;
                        }
                        event.stopPropagation();
                        event.preventDefault();
                        openInNewTab(this.querySelector('[data-testid="room-card-username"]').href,"_blank");
                    });
                }
                if (usernoteslist!=""){
                    newelem=document.createElement('div');
                    if (usernoteslist.usernames.indexOf(thumbroomname)!=-1){
                        newelem.innerHTML=note;
                    }else{
                        newelem.innerHTML=nonote;
                    }
                    newelem.style.position="absolute";
                    newelem.style.top="0px";
                    newelem.style.left="0px";
                    newelem.addEventListener("click", function(event){event.stopPropagation();shownote(this.name,event.pageY,event.pageX);});
                    newelem.style.cursor="pointer";
                    newelem.setAttribute("name", thumbroomname);
                    newelem.name=thumbroomname;
                    newelem.title="User notes";
                    tags[n].appendChild(newelem);
                }
            }
        }
        hidoffset=0;
        hiddenarray=[];
        if (document.location.href.split("/")[3]=="hidden-cams"){
            showhidden4();
            return;
        }
        if (document.location.href.split("/")[3]=="followed-cams"){
            if (document.location.href.split("/")[4]!="offline"){
                showhidden2();
                return;
            }
        }
        startthumbobserver();
        document.getElementById("holdpage").style.display="none";
    }

    function openInNewTab(href,target){
        var a=document.createElement('a');
        a.style.display = 'none';
        a.target=target;
        a.rel='noopener noreferrer';
        a.href=href;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
    }

    function startthumbobserver(){
        searchenable();
        var node="";
        if (pageType=="profile"){
            if (document.querySelector('[ts="MoreRoomsLikeThisWrapper"]')){
                node=document.querySelector('[ts="MoreRoomsLikeThisWrapper"]');
            }
        }
        if (pageType=="thumbs"){
            if (document.getElementsByClassName("FYPContainer").length>0){
                node=document.getElementsByClassName("FYPContainer")[0];
            }else{
                node=document.getElementsByClassName("DesktopRoomlistRoot")[0];
            }
        }
        if (node !=""){
            thumbobserver1.observe(node,thumbobserverConfig);
        }
    }

    function showhidden2(){
        if (hprom){return;}
        hprom=true;
        var url=hidurl+hidoffset*90;
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    hprom=false;
                    return;
                }
                response.json().then(function(data){
                    if (data.rooms != null){
                        var hiddenlist=data.rooms;
                        for (n=0; n<hiddenlist.length; n++){
                            hiddenarray.push(hiddenlist[n].username);
                        }
                        var pages=Math.ceil(data.total_count/90);//1.....
                        hidoffset++;//0.....
                        if (hidoffset!=pages){
                            hprom=false;
                            showhidden2();
                        }else{
                            hprom=false;
                            showhidden3();
                        }
                    }
                });
            });
    }

    function showhidden3(){
        var tags=document.querySelector('[data-testid="room-list-container"]').querySelectorAll('[data-testid="room-card"]');
        for (n=0; n<tags.length; n++){
            var name=tags[n].getElementsByClassName("RoomCardUserDetails__username")[0].innerHTML;
            if (tags[n].querySelector('[title="Hidden"]')){
                tags[n].querySelector('[title="Hidden"]').remove();
            }
            if (hiddenarray.indexOf(name)!=-1){
                var newelem=document.createElement('div');
                newelem.className="evolveMode ButtonV2 ButtonV2--secondary RoomCardPill RoomCardLabelPill RoomCardLabelPill--spy V2UShidden_pill";
                newelem.title="Hidden";
                newelem.innerHTML="hidden";
                newelem.addEventListener("click", function(event){event.stopPropagation();});
                tags[n].getElementsByClassName('RoomCardPillContainer')[0].prepend(newelem);
            }
        }
        startthumbobserver();
        document.getElementById("holdpage").style.display="none";
    }

    function showhidden4(){
       var tags=document.querySelector('[data-testid="room-list-container"]').querySelectorAll('[data-testid="room-card"]');
        for (n=0; n<tags.length; n++){
            if (tags[n].querySelector('[title="Hidden"]')){
                tags[n].querySelector('[title="Hidden"]').remove();
            }
            var newelem=document.createElement('a');
            newelem.className="evolveMode ButtonV2 ButtonV2--secondary RoomCardPill RoomCardLabelPill RoomCardLabelPill--spy V2UShidden_pill";
            newelem.title="Hidden";
            newelem.innerHTML="hidden";
            newelem.addEventListener("click", function(event){event.stopPropagation();});
            tags[n].getElementsByClassName("RoomCardPillContainer")[0].prepend(newelem);
        }
        startthumbobserver();
        document.getElementById("holdpage").style.display="none";
    }

    function shownote(name,pageY,pageX){
        if(document.getElementById("notepop").style.display=="block"){
            notepopclose();
            if (openthumbname==name){
                return;
            }
        }
        document.getElementById("notepop").style.height="170px";
        document.getElementById("notearea").value="";
        document.getElementById("notenote").innerHTML=notegrey + " Note";
        document.getElementById("notepopLink").style.color="grey";
        opennote="";
        openthumbname=name;
        document.getElementById("notearea").innerHTML="";
        document.getElementById("notepop").style.top=pageY+100+"px";
        document.getElementById("notepop").style.left=pageX+20+"px";
        document.getElementById("notepop").style.display="block";
        document.getElementById("notepopName").style.color="grey";
        document.getElementById("notepopName").innerHTML=openthumbname;
        setTimeout(function(){document.getElementById("main").addEventListener("click",notepopclose);},100);
        var url=domain+"api/notes/for_user/"+openthumbname+"/";
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    document.getElementById("notearea").value="!! This room is banned or deleted !!";
                    return;
                }
                response.json().then(function(data){
                    if (data.text != null){
                        document.getElementById("notearea").value=data.text;
                        opennote=data.text;
                        if (usernoteslist.usernames.indexOf(openthumbname)==-1){
                            usernoteslist.usernames.push(openthumbname);
                            updatedm2();
                        }
                    }
                    getusercolor();
                });
            });
    }

    function getusercolor(){
        var url=domain+"api/messaging/profile/"+openthumbname+"/";
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    return;
                }
                response.json().then(function(data){
                    if (data.can_pm){document.getElementById("notepopLink").style.color="green";}
                    var Bcolor="#939393";
                    if (data.sitewide_user.has_tokens){Bcolor="#69a";}
                    if (data.sitewide_user.tipped_recently){Bcolor="#1e5cfb";}
                    if (data.sitewide_user.tipped_alot_recently){Bcolor="#be6aff";}
                    if (data.sitewide_user.tipped_tons_recently){Bcolor="#804baa";}
                    document.getElementById("notepopName").style.color=Bcolor;
                });
            });
    }

    function buildnotepop(){
        var newelem=document.createElement('span');
        newelem.id="notepop";
        newelem.className="notepop";
        document.getElementById("footer-holder").appendChild(newelem);
        newelem=document.createElement('div');
        newelem.className="notepopb1";
        newelem.innerHTML='<span id="notepopName" style="text-Overflow: ellipsis; overflow:hidden; width:150px; height:20px; display:inline-block;cursor:pointer " ></span><span><img src="https://web.static.mmcdn.com/tsdefaultassets/close-gray.svg" style="position: absolute; height: 13px; width: 13px; right: 8px;" title="Close" id="noteclose"></span>';
        document.getElementById("notepop").appendChild(newelem);
        document.getElementById("notepopName").addEventListener("click", function(){var target="_self";if (!localStorage.getItem("newtabon")){target="_blank";}window.open(domain+"p/"+username+"/?tab=bio&model="+openthumbname, target);});
        document.getElementById("noteclose").addEventListener("click", notepopclose);
        newelem=document.createElement('div');
        newelem.style.border="inherit";
        newelem.style.height="15px";
        newelem.style.fontSize="12px";
        newelem.style.padding="8px";
        newelem.style.textAlign="left";
        newelem.style.cursor="pointer";
        newelem.addEventListener("click", function(){opendm2(openthumbname);});
        newelem.id="notepopLink";
        newelem.innerHTML='<img src="https://web.static.mmcdn.com/tsdefaultassets/popout-grey-d.svg" height="12px" width="12px"><b> Open DM in new window</b>';
        document.getElementById("notepop").appendChild(newelem);
        newelem=document.createElement('div');
        newelem.style.color="rgb(100, 100, 100)";
        newelem.style.height="10px";
        newelem.style.fontSize="12px";
        newelem.style.padding="8px";
        newelem.style.textAlign="left";
        newelem.id="notenote";
        newelem.innerHTML=notegrey + " Note";
        document.getElementById("notepop").appendChild(newelem);
        newelem=document.createElement('textarea');
        newelem.className="noteinput";
        newelem.id="notearea";
        newelem.setAttribute("placeholder", "Enter notes about this user (only seen by you)");
        newelem.setAttribute("spellcheck", false);
        newelem.addEventListener("input",openbutton);
        newelem.id="notearea";
        document.getElementById("notepop").appendChild(newelem);
        newelem=document.createElement('div');
        newelem.id="notecancelsubmit";
        document.getElementById("notepop").appendChild(newelem);
        newelem=document.createElement("div");
        newelem.className="evolveMode ButtonV2 ButtonV2--secondary ButtonV2--small ControlPanel__actionButton";
        newelem.style.marginRight="7px";
        newelem.style.marginTop="10px";
        newelem.addEventListener("click",closebutton);
        newelem.innerHTML='Cancel';
        document.getElementById("notecancelsubmit").appendChild(newelem);
        newelem=document.createElement("div");
        newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode";
        newelem.style.marginLeft="7px";
        newelem.addEventListener("click",savenote);
        newelem.innerHTML="Save";
        document.getElementById("notecancelsubmit").appendChild(newelem);
    }

    function savenote(){
        var notetext=document.getElementById("notearea").value;
        var url=domain+"api/notes/for_user/"+openthumbname+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "text", notetext );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            body: data
        }).then(aftersave);
    }

    function aftersave(){
        var notetext=document.getElementById("notearea").value;
        var doupdate=false;
        if ((opennote=="")||(notetext=="")){
            doupdate=true;
        }
        opennote=notetext;
        closebutton();
        if (doupdate){updatedm();}
    }

    function notepopclose(){
        document.getElementById("main").removeEventListener("click",notepopclose);
        document.getElementById("notepop").style.display="none";
    }

    function openbutton(){
        document.getElementById("notepop").style.height="215px";
        document.getElementById("notenote").innerHTML=notegrey + " Note (unsaved)";
        document.getElementById("notearea").value=document.getElementById("notearea").value.replace("$"," "+new Date().toLocaleDateString()+" ");
        if(opennote==document.getElementById("notearea").value){
            closebutton();
        }
    }
    function closebutton(){
        document.getElementById("notenote").innerHTML=notegrey + " Note";
        document.getElementById("notepop").style.height="170px";
        document.getElementById("notearea").value=opennote;
    }

    function opendm2(that){
        var dmurl="messages/";
        if (document.getElementById("dmListIconRoot")){dmurl="dm/";}
        var url=domain+dmurl+that;
        var dmwindow=window.open(url,that,'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1000,height=800');
        dmwindow.onload = function(){
            this.addEventListener('unload', function(){setTimeout(function(){updatedm();},1000);});
        };
    }

    function updatedm(){
        var url=domain+"api/notes/usernames/";
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200){
                    return;
                }
                response.json().then(function(data) {
                    usernoteslist=data;
                }).then(updatedm2);
            });
    }

    function updatedm2(){
        var tags=document.querySelectorAll('[title="User notes"]');
        for (n=0; n<tags.length; n++){
             if (usernoteslist.usernames.indexOf(tags[n].getAttribute("name"))!=-1){
                 tags[n].innerHTML=note;
             }else{
                 tags[n].innerHTML=nonote;
             }
         }
    }

    function moveimg(){
        if(localStorage.getItem("animationoff")){return;}
        thisfap=this;
        if (thisfap.parentNode.getElementsByClassName("RoomCardPillContainer__lastBroadcast").length!=0){return;}
        if (thisfap.parentNode.getElementsByClassName("V2UShidden_pill").length!=0){return;}
        fapbr=thisfap.getElementsByTagName("img")[0].src.split("/")[4].split("?")[0];
        cimg.addEventListener("load",regetimg);
        lt2=new Date().getTime();
        cimg.src = "https://jpeg.live.mmcdn.com/minifwap/"+fapbr+"?f="+lt2;
    }

    function moveimgstop(){
        cimg.removeEventListener("load",regetimg);
    }

    function regetimg(){
        var lt=new Date().getTime()-lt2;
        if (lt>180){lt=180;}
        thisfap.getElementsByTagName("img")[0].src=cimg.src;
        setTimeout(function(){lt2=new Date().getTime();cimg.src = "https://jpeg.live.mmcdn.com/minifwap/"+fapbr+"?f="+lt2;}, 200-lt);
    }

    function refresher(){
        document.addEventListener("visibilitychange", function(){
            if (document.getElementById("chat-tab-default")){
                document.getElementById("chat-tab-default").click();
            }
            if (document.hidden){return;}
            if (document.location.href.split("/")[3]=="followed-cams"){
                if (document.location.href.split("/")[4]!="offline"){
                    if (localStorage.getItem("refreshoff")){
                        document.location.reload();
                    }
                }
            }
            setsw();
        });
    }

    function tabpm(){
        if (document.visibilityState=="visible"){return;}
        if(!document.getElementById("message-tab-default").getElementsByTagName("span")[0].textContent.includes("(")){return;}
        if (tabblink==true){return;}
        ctitle=document.title;
        tabblink=true;
        tabblinker();
    }

    function tabblinker(){
        if (document.title == "!! !! !!"){
            document.title = document.getElementById("message-tab-default").getElementsByTagName("span")[0].textContent;
        }else{
            document.title = "!! !! !!";
        }
        if ((document.visibilityState=="visible")||(!document.getElementById("message-tab-default").getElementsByTagName("span")[0].textContent.includes("("))){
            document.title=ctitle;
            tabblink=false;
        }else{
            setTimeout(tabblinker,500);
        }
    }

    function makevidcontrol(){
        var newelem="";
        var slistyle="text-align: left; width: 310px;margin-right: 4px;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: 0px; right: 1px; float: right; border-radius: 4px; display: inline;";
        var cbutstyle="margin-right: 5px;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;right: 1px; float: right; border-radius: 4px; cursor: pointer; display: inline;";
        var place2=document.getElementsByClassName("RoomTabBar__roomActionWrapper")[0];
        var menuplace=document.getElementsByClassName("tabBar")[0];
        if(pageType=="ppage"){
            newelem=document.createElement('div');
            newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode";
            newelem.innerHTML="Follow";
            newelem.setAttribute("title", "Follow the bitch.");
            newelem.addEventListener("click", followbut);
            newelem.id="followbut";
            newelem.style.display="none";
            place2.appendChild(newelem);
            newelem=document.createElement('div');
            newelem.className="evolveMode ButtonV2 ButtonV2--secondary ButtonV2--small";
            newelem.innerHTML="Unfollow";
            newelem.setAttribute("title", "Dump her.");
            newelem.addEventListener("click", unfollowbut);
            newelem.id="unfollowbut";
            newelem.style.display="none";
            place2.appendChild(newelem);
            newelem=document.createElement('div');
            newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--success ButtonV2--small ButtonV2--anchor JoinFanClubButton";
            newelem.innerHTML="Join Fan Club";
            newelem.addEventListener("click", function(){
                var fcwindow= window.open(domain+"fanclub/join/"+roomname+"/?source=SupporterSourceJoinFanClubButton","");
                fcwindow.onload = function(){
                    fcwindow.addEventListener('unload', function(){setTimeout(function(){
                        document.getElementById("fanclubbut").style.display="none";
                        document.getElementById("fanclubmembut").style.display="none";
                        newinfo();},1000);});
                };
            });
            newelem.id="fanclubbut";
            newelem.style.display="none";
            place2.appendChild(newelem);
            newelem=document.createElement('div');
            newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--success ButtonV2--small ButtonV2--anchor JoinFanClubButton";
            newelem.innerHTML="Member";
            newelem.style.backgroundColor="#009900";
            newelem.id="fanclubmembut";
            newelem.style.display="none";
            place2.appendChild(newelem);
            newelem=document.createElement('div');
            newelem.className="evolveMode ButtonV2 ButtonV2--secondary ButtonV2--small";
            newelem.innerHTML=document.getElementsByClassName("SatisfactionRating")[0].innerHTML;
            document.getElementsByClassName("SatisfactionRating")[0].remove();
            place2.appendChild(newelem);
        }
        newelem=document.createElement('div');
        newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode";
        newelem.style.display="none";
        newelem.innerHTML="Chat Controls On/Off";
        newelem.addEventListener("click", ccontrol);
        newelem.id="ccontr";
        place2.prepend(newelem);
        newelem=document.createElement('div');
        newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode";
        newelem.innerHTML="Video Controls On/Off";
        newelem.style.display="none";
        newelem.addEventListener("click", vcontrol);
        newelem.id="vcontr";
        place2.prepend(newelem);
        newelem=document.createElement('div');
        newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode";
        newelem.innerHTML="Clean Profile = On";
        newelem.style.display="none";
        newelem.id="clean";
        newelem.addEventListener("click", cleancookie);
        place2.prepend(newelem);
        newelem=document.createElement('div');
        newelem.className="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode";
        newelem.innerHTML="Reload Info";
        newelem.addEventListener("click", newinfo);
        if (pageType=="noaccess"){
            newelem.style.display="none";
        }
        newelem.id="infore";
        place2.prepend(newelem);
        newelem=document.createElement('span');
        newelem.id="controls";
        newelem.style.display="none";
        newelem.style.position="absolute";
        newelem.style.border="2px solid rgb(244, 115, 33)";
        newelem.style.borderRadius="6px";
        newelem.style.width="340px";
        newelem.style.padding="12px";
        newelem.style.top="50px";
        newelem.style.right="420px";
        newelem.style.zIndex="10";
        if ((pageType=="ppage")||(pageType=="noaccess")){
            newelem.style.zIndex="3";
            newelem.style.right="915px";
            newelem.style.top="120px";
        }
        newelem.setAttribute("class","popclass");
        menuplace.appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        newelem.innerHTML="RESET ALL";
        newelem.addEventListener("click",vreset);
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        newelem.innerHTML="MIRROR";
        newelem.addEventListener("click",mirror);
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        newelem.innerHTML="INVERT";
        newelem.addEventListener("click",invert);
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        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=50 max=250 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=25 max=225 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", cbutstyle);
        newelem.innerHTML="SNAPSHOT";
        newelem.id="snapbut";
        newelem.addEventListener("click",snapshot);
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        newelem.innerHTML="STOP RECORDING";
        newelem.id="stopbut";
        newelem.addEventListener("click",recstop);
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        newelem.innerHTML="RECORD";
        newelem.id="recbut";
        newelem.addEventListener("click",recstart);
        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", cbutstyle);
        newelem.innerHTML="HIDE CONTROL PANEL";
        newelem.id="vcontr2";
        newelem.addEventListener("click",vcontrol);
        document.getElementById("controls").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", cbutstyle);
        newelem.id="rectime";
        newelem.style.display="none";
        newelem.style.cursor="default";
        newelem.innerHTML="REC(1): 00:00:00";
        document.getElementById("controls").appendChild(newelem);
        if ((pageType=="noaccess")||(pageType=="ppage")){return;}
        newelem=document.createElement('div');
        newelem.id="chatcontrols";
        newelem.style.display="none";
        newelem.style.position="absolute";
        newelem.style.border="2px solid rgb(244, 115, 33)";
        newelem.style.borderRadius="6px";
        newelem.style.width="340px";
        newelem.style.padding="12px";
        newelem.style.top="50px";
        newelem.style.right="10px";
        newelem.style.zIndex="99";
        newelem.setAttribute("class","popclass");
        menuplace.appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Small emoticons : <input type='range' id='c1' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Notice : <input type='range' id='c2' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Subject change : <input type='range' id='c3' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Mod/fan enter-leave : <input type='range' id='c4' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        if (document.location.href.split(".").length>2){newelem.style.display="none";}//only in english
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Grey user chat : <input type='range' id='c5' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Moderator chat : <input type='range' id='c6' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Lovense messages : <input type='range' id='c8' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Tips smaller than : <input class='tinput' type='number' id='c7a' min='2' max='1000' value='100' style='width: 4em;height:11px;cursor: pointer; '> tokens.<input type='range' id='c7' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Translate chat to: <select id='language' class='darkselect'></select><input type='range' id='c10' min=0 max=1 value=0 style='width: 40px;height:11px;cursor: pointer;float: right;'>";
        document.getElementById("chatcontrols").appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", slistyle);
        newelem.style.margin="2px";
        newelem.innerHTML="Tokens received : <span id='tclear' style='cursor:pointer'>  (Clear)</span><span id='c9' style='width: 40px;height:11px;float: right; color:black'>0</span>";
        document.getElementById("chatcontrols").appendChild(newelem);
        tr2=tr2.replace("www.chaturbate","translate.googleapis")+"single?client=gtx&sl=auto&tl=";
        var languages=["Afrikaans","Albanian","Arabic","Armenian","Azerbaijani","Balinese","Basque","Belarusian","Bengali","Bosnian","Bulgarian","Cantonese","Catalan","Chinese","Corsican","Croatian","Czech","Danish","Dutch","English","Estonian","Filipino","Finnish","French","Georgian","German","Greek","Hebrew","Hindi","Hungarian","Icelandic","Indonesian","Irish","Italian","Japanese","Javanese","Kazakh","Korean","Latvian","Limburgan","Lithuanian","Luxembourgish","Macedonian","Maltese","Mongolian","Myanmar","Norwegian","Papiamento","Persian","Polish","Portuguese","Punjabi","Romanian","Russian","Sanskrit","Serbian","Sicilian","Slovak","Slovenian","Somali","Spanish","Sundanese","Swahili","Swedish","Tamil","Thai","Turkish","Ukrainian","Urdu","Uzbek","Vietnamese","Yiddish"];
        var langcode=["af","sq","ar","hy","az","ban","eu","be","bn","bs","bg","yue","ca","zh","co","hr","cs","da","nl","en","et","fil","fi","fr","ka","de","el","he","hi","hu","is","id","ga","it","ja","jv","kk","ko","lv","li","lt","lb","mk","mt","mn","my","no","pap","fa","pl","pt","pa","ro","ru","sa","sr","scn","sk","sl","so","es","su","sw","sv","ta","th","tr","uk","ur","uz","vi","yi"];
        for(i=0;i < languages.length;i++) {
            var option=document.createElement('option');
            option.textContent=languages[i];
            option.value=langcode[i];
            document.getElementById("language").appendChild(option);
        }
    }

    function startvidzoom(){
        if (document.getElementById("TheaterModePlayer").style.height!="auto"){
            if(document.getElementById("chat-player").style.height=="auto"){
                document.getElementById("chat-player").style.height="100%";
                document.getElementById("chat-player").style.width="100%";
                document.getElementById("chat-player").style.left="0px";
                document.getElementById("chat-player").style.top="0px";
                zoomvalue=100;
            }
            return;
        }
        document.getElementsByTagName("video")[0].addEventListener("wheel",scrollvidzoom);
        document.getElementsByTagName("video")[0].addEventListener("mousedown",pullvidzoom);
        document.getElementsByTagName("video")[0].addEventListener("mouseup",endpullvidzoom);
    }
    function endvidzoom(){
        document.getElementsByTagName("video")[0].removeEventListener("wheel",scrollvidzoom);
        document.getElementsByTagName("video")[0].removeEventListener("mousedown",pullvidzoom);
        document.getElementsByTagName("video")[0].removeEventListener("mouseup",endpullvidzoom);
        document.getElementsByTagName("video")[0].removeEventListener("mousemove",movevidzoom);
        document.getElementsByTagName("video")[0].style.cursor="default";
    }
    function scrollvidzoom(event){
        event.preventDefault();
        if (event.deltaY > 0){zoomvalue=zoomvalue-12;}else{zoomvalue=zoomvalue+12;}
        if (zoomvalue<100){zoomvalue=100;}
        if (zoomvalue>500){zoomvalue=500;}
        vidzoom();
    }
    function pullvidzoom(event){
        vidposX=event.pageX;
        vidposY=event.pageY;
        document.getElementsByTagName("video")[0].style.cursor="grabbing";
        document.getElementsByTagName("video")[0].addEventListener("mousemove",movevidzoom);
    }
    function endpullvidzoom(){
        document.getElementsByTagName("video")[0].style.cursor="default";
        document.getElementsByTagName("video")[0].removeEventListener("mousemove",movevidzoom);
    }
    function movevidzoom(event){
        var movevidX=vidposX-event.pageX;
        var movevidY=vidposY-event.pageY;
        vidposX=event.pageX;
        vidposY=event.pageY;
        hpos=hpos+movevidX/10;
        vpos=vpos+movevidY/10;
        if (hpos<0){hpos=0;}
        if (vpos<0){vpos=0;}
        if (hpos>100){hpos=100;}
        if (vpos>100){vpos=100;}
        vidzoom();
    }
    function vidzoom(){
        document.getElementById("chat-player").style.height="auto";
        document.getElementById("chat-player").style.width=zoomvalue+"%";
        var windowwidth=parseInt(document.getElementById("VideoPanel").style.width);
        var videowidth=windowwidth*zoomvalue/100;
        var videoheight=videowidth*0.562;
        var windowheight=windowwidth*0.562;
        var posshifth=(videowidth-windowwidth)*hpos/100;
        var posshiftv=(videoheight-windowheight)*vpos/100;
        document.getElementById("chat-player").style.left="-"+posshifth+"px";
        document.getElementById("chat-player").style.top="-"+posshiftv+"px";
    }

    function followbut(){
        var url=domain+"follow/follow/"+roomname+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "location", "FollowButton" );
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+roomname+"/",
            body: data
        }).then(function(){
        document.getElementById("followbut").style.display="none";
        document.getElementById("unfollowbut").style.display="inline-flex";
        });
    }

    function unfollowbut(){
        var url=domain+"follow/unfollow/"+roomname+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "location", "FollowButton" );
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+roomname+"/",
            body: data
        }).then(function(){
        document.getElementById("unfollowbut").style.display="none";
        document.getElementById("followbut").style.display="inline-flex";
        });
    }

    function snapshot(){
        document.getElementById("snapbut").removeEventListener("click",snapshot);
        document.getElementById("snapbut").style.color="red";

        var video = document.getElementsByTagName('video')[0];
        var canvas = document.createElement('canvas');
        var ctx = canvas.getContext('2d', { alpha: false });
        ctx.reset();
        canvas.width = video.videoWidth;
        canvas.height = video.videoHeight;
        var imgqual="0.95";
        var fontsize=12;
        if (video.videoWidth < video.videoHeight){
            fontsize=6;
        }
        if (localStorage.getItem("smallsnap")){
            imgqual="0.75";
            if (video.videoWidth > video.videoHeight){
                canvas.height = 480;
                canvas.width=parseInt(video.videoWidth*480/video.videoHeight);
            }else{
                canvas.width = 480;
                canvas.height = parseInt(video.videoHeight*480/video.videoWidth);

            }
        }
        ctx.font=fontsize*canvas.height/480+"px Georgia";
        ctx.drawImage(video, 0, 0,video.videoWidth,video.videoHeight,0,0,canvas.width,canvas.height);
        ctx.fillStyle = "white";
        ctx.fillText(roomname+"@chaturbate. Made with chaturbate reloaded userscript by Ladroop.",10,canvas.height-10);
        var starttime=new Date().toISOString().split(".")[0]+"GMT";
        starttime=starttime.replaceAll(":","-");
        var snapname=roomname+"-"+starttime+".jpg";
        canvas.toBlob(function(blob) {
                GM_download({
                    url: blob,
                    name: snapname,
                    onload: imgdlready
                });
        }, 'image/jpeg', imgqual);
    }

    function imgdlready(){
        document.getElementById("snapbut").style.color="white";
        document.getElementById("snapbut").addEventListener("click",snapshot);
    }

    function getvid(){
        observer3.observe(document.getElementsByTagName("video")[0], observerConfig3);
        varea();
    }

    function varea(){
        var vnode=document.getElementsByTagName("video")[0];
        if((pageType=="ppage")||(pageType=="noaccess")){
            vnode.style.filter=vfilter;
            vnode.style.transform=vmirror;
            return vnode;
        }
        if (vnode.src){
            vnode.addEventListener("mouseover",startvidzoom);
            vnode.addEventListener("mouseout",endvidzoom);

            document.getElementsByClassName("resizeHandle")[0].addEventListener("mouseup",vidzoom);
            vnode.style.filter=vfilter;
            vnode.style.transform=vmirror;
            document.getElementById("vcontr").style.display="inline-flex";
        }else{
            if (recording){
                setTimeout(function(){
                    if (!vnode.src){
                        recstop();
                        setTimeout(function(){
                            if (!vnode.src){
                                document.getElementById("vcontr").style.display="none";
                                document.getElementById("controls").style.display="none";
                            }
                        },2000);
                    }
                },2000);
            }else{
                document.getElementById("vcontr").style.display="none";
                document.getElementById("controls").style.display="none";
            }
        }
        return(vnode);
    }

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

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

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

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

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

	function mirror(){
		if (varea().style.transform=="none"){
            vmirror="matrix(-1, 0, 0, 1, 0, 0)";
			varea();

		}else{
            vmirror="none";
			varea();
		}
	}

	function vreset(){
        vfilter="brightness(100%) contrast(100%) invert(0%) saturate(100%) hue-rotate(0deg)";
        vmirror="none";
  		varea();
 		document.getElementById("myRange").value=100;
		document.getElementById("myRange1").value=100;
		document.getElementById("myRange2").value=100;
		document.getElementById("myRange3").value=360;
	}

    function vcontrol(e){
        if (document.getElementById("controls").style.display=="block"){
            if (recording){return;}
            document.getElementById("controls").style.display="none";
        }else{
            setres();
            document.getElementById("controls").style.display="block";
        }
    }

    function setres(){
        if (document.querySelector('[aria-label="Video Quality"')){
            var voptions=document.querySelectorAll('[data-testid="quality-option"]');
            if (voptions[voptions.length-1].style.color){
                voptions[0].click();
            }
        }
    }

    function dragMouseDown(e) {
        e.preventDefault();
        pos1=e.pageX;
        pos2=e.pageY;
        document.onmouseup = closeDragElement;
        document.onmousemove = elementDrag;
    }

    function elementDrag(e) {
        e.preventDefault();
        pos3=pos1-e.pageX;
        pos4=pos2-e.pageY;
        pos1=e.pageX;
        pos2=e.pageY;
        if (e.pageY <130){return;}
        var pos5=parseInt(document.getElementById("controls").style.right)+pos3;
        var pos6=parseInt(document.getElementById("controls").style.top)-pos4;
        if (pos5 < -18){pos5=-18;}
        if (pos5 > window.innerWidth-450){pos5= window.innerWidth-450;}
        document.getElementById("controls").style.right = pos5 + "px";
        document.getElementById("controls").style.top = pos6 + "px";
    }

    function closeDragElement() {
        document.onmouseup = null;
        document.onmousemove = null;
    }

    function info(anon){
        var cred="same-origin";
        if (!anon){cred="omit";}
        var url=domain+"api/chatvideocontext/"+roomname+"/";
        fetching++;
         fetch(url,{ credentials: cred}).then(
            function(response) {
                if (response.status !== 200){
                    wprof("Error:","<div style='color:red'>You have no access to this room</div>");
                    if (anon){
                        noaccess=true;// ?weg
                        fetching--;
                        info(false);
                        return;
                    }
                    fetching--;
                    return;
                }
                response.json().then(function(roomdata) {
                    data=roomdata;
                    fetching--;
                    if (biodata==""){
                        fanbiodata();
                    }else{
                        setprofileinfo();
                    }
                });
            });
    }

    function fanbiodata(){
        var url=domain+"api/biocontext/"+roomname;
        fetch(url,{ credentials: "omit",referrer: domain+roomname+"/"}).then(
            function(response) {
                if (response.status !== 200){
                    setprofileinfo();
                    return;
                }
                response.json().then(function(data) {
                    biodata=data;
                    setprofileinfo();
                });
            });
    }

    function setprofileinfo(){
        room_status=data.room_status;
        username=data.viewer_username;
        if (room_status =="offline"){
            document.getElementById("vcontr").style.display="none";
        }
        wprof("","");
        wprof("Archive:","<a href='https://recu.me/performer/"+roomname+"' rel=noreferrer target='_new'>Open in recu</a>");
        wprof("Find:","<a href='https://camgirlfinder.net/models/cb/"+roomname+"' rel=noreferrer target='_new'>Open in camgirlfinder</a>");
        wprof("Statistics:","<a href='https://statbate.com/search/1/"+roomname+"' rel=noreferrer target='_new'>Open in statbate</a>");
        wprof("Schedule:","<a href='https://www.cbhours.com/user/"+roomname+".html' rel=noreferrer target='_new'>Open in cbhours</a>");
        if (document.getElementById("vcontr").style.display=="none"){
            if (!data.opt_out){
                wprof("Full video (anon):","<a href='https://www.girls4cock.com/fullvideo/?b="+roomname+"' rel=noreferrer target='_new'>Open full video mode as anonymous</a>");
                if (pageType!="noaccess"){
                    wprof("Full video:","<a href='"+domain+"fullvideo/?b="+roomname+"' rel=noreferrer target='_new'>Open full video mode</a>");
                }
            }
        }
        wprof("Myfreecams:","<a href='#' id='mfcName' rel=noreferrer target='_new'>dummy</a>&nbsp&nbsp<button type='button' class='profbutton' id='mfcCheck' > Check </button><span id=mfcStatus></span>","mfcProf");
        document.getElementById("mfcProf").style.display="none";
        wprof("Cam4:","<a href='#' id='c4Name' rel=noreferrer target='_new'>dummy</a>&nbsp&nbsp<button type='button' class='profbutton' id='c4Check' > Check </button><span id=c4Status></span>","c4Prof");
        document.getElementById("c4Prof").style.display="none";
        wprof("Bongacams:","<a href='#' id='bcName' rel=noreferrer target='_new'>dummy</a>&nbsp&nbsp<button type='button' class='profbutton' id='bcCheck' > Check </button><span id=bcStatus></span>","bcProf");
        document.getElementById("bcProf").style.display="none";
        wprof("Streamate:","<a href='#' id='smName' rel=noreferrer target='_new'>dummy</a>&nbsp&nbsp<button type='button' class='profbutton' id='smCheck' > Check </button><span id=smStatus></span>","smProf");
        document.getElementById("smProf").style.display="none";
        wprof("Camsoda:","<a href='#' id='csName' rel=noreferrer target='_new'>dummy</a>&nbsp&nbsp<button type='button' class='profbutton' id='csCheck' > Check </button><span id=csStatus></span>","csProf");
        document.getElementById("csProf").style.display="none";
        wprof("Stripchat:","<a href='#' id='scName' rel=noreferrer target='_new'>dummy</a>&nbsp&nbsp<button type='button' class='profbutton' id='scCheck' > Check </button><span id=scStatus></span>","scProf");
        document.getElementById("scProf").style.display="none";
        wprof ("On other sites:","<button type='button' class='profbutton' id='extedit' > Edit </button>");
        document.getElementById("extedit").addEventListener("click",externedit);
        if (data.opt_out){
            wprof("On network sites:","No");
        }
        makerulesarea(data.chat_rules);
        if(data.chat_rules!=""){
            wprof ("Chat rules:","Yes <button type='button' class='profbutton' id='rulesview'>Show chatrules</button>");
            document.getElementById("rulesview").addEventListener("click",function(){
                if(document.getElementById("rulespop").style.display=="none"){
                    document.getElementById("rulespop").innerHTML=chatrules;
                    document.getElementById("rulespop").style.display="block";
                }
                else{
                    document.getElementById("rulespop").style.display="none";
                    document.getElementById("rulespop").innerHTML="";
                }
            });
        }
        if(pageType=="ppage"){
            if(!noaccess){
                if (data.following){
                    document.getElementById("unfollowbut").style.display="inline-flex";
                }else{
                    document.getElementById("followbut").style.display="inline-flex";
                }
                if (data.fan_club_is_member){
                    document.getElementById("fanclubmembut").style.display="inline-flex";
                }else{
                    if (data.performer_has_fanclub){
                        document.getElementById("fanclubbut").style.display="inline-flex";
                    }
                }
            }
        }
        if (room_status =="offline"){
            if (biodata.last_broadcast){
                wprof("Last online:",biodata.last_broadcast.split("T")[0]);
            }
        }
        wprof("Users in room:","<span id='numusers'>"+data.num_viewers+"</span> <button type='button' class='profbutton' id='userview' style='display:none'> Show userlist</button>");
        document.getElementById("userview").addEventListener("click",getuserlist);
        if (pageType=="ppage"){
            document.querySelector('[data-testid="satisfaction-rating"]').getElementsByTagName("button")[0].lastChild.remove();
            if (!data.hide_satisfaction_score){
                document.querySelector('[data-testid="satisfaction-rating"]').getElementsByTagName("button")[0].append(data.satisfaction_score.percent+"%");
            }
        }
        if (!data.hide_satisfaction_score){
            if (!document.getElementById("vup")){
                var newelem = document.createElement("div");
                newelem.id="vup";
                if (document.querySelector('[data-testid="satisfaction-score"]')){
                    document.querySelector('[data-testid="satisfaction-score"]').prepend(newelem);
                    }else{
                        document.querySelector('[data-testid="satisfaction-rating"]').prepend(newelem);
                    }
                newelem = document.createElement("div");
                newelem.id="vdown";
                if(document.querySelector('[data-testid="satisfaction-score"]')){
                    document.querySelector('[data-testid="satisfaction-score"]').appendChild(newelem);
                }else{
                    document.querySelector('[data-testid="satisfaction-rating"]').appendChild(newelem);
                }
            }
            document.getElementById("vup").innerHTML="&nbsp;&nbsp;"+data.satisfaction_score.up_votes;
            document.getElementById("vdown").innerHTML=data.satisfaction_score.down_votes+"&nbsp;&nbsp;";
        }
        if (data.low_satisfaction_score){
            wprof("Satisfaction score:","<font color=#CC0000>LOW !!!</font>");
        }
        if (data.is_moderator){
            wprof("Moderator:","Yes");
        }
        if (data.fan_club_is_member){
            wprof("Fanclub member:","Yes");
        }
        videoSrc=data.hls_source;
        wprof("Room status:",'<div style="display:flex;gap: 5px"><span id="premium" style="display:none">Premium </span><span id="rstatus">'+room_status+'</span> <button type="button" class="profbutton" id="hls">Update status</button></div>');
        if (data.premium_show_running){document.getElementById("premium").style.display="block";}
        document.getElementById("hls").addEventListener("click",function(){getnewhls(!noaccess,true);});
        if(document.querySelector('[data-testid="offline-content-container"]')){
            if(document.querySelector('[data-testid="offline-content-container"]').style.display=="block"){ // offline normal page
                wprof("<div id='alarmmode1'>Status alarm mode:</div>","<div id='alarmmode'><input type='range' id='alrmtype' min=0 max=1 value=0 style='width: 35px;height:auto;cursor: pointer'> Reload if visible <-> Alarm on status change<div>");
            }
        }else{
            if (videoSrc == ""){
                wprof("<div id='alarmmode1'>Status alarm mode:</div>","<div id='alarmmode'><input type='range' id='alrmtype' min=0 max=1 value=0 style='width: 35px;height:auto;cursor: pointer'> Reload if visible <-> Alarm on status change<div>");
            }
        }
        wprof("Status alarm:","<div><input type='range' id='alrm' min=0 max=1 value=0 style='width: 35px;height:auto;cursor: pointer'> Off <-> On<div>");
        document.getElementById("alrm").addEventListener("change",setalrm);
        document.title=ctitle;
        if (data.tips_in_past_24_hours !== 0){
            wprof("You tipped:",data.tips_in_past_24_hours+" Tk/24h");
        }
        wprof("Nationality:","<span id='flaginfo'>wait....</span>");
        wprof("Region:","<span id='regioninfo'>wait....</span>");
        getregion(false);
        if (pageType=="ppage"){
            if (room_status.indexOf("hidden")!=-1){
                wprof("Hidden show message:",data.hidden_message);
            }
        }
        if ((room_status=="offline")||(pageType=="ppage")){
            wprof("Room topic:","<div style='width:450px;height:auto'>"+data.room_title+"</div>");
        }
        if (biodata.performer_has_fanclub){
            wprof("Fanclub costs:",biodata.fan_club_cost*3+" Tk / 3 Months");
        }
        if (!data.is_age_verified){
            wprof("Status:","Exhibitionist");
        }else{
            if (data.allow_private_shows){
                wprof("Private recording:",data.allow_show_recordings ? "Yes":"No");
                if (data.spy_private_show_price!=0){
                    if (data.premium_private_price!=0){
                        wprof("Min. premium private:",data.premium_private_min_minutes+" Minutes");
                        wprof("Premium privateshow:",data.premium_private_price+" Tk/min");
                    }
                }
                if (data.spy_private_show_price !== 0){
                    if ((data.fan_club_spy_private_show_price !==null)&&(data.fan_club_spy_private_show_price!==data.spy_private_show_price)){
                        if(data.fan_club_spy_private_show_price==0){
                            wprof("Fan Spy on private:","Free");
                        }else{
                            wprof("Fan Spy on private:",data.fan_club_spy_private_show_price+" Tk/min");
                        }
                    }
                    wprof("Spy on private:",data.spy_private_show_price+" Tk/min");
                }else{
                    wprof("Spy on private:","Disabled");
                }
                wprof("Minimum private:",data.private_min_minutes+" Minutes");
                wprof("Privateshow:",data.private_show_price+" Tk/min");
            }else{
                wprof("Privateshow:","Disabled");
            }
        }
        if (login){
            if (pageType!="noaccess"){
                if (roomname!=username){//ok
                    var dmurl="messages/";
                    if (document.getElementById("dmListIconRoot")){dmurl="dm/";}
                    wprof ("DM/PM:","<a href='"+domain+dmurl+roomname+"/' id='dmpop'>Open window</a>");
                    document.getElementById("dmpop").addEventListener("click", function(event){opendm(this);event.stopPropagation();event.preventDefault();return false;});
                }
            }
            getnotes();
            gojpg=false;
            createimage();
        }
        if ((room_status!="offline")&&(pageType!="ppage")){chatchange();}
    }

    function getuserlist(){
        if (regiofetch){alert("Please wait");return;}
        if(document.getElementById("rulespop").style.display=="block"){
            document.getElementById("rulespop").style.display="none";
            document.getElementById("rulespop").innerHTML="";
            return;
        }else{
            document.getElementById("rulespop").style.display="block";
        }

        var listurl=domain+"api/getchatuserlist/?sort_by=a&roomname="+roomname+"&exclude_staff=false";
        fetch(listurl,{credentials: "omit",referrerPolicy: "no-referrer"}).then(
            function(response) {
                if (response.status !== 200){
                    return;
                }
                response.text().then(function(userdata) {
                    formatuserlist(userdata);
                });
            });
    }

    function externedit(){
        if (document.getElementById("rulespop").style.display=="block"){
            document.getElementById("rulespop").style.display="none";
            document.getElementById("rulespop").innerHTML="";
            return;
        }
        document.getElementById("rulespop").style.display="block";
        document.getElementById("rulespop").innerHTML="";
        var edittext='<div id="extpop" style="width:100%;height:100%;margin:10px"><table><colgroup><col style="width:80px"><col><col><col><tbody>'+
        '<tr><th colspan="4">Enter the name of the model on the other sites.</th></tr>'+
        '<tr><th>Stripchat:</th><th><input type="text" id="scTestName"></th><th><button id="sctest">Check</button></th><th id="scresult"><th></tr>'+
        '<tr><th>Camsoda:</th><th><input type="text" id="csTestName"></th><th><button id="cstest">Check</button></th><th id="csresult"><th></tr>'+
        '<tr><th>Streamate:</th><th><input type="text" id="smTestName"></th><th><button id="smtest">Check</button></th><th id="smresult"><th></tr>'+
        '<tr><th>Cam4:</th><th><input type="text" id="c4TestName"></th><th><button id="c4test">Check</button></th><th id="c4result"><th></tr>'+
        '<tr><th>Myfreecams:</th><th><input type="text" id="mfcTestName"></th><th><button id="mfctest">Check</button></th><th id="mfcresult"><th></tr>'+
        '<tr><th>Bongacams:</th><th><input type="text" id="bcTestName"></th><th><button id="bctest">Check</button></th><th id="bcresult"><th></tr>'+
        '<tr><th><div id="cancelextern" class="evolveMode ButtonV2 ButtonV2--secondary ButtonV2--small ControlPanel__actionButton">Cancel</div></th>'+
        '<th><div id="subextern" class="evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode">Save</div></th></tr></div>'+
        '</tbody></table>';
        document.getElementById("rulespop").innerHTML=edittext;
        document.getElementById("extpop").onclick=function(event){event.stopPropagation();event.preventDefault();};
        var testnote=opennote.replaceAll((/[\r\n]+/g)," ");
        var editnote=" "+opennote+" ";
        var testparts=[];
        if (testnote.includes("sc:")){
            var scName=testnote.split("sc:")[1].split(" ")[0];
            if (scName.length>2){
                document.getElementById("scTestName").value=scName.toLowerCase();
            }
            testparts=editnote.split("sc:"+scName);
            editnote=testparts[0]+testparts[1].slice(1);
        }
        if (testnote.includes("cs:")){
            var csName=testnote.split("cs:")[1].split(" ")[0];
            if (csName.length>2){
                document.getElementById("csTestName").value=csName.toLowerCase();
            }
            testparts=editnote.split("cs:"+csName);
            editnote=testparts[0]+testparts[1].slice(1);
        }
        if (testnote.includes("sm:")){
            var smName=testnote.split("sm:")[1].split(" ")[0];
            if (smName.length>2){
                document.getElementById("smTestName").value=smName.toLowerCase();
            }
            testparts=editnote.split("sm:"+smName);
            editnote=testparts[0]+testparts[1].slice(1);
        }
        if (testnote.includes("c4:")){
            var c4Name=testnote.split("c4:")[1].split(" ")[0];
            if (c4Name.length>2){
                document.getElementById("c4TestName").value=c4Name.toLowerCase();
            }
            testparts=editnote.split("c4:"+c4Name);
            editnote=testparts[0]+testparts[1].slice(1);
        }
        if (testnote.includes("mfc:")){
            var mfcName=testnote.split("mfc:")[1].split(" ")[0];
            if (mfcName.length>2){
                document.getElementById("mfcTestName").value=mfcName.toLowerCase();
            }
            testparts=editnote.split("mfc:"+mfcName);
            editnote=testparts[0]+testparts[1].slice(1);
        }
        if (testnote.includes("bc:")){
            var bcName=testnote.split("bc:")[1].split(" ")[0];
            if (bcName.length>2){
                document.getElementById("bcTestName").value=bcName.toLowerCase();
            }
            testparts=editnote.split("bc:"+bcName);
            editnote=testparts[0]+testparts[1].slice(1);
        }
        document.getElementById("sctest").onclick=function(){
            document.getElementById("scresult").innerHTML="";
            if (document.getElementById("scTestName").value==""){return;}
            document.getElementById("scTestName").value=document.getElementById("scTestName").value.trim();
            scCheck(document.getElementById("scTestName").value);
        };
        document.getElementById("cstest").onclick=function(){
            document.getElementById("csresult").innerHTML="";
            if (document.getElementById("csTestName").value==""){return;}
            document.getElementById("csTestName").value=document.getElementById("csTestName").value.trim();
            csCheck(document.getElementById("csTestName").value);
        };
        document.getElementById("smtest").onclick=function(){
            document.getElementById("smresult").innerHTML="";
            if (document.getElementById("smTestName").value==""){return;}
            document.getElementById("smTestName").value=document.getElementById("smTestName").value.trim();
            smCheck(document.getElementById("smTestName").value);
        };
        document.getElementById("c4test").onclick=function(){
            document.getElementById("c4result").innerHTML="";
            if (document.getElementById("c4TestName").value==""){return;}
            document.getElementById("c4TestName").value=document.getElementById("c4TestName").value.trim();
            c4Check(document.getElementById("c4TestName").value);
        };
        document.getElementById("mfctest").onclick=function(){
            document.getElementById("mfcresult").innerHTML="";
            if (document.getElementById("mfcTestName").value==""){return;}
            document.getElementById("mfcTestName").value=document.getElementById("mfcTestName").value.trim();
            mfcCheck(document.getElementById("mfcTestName").value);
        };
        document.getElementById("bctest").onclick=function(){
            document.getElementById("bcresult").innerHTML="";
            if (document.getElementById("bcTestName").value==""){return;}
            document.getElementById("bcTestName").value=document.getElementById("bcTestName").value.trim();
            bcCheck(document.getElementById("bcTestName").value);
        };
        document.getElementById("cancelextern").onclick=function(){
            document.getElementById("rulespop").style.display="none";
            document.getElementById("rulespop").innerHTML="";
        };
        document.getElementById("subextern").onclick=function(){
            editnote=editnote.trim();
            if (document.getElementById("scTestName").value!=""){
                editnote=editnote+"\nsc:"+document.getElementById("scTestName").value.trim();
            }
            if (document.getElementById("csTestName").value!=""){
                editnote=editnote+"\ncs:"+document.getElementById("csTestName").value.trim();
            }
            if (document.getElementById("smTestName").value!=""){
                editnote=editnote+"\nsm:"+document.getElementById("smTestName").value.trim();
            }
            if (document.getElementById("c4TestName").value!=""){
                editnote=editnote+"\nc4:"+document.getElementById("c4TestName").value.trim();
            }
            if (document.getElementById("mfcTestName").value!=""){
                editnote=editnote+"\nmfc:"+document.getElementById("mfcTestName").value.trim();
            }
            if (document.getElementById("bcTestName").value!=""){
                editnote=editnote+"\nbc:"+document.getElementById("bcTestName").value.trim();
            }
            if (editnote.length <3){editnote="";}
            if (editnote.charAt(0)=="\n"){editnote=editnote.substring(1);}
            document.getElementById("proftext").value=editnote;
            opennote=editnote;
            document.getElementById("rulespop").style.display="none";
            document.getElementById("rulespop").innerHTML="";
            profsavenote();
            setTimeout(function(){
                document.getElementById("scProf").style.display="none";
                document.getElementById("csProf").style.display="none";
                document.getElementById("smProf").style.display="none";
                document.getElementById("c4Prof").style.display="none";
                document.getElementById("mfcProf").style.display="none";
                document.getElementById("bcProf").style.display="none";
                setExtern();},1000);
        };
    }

    function setalrm(){
        if (document.getElementById("alrm").value==0){document.title=ctitle;return;}
        ctitle=document.title;
        getnewhls(true,false);
        setTimeout(function(){
            oldroomstatus=roomstatus;
            if(!alarmrun){
            alarmrun=true;
            testalarm();}},1000);
    }

    function testalarm(){
        document.title="\u23F0 "+ctitle;
        setTimeout(function(){
            if(document.getElementById("alrm").value==0){alarmrun=false;return;}
            getnewhls(true,false,2);
        }, 60000);
    }

    function testalarm2(){
        if (roomstatus != oldroomstatus){
            if (!document.getElementById("alrmtype")){
                playalarm();
                alarmtab();
                alarmrun=false;
            }else{
                if(document.getElementById("alrmtype").value==0){
                    if ((roomstatus=="public")||(roomstatus.indexOf("watching")!=-1)){
                        if (pageType=="ppage"){
                            window.focus();
                            setTimeout(newinfo,1000);
                            return;
                        }
                        forceopen(roomname);
                    }
                    oldroomstatus=roomstatus;
                    if (alarmrun){
                        testalarm();
                        return;
                    }
                }
                playalarm();
                alarmtab();
                alarmrun=false;
            }
        }else{
            if (alarmrun){
                testalarm();
            }
        }
    }

    function playalarm(){
        if (document.getElementById("alrm")){
            if (document.getElementById("alrm").value==0){return;}
        }
        setTimeout(playalarm,2000);
    }

    function alarmtab(){
        if (document.getElementById("alrm")){
            if (document.getElementById("alrm").value==0){document.title=ctitle;return;}
        }
        if (document.title != "ALARM"){
            document.title = "ALARM";
        }else{
            document.title = "!!!!!!";
        }
        setTimeout(alarmtab,500);
    }

    function formatuserlist(userdata){
        var broadcastarray=[];
        for(i=0;i < region.length;i++) {
            broadcastarray[i]=JSON.parse(localStorage.getItem("region_"+region[i]));
        }
        var bc="";
        var userarray=userdata.split(",");
        var height=15*userarray.length+120;
        var scroll="";
        if (height<240){height=240;}
        if (height>500){height=500;scroll=";overflow-y:scroll";}
        var userstring="<div style='float:right;color:black'>(Close)</div><div onclick='event.stopPropagation()' style='cursor:default;color:black;width:350px;height:"+height+"px"+scroll+"'>";
        var x=2;
        var followr=0;
        var notok=0;
        if (userarray[1].includes("|")){x=1;}
        for (i=x; i<userarray.length; i++){
            var user=userarray[i].split("|");
            if (user[1]=="o"){user[1]="#dc5500";}
            if (user[1]=="m"){user[1]="#dc0000";}
            if (user[1]=="f"){user[1]="#090";}
            if (user[1]=="l"){user[1]="#804baa";}
            if (user[1]=="p"){user[1]="#be6aff";}
            if (user[1]=="tr"){user[1]="#1e5cfb";}
            if (user[1]=="t"){user[1]="#69a";}
            if (user[1]=="g"){user[1]="#939393";notok++;}
            if (user[2]=="m"){user[2]="https://web.static.mmcdn.com/tsdefaultassets/gendericons/male.svg";}
            if (user[2]=="f"){user[2]="https://web.static.mmcdn.com/tsdefaultassets/gendericons/female.svg";}
            if (user[2]=="c"){user[2]="https://web.static.mmcdn.com/tsdefaultassets/gendericons/couple.svg";}
            if (user[2]=="s"){user[2]="https://web.static.mmcdn.com/tsdefaultassets/gendericons/trans.svg";}
            if (user[3]=="t"){user[3]="<span title='follower'>⭐</span>";followr++;}
            if (user[3]=="f"){user[3]="";}
            bc="";
            for(n=0;n < region.length;n++) {
                if (broadcastarray[n].indexOf(user[0])!=-1){
                    bc="<span title='broadcaster' name='broadcast' broadcaster='"+user[0]+"'>🖥️</span>";
                    break;
                }
            }
            if (user[0]==roomname){
                bc="<span title='broadcaster' name='broadcast' broadcaster='"+user[0]+"'>🖥️</span>";
            }
            if ((user[0]==roomname)||(user[0]==username)){
                userstring=userstring+"<img style='height:16px' src='"+user[2]+"'>"+bc+"<a style='font-weight: bold;color:"+user[1]+"'>"+user[0]+"</a> "+user[3]+"<br>";
            }else{
                if (login){
                    userstring=userstring+"<img style='height:16px' src='"+user[2]+"'>"+bc+"<a target=_blank style='font-weight: bold;color:"+user[1]+"' href='"+domain+"p/"+username+"?tab=bio&model="+user[0]+"'>"+user[0]+"</a> "+user[3]+"<br>";
                }else{
                    userstring=userstring+"<img style='height:16px' src='"+user[2]+"'>"+bc+"<a target=_blank style='font-weight: bold;color:"+user[1]+"' href='"+domain+user[0]+"'>"+user[0]+"</a> "+user[3]+"<br>";
                }
            }
        }
        if (x==1){
            userstring=userstring+"+"+userarray[0]+" Anonymous users.</div>";
        }else{
            userstring=userstring+"+"+userarray[0]+" Anonymous users.<br>";
            userstring=userstring+" "+(parseInt(userarray[0])-parseInt(userarray[1]))+" On site. - "+userarray[1]+" Promoted.</div>";
        }

        document.getElementById("rulespop").innerHTML=userstring;
        if (x==1){
            document.getElementById("numusers").innerHTML=userarray.length-x+" + "+userarray[0]+" Anon";
        }else{
            document.getElementById("numusers").innerHTML=userarray.length-x+"("+(userarray.length-x-notok)+" with tokens. "+followr+" are follower.) + "+userarray[0]+" Anon ("+(parseInt(userarray[0])-parseInt(userarray[1]))+" On site. - "+userarray[1]+" Promoted.)";
        }
        broadcastarray="";
        broadcastcheck(document.getElementsByName("broadcast").length-1);
    }

    function broadcastcheck(n){
        if (n<0){return;}
        var name=document.getElementsByName("broadcast")[n].getAttribute("broadcaster");
        var url=domain+"get_edge_hls_url_ajax/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "room_slug", name );
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,{
            credentials: "omit",
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+name+"/",
            body: data
        }).then(function(response){
            response.json().then(function(data){
                if(data.room_status=="offline"){
                    document.getElementsByName("broadcast")[n].innerHTML="🖥️❌";
                    document.getElementsByName("broadcast")[n].title="broadcaster offline";
                }
                document.getElementsByName("broadcast")[n].addEventListener("mouseenter",showicon);
                document.getElementsByName("broadcast")[n].addEventListener("mouseout",unshowicon);
                n--;
                broadcastcheck(n);
                return;
            });
        });
    }

    function showicon(){
        var newimg=document.createElement('img');
        newimg.id="picon";
        newimg.style.width="250px";
        newimg.style.position="absolute";
        newimg.style.top="0px";
        newimg.style.right="0px";
        newimg.src="https://thumb.live.mmcdn.com/riw/"+this.getAttribute("broadcaster")+".jpg?"+new Date().getTime();
        document.getElementById("rulespop").prepend(newimg);

    }

    function unshowicon(){
        document.getElementById("picon").remove();
    }

    function chatchange(){
        document.getElementById("ccontr").style.display="block";
        document.getElementById("c1").addEventListener("change",chatsetchange);
        document.getElementById("c2").addEventListener("change",chatsetchange);
        document.getElementById("c3").addEventListener("change",chatsetchange);
        document.getElementById("c4").addEventListener("change",chatsetchange);
        document.getElementById("c5").addEventListener("change",chatsetchange);
        document.getElementById("c6").addEventListener("change",chatsetchange);
        document.getElementById("c7").addEventListener("change",chatsetchange);
        document.getElementById("c7a").addEventListener("change",chatsetchange);
        document.getElementById("c8").addEventListener("change",chatsetchange);
        document.getElementById("c10").addEventListener("change",chatsetchange);
        var chatobserver = new MutationObserver(chatadjust);
        var pmchatobserver = new MutationObserver(tabpm);
        var chatobserverConfig = {childList: true};
        var pmchatobserverConfig = {characterData:true, childList: true};
        var observenode=document.getElementsByClassName("message-list")[0];
        var pmobservenode=document.getElementById("message-tab-default").getElementsByTagName("span")[0];
        if (readCookie(roomname+"Tokens")){
            document.getElementById("c9").innerHTML=readCookie(roomname+"Tokens");
            firstentry=false;
        }
        document.getElementById("tclear").addEventListener("click",cleartokens);
        chatobserver.observe(observenode,chatobserverConfig);
        pmchatobserver.observe(pmobservenode,pmchatobserverConfig);
    }

    function cleartokens(){
        document.getElementById("c9").innerHTML=0;
        eraseCookie(roomname+"Tokens");
    }

    function chatsetchange(){
        c1=document.getElementById("c1").value;
        c2=document.getElementById("c2").value;
        c3=document.getElementById("c3").value;
        c4=document.getElementById("c4").value;
        c5=document.getElementById("c5").value;
        c6=document.getElementById("c6").value;
        c7=document.getElementById("c7").value;
        c7a=document.getElementById("c7a").value;
        if (c7a<2){c7a=2;document.getElementById("c7a").value=2;}
        if (c7a>1000){c7a=1000;document.getElementById("c7a").value=1000;}
        c8=document.getElementById("c8").value;
        c10=document.getElementById("c10").value;
        smallemoonoff();
        chatadjust();// after change
    }

    function chatadjust(){
        if (!firstentry){
            twaiting=true;
            setTimeout(function(){twaiting=false;}, 200);
            firstentry=true;
        }

        var tags=document.getElementsByClassName('msg-list-fvm');
        for (n=0; n<tags.length; n++){
            chattamper(n);
        }
    }

    function chattamper(tag){
        var messages=document.getElementsByClassName('msg-list-fvm')[tag].querySelectorAll('[data-testid="chat-message"]');
        var chatmessages=messages.length;
        if (chatmessages==0){return;}
        var translated=0;
        for (i = chatmessages-1; i > 0; i--) {
            var noticeelm=messages[i].querySelector('[data-testid="room-notice"]');
            if (noticeelm!=null){
                var noticeclasses=noticeelm.classList;
                var notetext=noticeelm.querySelector('[data-testid="room-notice-viewport"]').textContent;
                if (noticeclasses.length==1){ // notice with no additional class
                    if (notetext.indexOf("Notice:")==0){ // normal notice
                        if (c2==1){
                            messages[i].style.display="none";
                        }else{
                            messages[i].style.display="block";
                        }
                    }
                    if (notetext.indexOf("Moderator")==0){
                        if (c4==1){
                            messages[i].style.display="none";
                        }else{
                            messages[i].style.display="block";
                        }
                    }
                    if (notetext.indexOf("Fan club member")==0){
                        if (c4==1){
                            messages[i].style.display="none";
                        }else{
                            messages[i].style.display="block";
                        }
                    }
                }
                if (noticeclasses.contains("titleChange")){
                    if (c3==1){
                        messages[i].style.display="none";
                    }else{
                        messages[i].style.display="block";
                    }
                }
                if (noticeclasses.contains("isTip")){
                    var tokens=parseInt(notetext.split("tipped ")[1].split(" ")[0]);
                    if (tag==0){
                        if(messages[i].style.display=="flex"){
                            if(!twaiting){
                                document.getElementById("c9").innerHTML=parseInt(document.getElementById("c9").innerHTML)+tokens;
                                createCookie(roomname+"Tokens",document.getElementById("c9").innerHTML);
                            }
                        }
                    }
                    if ((c7==1)&&(tokens<c7a)){
                        messages[i].style.display="none";
                    }else{
                        messages[i].style.display="block";
                    }
                }
            }
            if (messages[i].querySelector('[data-testid="chat-message-text"]')!=null){
                var chattext=messages[i].querySelector('[data-testid="chat-message-text"]').textContent;
                if (messages[i].querySelector('[data-testid="chat-message-username"]').className=="broadcaster"){
                    if ((chattext.indexOf("Lovense")!=-1)||(chattext.indexOf("------")!=-1)||(chattext.indexOf("******")!=-1)||(chattext.indexOf("The High Tipper")!=-1)||(chattext.indexOf("The king Tipper")!=-1)||(chattext.indexOf("Special Commands:")!=-1)||(chattext.indexOf("Blitz Mode")!=-1)||(chattext.indexOf("the critical hit rate")!=-1)){
                        messages[i].name="notranslate";
                        if (c8==1){
                            messages[i].style.display="none";
                        }else{
                            messages[i].style.display="block";
                        }
                    }
                }
                if (messages[i].querySelector('[data-testid="chat-message-username"]').className=="defaultUser"){
                    if (c5==1){
                        messages[i].style.display="none";
                    }else{
                        messages[i].style.display="block";
                    }
                }
                if (messages[i].querySelector('[data-testid="chat-message-username"]').className=="mod"){
                    if (c6==1){
                        messages[i].style.display="none";
                    }else{
                        messages[i].style.display="block";
                    }
                }
                if (c10==1){
                    if(!messages[i].name){
                        if (messages[i].style.display!="none"){
                            var splitmode=true;
                            var splitchatblock=false;
                            if(document.getElementsByClassName('msg-list-fvm')[tag].classList.contains("message-list")){splitchatblock=true;}
                            if(document.getElementById("ChatTabContainer").style.display=="none"){splitmode=false;}
                            if ((splitmode&&splitchatblock)||(!splitmode&&!splitchatblock)){
                                messages[i].name="translate";
                                translated++;
                                if (translated<8){
                                    translate(messages[i]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    function translate(elm){
        var chattext=elm.querySelector('[data-testid="chat-message-text"]').textContent;
        var result="";
        chattext=chattext.replace(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g,"");
        chattext=chattext.replace(/\./gi,"{.}");
        chattext=chattext.replace(/\?/gi,"{?}");
        chattext=chattext.replace(/\!/gi,"{!}");
        chattext=chattext.replace(/\|/gi,"{|}");
        chattext=chattext.replace(/\&/gi,"{{");
        chattext=chattext.toLowerCase();
        if (chattext.length>2){
            chattext=encodeURI(chattext);
            var lang=document.getElementById("language").options[document.getElementById("language").selectedIndex].value;
            GM_xmlhttpRequest({
                method: "GET",
                timeout: 5000,
                mozAnon: true,
                anonymous: true,
                url: tr2+lang+"&dt=t&q="+chattext,
                onload: function(response) {
                    if (response.status !== 200){
                        result="Translate error "+response.status;
                    }else{
                        result=JSON.parse(response.responseText)[0][0][0];
                        result=result.replace(/\\u200b/gi,"");
                        result=result.replace(/\\u003d/gi,"=");
                        result=result.replace(/\\u003c/gi,"<");
                        result=result.replace(/\\u003e/gi,">");
                        result=result.replace(/\{\{/gi,"&");
                        result=result.replace(/\{/gi,"");
                        result=result.replace(/\}/gi,"");
                    }
                    showtranslate(result,elm);
                },
                ontimeout: function(){
                    result="Translate error timeout";
                    showtranslate(result,elm);
                }
            });
        }
    }

    function showtranslate(result,elm){
        var newelem=document.createElement('span');
        newelem.innerHTML=result;
        newelem.className="translated";
        elm.firstChild.lastElementChild.appendChild(newelem);
    }

    function smallemoonoff(){
        if (c1==1){
            document.body.classList.add("smallemo");
        }else{
            document.body.classList.remove("smallemo");
        }
    }

    function ccontrol(){
        if (document.getElementById("chatcontrols").style.display=="block"){
            document.getElementById("chatcontrols").style.display="none";
        }else{
            document.getElementById("chatcontrols").style.display="block";
        }
    }

    function opendm(that){
       var dmwindow= window.open(that.href,'DMpop','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1000,height=800');
       dmwindow.onload = function(){
           this.addEventListener('unload', function(){setTimeout(function(){newinfo();},1000);});
       };
    }

    function getnotes(){
        var url=domain+"api/notes/for_user/"+roomname+"/";
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    wprof("Attention:","This room is banned.");
                    return;
                }
                response.json().then(function(data) {
                    if (data.text == null){data.text="";}
                    opennote=data.text;
                    buildprofnote();
                });
            });
    }

    function makerulesarea(rule){
        if (document.getElementById("rulespop")){return;}
        var newelem=document.createElement('span');
        newelem.className="rulespop";
        newelem.id="rulespop";
        chatrules="<div style='color:black'><b>"+roomname+" chatrules:</b><br><br>"+rule+"<br><br><center>(Click to close)</center></div>";
        newelem.addEventListener("click",function(){this.style.display="none";this.innerHTML="";});
        document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newelem);
    }

    function createimage(){
        if ((pageType!="ppage")&&(pageType!="noaccess")){return;}
        hls.detachMedia();
        if (document.getElementById("profimg")){
            document.getElementById("profimg").remove();
        }
        if (document.getElementById("profjpgimg")){
            pimg.removeEventListener("load",regetimgprof);
            pimg.removeEventListener("error",errorimgprof);
            document.getElementById("profjpgimg").remove();
        }
        if (document.getElementById("profplayer")){
            document.removeEventListener("visibilitychange",vidpause);
            document.getElementById("profplayer").remove();
            document.getElementById("controls").style.display="none";
            document.getElementById("vcontr").style.display="none";
        }
        if ((room_status=="public")||(room_status.indexOf("watching")!=-1)){
            if (!gojpg){
                if (videoSrc!=""){
                    makevidplayer();
                    startvid();
                    return;
                }
            }
            makejpgplayer();
            return;
        }
        var url="https://jpeg.live.mmcdn.com/minifwap/"+roomname+".jpg";
        fetch(url,{
            cache: "no-cache",
            credentials: "same-origin",referrer: domain}).then(
            function(response){
                response.blob().then(
                    function(rawimg){
                        var imgsize=rawimg.size;
                        if ((imgsize<4408)||(imgsize>4415)){
                            makeimg();
                        }else{
                            makecrd();
                        }
                    });
                }
        );
    }
/*
Hi there
I see you are trying to read the code.
That's fine, it's all free. You will notice the code is a bit messy and in an old dialect but it all works (i learned javascript in 1996).
The strength of a good userscript is not the code but it's the idea.
As a javascript writer you can write your own code in your own dialect and you can use this code as inspiration.
But it's just not nice to copy the idea's.
*/
    function makecrd(){
        if (noaccess){return;}
        if (data.summary_card_image==""){return;}
        var newelem=document.createElement('img');
        newelem.src=data.summary_card_image;
        newelem.className="profplayer";
        newelem.id="profimg";
        newelem.style.height="480px";
        newelem.style.maxWidth="854px";
        document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newelem);
    }

    function makeimg(){
        var newelem=document.createElement('img');
        newelem.src="https://jpeg.live.mmcdn.com/minifwap/"+roomname+".jpg";
        newelem.className="profplayer";
        newelem.id="profimg";
        newelem.style.height="270px";
        newelem.style.width="480px";
        document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newelem);
    }

    function makejpgplayer(){
        var newelem=document.createElement('canvas');
        newelem.id="profjpgimg";
        var img=new Image();
        img.onload = function(){
            document.getElementById("profjpgimg").height=img.naturalHeight;
            document.getElementById("profjpgimg").width=img.naturalWidth;
        };
        newelem.style.display="none";
        document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newelem);
        pimg.addEventListener("load",regetimgprof);
        pimg.addEventListener("error",errorimgprof);
        pimg.crossOrigin = "Anonymous";
        n=new Date().getTime();
        img.src="https://jpeg.live.mmcdn.com/stream?room="+roomname+"&f="+n;
        pimg.src = "https://jpeg.live.mmcdn.com/stream?room="+roomname+"&f="+n;
        var canvas=document.querySelector('canvas');
        stream = canvas.captureStream();
        makevidplayer();
        document.querySelector('video').srcObject=stream;
        document.querySelector('video').play();
    }

    function errorimgprof(){
        if (gojpg){return;}
        recstop();
        setTimeout(function(){getnewhls(true,false,1);},2000);
    }

    function regetimgprof(){
        var lt=new Date().getTime()-n;
        if (lt>180){lt=180;}
        if ((document.visibilityState!="visible")&&(!recording)){
            setTimeout(regetimgprof,2000);
        }else{
            var canvas = document.querySelector('canvas');
            canvas.getContext('2d').drawImage(pimg, 0, 0, pimg.width, pimg.height);
            setTimeout(function(){n=new Date().getTime();pimg.src = "https://jpeg.live.mmcdn.com/stream?room="+roomname+"&f="+n;}, 200-lt);
        }
    }

    function makevidplayer(){
        if(document.getElementById("tabs_content_container")){
            document.getElementById("tabs_content_container").style.minHeight=parseInt(0.562*window.innerWidth-5)+"px";
        }
        var vidobserver=new MutationObserver(vidsize);
        var vidobserverConfig ={attributes : true, attributeFilter : ['style'] };
        var vidobserver2=new MutationObserver(vidsize);
        var vidobserverConfig2 ={attributes : true, attributeFilter : ['class'] };
        var control=localStorage.getItem("videoControls");
        var newdivelem=document.createElement('div');
        newdivelem.className="profdivplayer";
        newdivelem.style.width=vidwidth+"px";
        newdivelem.id="profplayer";
        newdivelem.style.backgroundImage = "url('https://jpeg.live.mmcdn.com/minifwap/"+roomname+".jpg')";
        newdivelem.style.backgroundPosition="top";
        newdivelem.style.backgroundRepeat="no-repeat";
        newdivelem.style.backgroundSize="100% calc(100% - 3px)";
        var newelem=document.createElement('video');
        newelem.style.width="100%";
        newelem.controls=true;
        if (control.indexOf("true")!=-1){newelem.muted=true;}
        var volume=control.split(":")[1].split(",")[0];
        newelem.volume=volume/100;
        newelem.poster="https://jpeg.live.mmcdn.com/stream?room="+roomname+"&f="+ new Date().getTime();
        newelem.height=parseInt(vidwidth*0.562)+1;
        newelem.muted = true;
        newelem.id="profvid";
        newelem.autoplay=true;
        newelem.setAttribute("playsinline", "true");
        newdivelem.appendChild(newelem);
        document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newdivelem);
        vidobserver.observe(document.getElementById("profplayer"), vidobserverConfig);
        vidobserver2.observe(document.querySelector('[data-testid="desktop-sidebar"]'), vidobserverConfig2);
        if(!document.querySelector('canvas')){
            document.addEventListener("visibilitychange",vidpause);
        }
        document.getElementById("vcontr").style.display="block";
    }

    function vidsize(){
        var videdge=260;
        if (document.getElementsByClassName("collapsed").length>0){
            videdge=120;
        }
        vidwidth=parseInt(document.getElementById("profplayer").style.width);
        if (vidwidth<80){vidwidth=80;document.getElementById("profplayer").style.width=vidwidth+"px";}
        if (vidwidth>window.innerWidth-videdge){vidwidth=window.innerWidth-videdge;document.getElementById("profplayer").style.width=vidwidth+"px";}
        document.getElementById("profvid").height=parseInt(vidwidth*0.562)+1;
    }

    function startvid(){
        getnewhls(true,false,3);
    }

    function startvid2(){
        if(document.visibilityState!="visible"){return;}
        document.getElementById("vcontr").style.display="inline-flex";
        if (videoSrc==""){
            createimage();
            return;
        }
        var video=document.getElementsByTagName('video')[0];
        video.poster="https://jpeg.live.mmcdn.com/stream?room="+roomname+"&f="+ new Date().getTime();
        hls.loadSource(videoSrc);
        hls.attachMedia(video);
        hls.on(Hls.Events.ERROR, function (event, data) {
            if ((data.fatal==true)&&(data.type="networkError")){
                hls.stopLoad();
                hls.detachMedia();
                getnewhls(true,false,1);
                return;
            }
            if (fatalerror==0){
                setTimeout(function(){
                    fatalerror=0;
                 }, 15000);
            }
            fatalerror++;
            if (fatalerror > 6){
                restarts++;
                setTimeout(function(){restarts=0;}, 15000);

                if (restarts==3){
                    restarts=0;
                    if (!recording){
                        gojpg=true;
                        hls.stopLoad();
                        hls.detachMedia();
                        createimage();
                        setTimeout(function(){gojpg=false;getnewhls(true,false,1);},15000);
                        return;
                    }
                }
                fatalerror=0;
                hls.stopLoad();
                hls.detachMedia();
                getnewhls(true,false,3);
                return;
            }
        });
    }

    function vidpause(){
        if (recording){return;}
        if (document.hidden){
            clearTimeout(vidpausetime);
            vidpausetime=setTimeout(function(){
                if (document.hidden){
                    vidonpause=true;
                    hls.stopLoad();
                    hls.detachMedia();
                }
            },10000);
        }else{
            if (!document.hidden){
                clearTimeout(vidpausetime);
                if (vidonpause){
                    vidonpause=false;
                    startvid();
                }
            }
        }
    }

    function recstop(){
        if (!recording){return;}
        stoppressed=true;
        mediaRecorder.stop();
    }

    function recstart(){
        stoppressed=false;
        if (recording){
            if (recwait){return;}
            if (!recpause){
                clearTimeout(recTimeoutID);
                mediaRecorder.pause();
                recpause=true;
                return;
            }
            mediaRecorder.resume();
            document.getElementById("recbut").style.color="white";
            recpause=false;
            return;
        }
        recording=true;
        document.getElementById("vcontr").style.cursor="not-allowed";
        document.getElementById("vcontr2").style.cursor="not-allowed";
        document.getElementById("recbut").innerHTML="&nbsp&nbspPAUSE&nbsp&nbsp";
        document.getElementById("rectime").style.display="block";
        if (!document.getElementById('profjpgimg')){
            var video=document.querySelector('video');
            video.addEventListener("pause", function(){video.play();});
            stream=video.captureStream();
        }
        mediaRecorder = new MediaRecorder(stream,{
            mimeType:mimeTypes[mimeType],
            videoBitsPerSecond: bitrate
        });
        mediaRecorder.onstop = autosave;
        mediaRecorder.ondataavailable = handleDataAvailable;
        timedisplay();
        recstart2();
    }

    function recstart2(){
        prectime=0;
        recwait=false;
        recpause=false;
        clearTimeout(recTimeoutID);
        var starttime=new Date().toISOString().split(".")[0]+"GMT";
        starttime=starttime.replaceAll(":","-");
        recname=roomname+"("+recparts+")-"+starttime;
        try {
            mediaRecorder.start(1000);
        } catch (e) {
            endrecord();
            return;
        }
        recTimeoutID=setTimeout(recstop,10000);
    }

    function handleDataAvailable(event) {
        clearTimeout(recTimeoutID);
        if (event.data){
            if (event.data.size){
                if (event.data.size>0){
                    recordedBlobs.push(event.data);
                    zeroData=0;
                }else{
                    zeroData++;
                }
            }else{
                zeroData++;
            }
        }
        if (zeroData>10){
            recstop();
            return;
        }
        if (!recpause){
            if(!recwait){
                recTimeoutID=setTimeout(recstop,10000);
            }
        }
    }

    function timedisplay(){
        if (recording){
            setTimeout(timedisplay,1000);
            if(!recpause){
                if(!recwait){
                    var h = Math.floor(rectime / 3600);
                    var H=("0"+h).substr(-2);
                    var m = Math.floor(rectime % 3600 / 60);
                    var M=("0"+m).substr(-2);
                    var s = Math.floor(rectime % 3600 % 60);
                    var S=("0"+s).substr(-2);
                    document.getElementById("rectime").innerHTML="REC("+recparts+"): "+H+" : "+M+" : "+S;
                    rectime++;
                    prectime++;
                }
            }
            if (recpause){
                if (document.getElementById("recbut").style.color=="red"){
                    document.getElementById("recbut").style.color="white";
                }else{
                    document.getElementById("recbut").style.color="red";
                }
            }
            if (prectime==savetime*60){
                timerrecstop=true;
                mediaRecorder.stop();
            }
        }
    }

    function autosave(){
        recwait=true;
        document.getElementById("recbut").style.color="white";
        clearTimeout(recTimeoutID);
        if (prectime<10){
            recparts--;
            dlready();
            return;
        }
        if (recordedBlobs.length <3){
            stoppressed=true;
            dlready();
            return;
        }

        document.getElementById("rectime").innerHTML="SAVING";
        blob = new Blob(recordedBlobs, {type: vidcontainers[mimeType]});
        URL.revokeObjectURL(url);
        url = URL.createObjectURL(blob);
        GM_download({
            url: url,
            name: recname+extentions[mimeType],
            onload: dlready,
        });
    }

    function dlready(){
        recordedBlobs=[];
        blob = new Blob([]);
        if(stoppressed==false){
            recparts++;
            if (timerrecstop==false){
                    document.getElementById("rectime").innerHTML="WAITING";
                    setTimeout(recstart2,10000);
                    return;
            }
            timerrecstop=false;
            recstart2();
            return;
        }else{
            endrecord();
        }
    }

    function endrecord(){
        document.getElementById("vcontr").style.cursor="pointer";
        document.getElementById("vcontr2").style.cursor="pointer";
        document.getElementById("recbut").innerHTML="RECORD";
        document.getElementById("recbut").style.color="white";
        document.getElementById("rectime").style.display="none";
        document.getElementById("rectime").innerHTML="";
        recparts=1;
        rectime=0;
        recording=false;
        recpause=false;
        recwait=false;
        stoppressed=false;
    }

    function buildprofnote(){
        var subbut="<span id='profsubmit' class='evolveMode ButtonV2 ButtonV2--primary ButtonV2--brand-primary ButtonV2--small evolveMode'>Save</span>";
        var canclebut="<span id='profcancel' class='evolveMode ButtonV2 ButtonV2--secondary ButtonV2--small ControlPanel__actionButton' style='margin-right:10px;'>Cancel</span>";
        wprof("",'<div width="300px" id="profnote" style="display:none">'+canclebut+subbut+'</div>');
        wprof("Personal notes:","<textarea id='proftext' class='proftext' spellcheck='false' placeholder='Enter notes about this user (only seen by you).'></textarea>");
        document.getElementById("proftext").value=opennote;
        document.getElementById("proftext").addEventListener("input",profopenbutton);
        document.getElementById("profcancel").addEventListener("click",profclosebutton);
        document.getElementById("profsubmit").addEventListener("click",profsavenote);
        setExtern();
    }

    function profsavenote(){
        var notetext=document.getElementById("proftext").value;
        var url=domain+"api/notes/for_user/"+roomname+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "text", notetext );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+roomname+"/",
            body: data
        }).then(profaftersave);
    }

    function profaftersave(){
        opennote=document.getElementById("proftext").value;
        profclosebutton();
    }

    function profopenbutton(){
        document.getElementById("profnote").style.display="block";
        document.getElementById("proftext").value=document.getElementById("proftext").value.replace("$"," "+new Date().toLocaleDateString()+" ");
        if(opennote==document.getElementById("proftext").value){
            profclosebutton();
        }
    }

    function profclosebutton(){
        document.getElementById("profnote").style.display="none";
        document.getElementById("proftext").value=opennote;
    }

    function setExtern(){
        var testnote=opennote.toLowerCase().replaceAll((/[\r\n]+/g)," ");
         if (testnote.includes("cs:")){
            var csName=testnote.split("cs:")[1].split(" ")[0];
            if (csName.length>2){
                document.getElementById("csStatus").innerHTML="";
                document.getElementById("csName").innerHTML=csName;
                document.getElementById("csName").href="https://camsoda.com/"+csName;
                document.getElementById("csCheck").addEventListener("click",function(){csCheck(document.getElementById("csName").innerHTML);});
                document.getElementById("csProf").style.display="";
            }
        }
        if (testnote.includes("sc:")){
            var scName=testnote.split("sc:")[1].split(" ")[0];
            if (scName.length>2){
                document.getElementById("scStatus").innerHTML="";
                document.getElementById("scName").innerHTML=scName;
                document.getElementById("scName").href="https://stripchat.com/"+scName;
                document.getElementById("scCheck").addEventListener("click",function(){scCheck(document.getElementById("scName").innerHTML);});
                document.getElementById("scProf").style.display="";
            }
        }
        if (testnote.includes("sm:")){
            var smName=testnote.split("sm:")[1].split(" ")[0];
            if (smName.length>2){
                document.getElementById("smStatus").innerHTML="";
                document.getElementById("smName").innerHTML=smName;
                document.getElementById("smName").href="https://streamate.com/cam/"+smName;
                document.getElementById("smCheck").addEventListener("click",function(){smCheck(document.getElementById("smName").innerHTML);});
                document.getElementById("smProf").style.display="";
            }
        }
        if (testnote.includes("bc:")){
            var bcName=testnote.split("bc:")[1].split(" ")[0];
            if (bcName.length>2){
                document.getElementById("bcStatus").innerHTML="";
                document.getElementById("bcName").innerHTML=bcName;
                document.getElementById("bcName").href="https://bongacams.com/"+bcName;
                document.getElementById("bcCheck").addEventListener("click",function(){bcCheck(document.getElementById("bcName").innerHTML);});
                document.getElementById("bcProf").style.display="";
            }
        }
        if (testnote.includes("c4:")){
            var c4Name=testnote.split("c4:")[1].split(" ")[0];
            if (c4Name.length>2){
                document.getElementById("c4Status").innerHTML="";
                document.getElementById("c4Name").innerHTML=c4Name;
                document.getElementById("c4Name").href="https://cam4.com/"+c4Name;
                document.getElementById("c4Check").addEventListener("click",function(){c4Check(document.getElementById("c4Name").innerHTML);});
                document.getElementById("c4Prof").style.display="";
            }
        }
        if (testnote.includes("mfc:")){
            var mfcName=testnote.split("mfc:")[1].split(" ")[0];
            if (mfcName.length>2){
                document.getElementById("mfcStatus").innerHTML="";
                document.getElementById("mfcName").innerHTML=mfcName;
                document.getElementById("mfcName").href="https://myfreecams.com/#"+mfcName;
                document.getElementById("mfcCheck").addEventListener("click",function(){mfcCheck(document.getElementById("mfcName").innerHTML);});
                document.getElementById("mfcProf").style.display="";
            }
        }
    }

    function wprof(col1,col2,id){
        var container=document.getElementsByClassName("BioTabContentDesktop__table")[0].getElementsByTagName("tbody")[0];
        var newtr=document.createElement('tr');
        if (id){newtr.id=id;}
        if (id!="k"){
            newtr.setAttribute("name", "info");
        }
        newtr.className=("AboutMeTable BioTabContentDesktop__tableRow");
        var newtd=document.createElement('td');
        newtd.className="BioTabContentDesktop__label";
        newtd.innerHTML=col1;
        newtr.appendChild(newtd);
        var newtd2=document.createElement('td');
        newtd2.className="BioTabContentDesktop__description";
        newtd2.innerHTML=col2;
        newtr.appendChild(newtd2);
        container.insertBefore(newtr, container.getElementsByTagName("tr")[1]);
    }

    function newinfo(easy){
        if (fetching!==0){alert("Slow down !");return;}
        if (regiofetch){alert("Please wait !");return;}
        regiofetch=true;
        if (easy!=1){
            localStorage.setItem("regloaded","bar");
        }
        if(document.getElementById("rulespop")){document.getElementById("rulespop").style.display="none";}
        var tags=document.getElementsByName("info");
  		for(i=tags.length-1;i>=0;i--){
            tags[i].remove();
        }
        info(true);
    }

    function cleaninit(){
        var p=0;
        var maxoke="";
        var attr="";
        var tags=document.querySelectorAll('[rel="nofollow"]');
        for (n=0; n<tags.length; n++){
            if (tags[n].style.position){
                if (tags[n].style.position=="fixed"){
                    tags[n].style.position="absolute";
                }
                if (tags[n].style.position.indexOf("var")!=-1){
                    tags[n].style.position="absolute";
                }
                if (tags[n].style.position.indexOf("absolute")!=-1){
                    if (tags[n].getAttribute("style").indexOf("!important")!=-1){
                        attr=tags[n].getAttribute("style");
                        attr=attr.split("!important").join("");
                        tags[n].setAttribute("style",attr);
                    }
                    tags[n].classList.add("profpos");
                    p++;
                }
            }
            if (tags[n].style.top){
                if (parseInt(tags[n].style.top) <-30){
                    tags[n].classList.add("profpos");
                    p++;
                }
            }
            if (tags[n].style.marginTop){
                maxoke=-30;
                if(tags[n].style.marginTop.indexOf("px")!=-1){maxoke=-200;}
                if (parseFloat(tags[n].style.marginTop)<maxoke){
                    if (tags[n].getAttribute("style").indexOf("!important")!=-1){
                        attr=tags[n].getAttribute("style");
                        attr=attr.split("!important").join("");
                        tags[n].setAttribute("style",attr);
                    }
                    tags[n].classList.add("profmar");
                    p++;
                }
            }
            if (tags[n].style.margin){
                maxoke=-30;
                if(tags[n].style.margin.split(" ")[0].indexOf("px")!=-1){maxoke=-200;}
                if (parseFloat(tags[n].style.margin)<maxoke){
                    if (tags[n].getAttribute("style").indexOf("!important")!=-1){
                        attr=tags[n].getAttribute("style");
                        attr=attr.split("!important").join("");
                        tags[n].setAttribute("style",attr);
                    }
                    tags[n].classList.add("profmar");
                    p++;
                }
            }
            if (tags[n].style.cursor){
                if (tags[n].getAttribute("style").indexOf("!important")!=-1){
                    attr=tags[n].getAttribute("style");
                    attr=attr.split("!important").join("");
                    tags[n].setAttribute("style",attr);
                }
                tags[n].classList.add("profcur");
                p++;
            }
        }
        document.getElementById("clean").style.display="none";
        if (p!==0){
            document.getElementById("clean").style.display="inline-flex";
            cleanup();
        }
    }

	function cleancookie(){
        if (localStorage.getItem("pclean")){
            localStorage.removeItem("pclean");
		}else{
            localStorage.setItem("pclean", "foo");
        }
		cleanup();
	}

    function cleanup(){
        var claction=!localStorage.getItem("pclean");
        if (claction){
            document.getElementById("clean").innerHTML= "Clean Profile = On&nbsp;";
            document.body.classList.add("cleanprof");
        }else{
            document.getElementById("clean").innerHTML= "Clean Profile = Off";
            document.body.classList.remove("cleanprof");
        }
    }

    function linkfix(){
        var bioarea= document.getElementsByClassName('BioContents')[0];
        var tags = bioarea.getElementsByTagName('a');
        for (i=0; i<tags.length; i++){
            if (tags[i].href.indexOf('?url=') != -1){
                var linkout=decodeURIComponent(tags[i].href).split("?url=")[1];
                tags[i].href=linkout;
            }
         }
    }

    function collectiondownload(){
        document.getElementById("main").addEventListener("click", collectiondownload2);
        collectiondownload2();
    }

    function collectiondownload2(){
        setTimeout(function(){collectiondownload3();}, 2000);
    }

    function collectiondownload3(){
        if(document.getElementsByTagName("video").length>0){
            if(document.getElementsByTagName("video")[0].src){
                if(!document.getElementById("link")){
                    var newelem=document.createElement('a');
                    newelem.id="link";
                    newelem.style.position="relative";
                    newelem.style.left="250px";
                    newelem.style.top="5px";
                    newelem.href= document.getElementsByTagName("video")[0].src;
                    newelem.target="_blank";
                    newelem.innerHTML="Right click, save to disk.";
                    newelem.style.backgroundColor="white";
                    newelem.style.marginLeft="20px";
                    document.getElementsByClassName("createdAt")[0].parentNode.appendChild(newelem);
                }
            }
        }
    }

    function savedprvdownload(){
        setTimeout(function(){savedprvdownload3();}, 2000);
    }

    function savedprvdownload3(){
        var newelem=document.createElement('a');
        newelem.href= document.getElementsByTagName("video")[0].src;
        newelem.target="_blank";
        newelem.innerHTML="Right click, save to disk.<br>";
        newelem.style.backgroundColor="white";
        newelem.style.marginLeft="20px";
        document.getElementById("tsRecordedShowPlayer").appendChild(newelem);
    }

    function passwordfollow(){
        setTimeout(function(){
            var unfollow=document.querySelector('[data-testid="unfollow-button"]');
            var follow=document.querySelector('[data-testid="follow-button"]');
            document.getElementsByClassName("tooltip")[0].parentNode.style.display="block";
            if (unfollow.style.display=="none"){
                follow.style.display="block";
            }
            unfollow.addEventListener("click", function(){
                setTimeout(function(){
                    follow.style.display="block";
                    unfollow.style.display="none";
                }, 500);} );
            follow.addEventListener("click", function(){
                setTimeout(function(){
                    unfollow.style.display="block";
                    follow.style.display="none";
                }, 500);} );
        }, 1000);
        var newelem=document.createElement('div');
        newelem.className="BioTabContentDesktop__table";
        var newtable=document.createElement('table');
        newtable.innerHTML='<colgroup><col class="BioTabContentDesktop__labelCol"><col></colgroup><tbody><tr></tr><tr></tr></tbody>';
        newelem.appendChild(newtable);
        document.getElementsByClassName("defaultColor")[0].appendChild(newelem);
        if(document.querySelector('[name="twitter:image"]')){
            document.getElementsByClassName("PasswordPrompt")[0].style.minHeight="550px";
            var limg=document.querySelector('[name="twitter:image"]').getAttribute("content");
            newelem=document.createElement('img');
            newelem.src=limg;
            newelem.className="profplayer";
            newelem.id="profimg";
            newelem.style.top="100px";
            newelem.style.right="50px";
            newelem.style.height="480px";
            newelem.style.maxWidth="854px";
            document.querySelector('[id="tsContent"]').appendChild(newelem);
        }
        var butt=document.getElementsByClassName("button")[0];
        var newbutt=butt.cloneNode(true);
        document.getElementsByTagName("form")[0].appendChild(newbutt);
        document.getElementsByClassName("button")[1].value="Login to profile";
        document.getElementsByClassName("button")[1].addEventListener("click", function(event){
            event.stopPropagation();
            event.preventDefault();
            passenter();
        });
        var dmurl="messages/";
        if (document.getElementById("dmListIconRoot")){dmurl="dm/";}
        wprof("Archive:","<a href='https://recu.me/performer/"+roomname+"' rel=noreferrer target='_new'>Open in recu</a>");
        wprof("Find:","<a href='https://camgirlfinder.net/models/cb/"+roomname+"' rel=noreferrer target='_new'>Open in camgirlfinder</a>");
        wprof("Statistics:","<a href='https://statbate.com/search/1/"+roomname+"' rel=noreferrer target='_new'>Open in statbate</a>");
        wprof ("DM/PM:","<a href='"+domain+dmurl+roomname+"/' id='dmpop'>Open window</a>");
        wprof("Video:",'<div id="rstatus"></div>');
        wprof("Video status:","<a href=# id='hls'>Update status</a>");
        wprof("Check:","Off <input type='range' id='pwalrm' min=0 max=1 value=0 style='width: 35px;height:auto;cursor: pointer'> On || Enter the room if you get access.");
        document.getElementById("pwalrm").addEventListener("change",setpwalrm);
        getnewhls(true,false);
        document.getElementById("hls").addEventListener("click",function(){getnewhls(true,true);});
        document.getElementById("dmpop").addEventListener("click", function(event){opendm3(this);event.stopPropagation();event.preventDefault();return false;});
        getnotes();
        document.getElementsByClassName("tooltip")[0].innerHTML="If follow does not work this room banned your region or gender.";
        document.getElementsByClassName("tooltip")[0].style.marginLeft="-300px";
        document.getElementById("tsContent").style.minHeight="400px";
    }

    function setpwalrm(){
        if (document.getElementById("pwalrm").value==0){return;}
        if (alarmrun==false){
            alarmrun=true;
            checkpwalarm();
        }
    }

    function checkpwalarm(){
        setTimeout(function(){
            if(document.getElementById("pwalrm").value==0){alarmrun=false;return;}
            var url=domain+"api/chatvideocontext/"+roomname+"/";
            fetch(url,{credentials: "same-origin"}).then(
            function(response) {
                if (response.status == 200){
                    forceopen(roomname);
                    return;
                }
                checkpwalarm();
            });
        },60000);
    }

    function passenter(){
        var url=domain+"api/ts/chat/roomloginform/"+roomname+"/";
        var csrftoken= readCookie("csrftoken");
        var passw=document.querySelector('[data-testid="room-password-input"]').value;
        if (passw==""){return;}
        var data = new FormData();
        data.append( "password", passw );
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+"roomlogin"+roomname+"/",
            body: data
        }).then(
            function(response){
                if (response.status == 201){
                    document.location.href=domain+"p/"+username+"/?tab=bio&model="+roomname;
                }else{
                    document.getElementsByClassName("fieldError")[0].innerHTML="Wrong guess.";
                    document.getElementsByClassName("fieldError")[0].style.display="block";
                }
            });
    }

    function forceopen(room){
        window.focus();
        setTimeout(function(){document.location.href=domain+room;},1000);
    }

    function opendm3(that){
       window.open(that.href,'DMpop','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1000,height=800');
    }

    function bannedroom(){
        var url=domain+"api/chatvideocontext/"+roomname+"/";
        fetch(url,{credentials: "omit"}).then(
            function(response) {
                if (response.status !== 200){
                    noaccess=true;
                    response.json().then(function(data){
                        if (data.detail=="This room has been banned."){
                            setprofile(0);
                            return;
                        }
                        if (data.detail=="Room is deleted"){
                            setprofile(2);
                            return;
                        }
                        setprofile(1);
                    });
                }else{
                    document.location.href=domain+'p/'+username+'?tab=bio&model='+roomname;
                    return;
                }
            });
    }

    function setprofile(type){
        document.querySelector('[ts="RoomDeniedMessageWrapper"]').innerHTML="";
        document.querySelector('[ts="RoomDeniedMessageWrapper"]').style.paddingRight="20px";
        var newelem=document.createElement('div');
        newelem.id="roomTabs";
        newelem.className="evolveMode";
        newelem.style.height="100%";
        newelem.style.width="100%";
        newelem.style.position="static";
        newelem.style.overflow="visible";
        newelem.style.boxSizing="border-box";
        newelem.style.minHeight="325px";
        newelem.setAttribute("data-testid","room-tabs");
        document.querySelector('[ts="RoomDeniedMessageWrapper"]').appendChild(newelem);
        newelem=document.createElement('div');
        newelem.className="tabBar";
        newelem.setAttribute("data-testid","room-tab-bar");
        newelem.style.height="50px";
        document.getElementById("roomTabs").appendChild(newelem);
        newelem=document.createElement('div');
        newelem.className="RoomTabBar__roomActionWrapper";
        newelem.style.height="50px";
        document.getElementsByClassName("tabBar")[0].appendChild(newelem);
        newelem=document.createElement('div');
        newelem.id="tabs_content_container";
        newelem.className="BioContents";
        newelem.setAttribute("data-testid","room-bio-tab-contents");
        document.getElementById("roomTabs").appendChild(newelem);
        newelem=document.createElement('div');
        newelem.setAttribute("data-testid","bio-tab-content-desktop");
        newelem.className="BioTabContentDesktop__table";
        newelem.style.margin="20px";
        newelem.style.height="1010px";
        var newtable=document.createElement('table');
        newtable.innerHTML='<colgroup><col class="BioTabContentDesktop__labelCol"><col></colgroup><tbody><tr></tr><tr></tr></tbody>';
        newelem.appendChild(newtable);
        document.getElementById("tabs_content_container").appendChild(newelem);
        if (type==1){
            putinlinks();
            makevidcontrol();
            getnewhls(true,false,1);
            setTimeout(function(){
                if (room_status!="public"){
                    if(room_status.indexOf("watching")==-1){
                        document.getElementById("vcontr").style.display="none";
                        document.getElementById("controls").style.display="none";
                    }
                }
            },1000);
        }
        if (type==0){
            putinlinks2();
        }
        if (type==2){
            putinlinks3();
        }
    }

    function putinlinks3(){
        if(document.querySelector('[name="twitter:image"]')){
            var limg=document.querySelector('[name="twitter:image"]').getAttribute("content");
            var newelem=document.createElement('img');
            newelem.src=limg;
            newelem.className="profplayer";
            newelem.id="profimg";
            newelem.style.height="480px";
            newelem.style.maxWidth="854px";
            document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newelem);
        }
        wprof("Archive:","<a href='https://recu.me/performer/"+roomname+"' rel=noreferrer target='_new'>Open in recu</a>");
        wprof("Find:","<a href='https://camgirlfinder.net/models/cb/"+roomname+"' rel=noreferrer target='_new'>Open in camgirlfinder</a>");
        wprof("Statistics:","<a href='https://statbate.com/search/1/"+roomname+"' rel=noreferrer target='_new'>Open in statbate</a>");
        wprof("Schedule:","<a href='https://www.cbhours.com/user/"+roomname+".html' rel=noreferrer target='_new' id='userview'>Open in cbhours</a>");
        wprof("<b>Access denied:</b>","<b>This room is deleted.</b>");
    }

    function putinlinks2(){
        if(document.querySelector('[name="twitter:image"]')){
            var limg=document.querySelector('[name="twitter:image"]').getAttribute("content");
            var newelem=document.createElement('img');
            newelem.src=limg;
            newelem.className="profplayer";
            newelem.id="profimg";
            newelem.style.height="480px";
            newelem.style.maxWidth="854px";
            document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newelem);
        }
        wprof("Archive:","<a href='https://recu.me/performer/"+roomname+"' rel=noreferrer target='_new'>Open in recu</a>");
        wprof("Find:","<a href='https://camgirlfinder.net/models/cb/"+roomname+"' rel=noreferrer target='_new'>Open in camgirlfinder</a>");
        wprof("Statistics:","<a href='https://statbate.com/search/1/"+roomname+"' rel=noreferrer target='_new'>Open in statbate</a>");
        wprof("Schedule:","<a href='https://www.cbhours.com/user/"+roomname+".html' rel=noreferrer target='_new' id='userview'>Open in cbhours</a>");
        wprof ("DM/PM:","<a href='"+domain+"messages/"+roomname+"/' id='dmpop'>Open window (to check status)</a>");
        wprof("<b>Access denied:</b>","<b>This room is banned.</b>");
        document.getElementById("dmpop").addEventListener("click", function(event){opendm3(this);event.stopPropagation();event.preventDefault();return false;});
    }


    function putinlinks(){
        wprof("","<a href=# id=moreinfo>Click here to search for more info.</a>");
        document.getElementById("moreinfo").addEventListener("click",moreinfo);
        wprof("Archive:","<a href='https://recu.me/performer/"+roomname+"' rel=noreferrer target='_new'>Open in recu</a>");
        wprof("Find:","<a href='https://camgirlfinder.net/models/cb/"+roomname+"' rel=noreferrer target='_new'>Open in camgirlfinder</a>");
        wprof("Statistics:","<a href='https://statbate.com/search/1/"+roomname+"' rel=noreferrer target='_new'>Open in statbate</a>");
        wprof("Schedule:","<a href='https://www.cbhours.com/user/"+roomname+".html' rel=noreferrer target='_new' id='userview'>Open in cbhours</a>");
        wprof("Video status:","<a href=# id='hls'>Update status</a>");
        document.getElementById("hls").addEventListener("click",function(){getnewhls(true,true,1);});
        wprof("Video:",'<div id="rstatus">'+room_status+'</div>');
        wprof("Nationality:","<span id='flaginfo'>wait....</span>");
        wprof("Region:","<span id='regioninfo'>wait....</span>");
        setTimeout(function(){
            getregion(false);
        },1000);
        if(login){
            getnotes();
        }
        wprof ("DM/PM:","<a href='"+domain+"messages/"+roomname+"/' id='dmpop'>Open window (to check status)</a>");
        wprof("<b>Access denied:</b>","<b>No access due to your region or gender.</b>");
        document.getElementById("dmpop").addEventListener("click", function(event){opendm3(this);event.stopPropagation();event.preventDefault();return false;});
    }

    function moreinfo(){
        if (room_status!="public"){
            document.getElementById("moreinfo").innerHTML="Room is not public.";
            setTimeout(function(){document.getElementById("moreinfo").innerHTML="Click here to search for more info.";},3000);
            return;
        }
        document.getElementById("moreinfo").removeEventListener("click",moreinfo);
        document.getElementById("moreinfo").innerHTML="Please wait....";
        var dataurl=domain+"affiliates/api/onlinerooms/?format=json&wm=DEieF";
        fetch(dataurl,{credentials: "omit",referrerPolicy: "no-referrer"}).then(
            function(response) {
                if (response.status !== 200){
                    document.getElementById("moreinfo").innerHTML="Error reading roomlist.";
                    return;
                }
                response.json().then(function(data) {
                    for (n=0; n<data.length; n++){
                        if (data[n].username==roomname){
                            wprof("Gender:",data[n].gender);
                            wprof("Given location:",data[n].location);
                            if (data[n].country !=""){
                                if (document.getElementById("flaginfo").innerHTML!=data[n].country){
                                    wprof("Nationality:",data[n].country);
                                }
                            }
                            wprof("Room topic:","<div style='width:450px;height:auto'>"+data[n].room_subject+"</div>");
                            wprof("Spoken languages:",data[n].spoken_languages);
                            wprof("Name:", data[n].display_name);
                            wprof("Birthday:",data[n].birthday);
                            wprof("Age:",data[n].age);
                            wprof("Time online:",toTime(data[n].seconds_online));
                            wprof("Users in room:",data[n].num_users);
                            wprof("Followers:",data[n].num_followers);
                            document.getElementById("moreinfo").innerHTML="";
                            data="";
                            break;
                        }
                    }
                    if (n==data.length){
                        document.getElementById("moreinfo").innerHTML="No information found, user may no longer be in public or opt-out.";
                        setTimeout(function(){
                            document.getElementById("moreinfo").innerHTML="Click here to search for more info.";
                            document.getElementById("moreinfo").addEventListener("click",moreinfo);
                        },3000);
                    }
                    data="";
                });
            });
    }

    function toTime(seconds) {
        var date = new Date(null);
        date.setSeconds(seconds);
        return date.toISOString().substr(11, 8).replace(":","h").replace(":","m")+"s";
    }

	function createCookie(name,value,days,cdomain){
        var expires="";
        if (cdomain){
            cdomain=";domain=."+cdomain;
        }else{
            cdomain = "";
        }
        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=/"+cdomain;
	}

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

    function rebuildbio(){
        document.getElementsByClassName("BioTabContentDesktop__title")[0].innerHTML="";
        document.querySelector('[data-testid="bio-tab-real-name-value"]').innerHTML="Loading.....";
        document.getElementsByClassName("BroadcastRoomTabBar__tabWrapper")[0].remove();
        document.getElementsByClassName("BioTabContentDesktop__editButton")[0].remove();
        var newelem=document.createElement('div');
        newelem.className="RoomTabBar__roomActionWrapper";
        newelem.style.height="50px";
        document.getElementsByClassName("tabBar")[0].appendChild(newelem);
        removebionode();
        document.title=tocap(roomname) + "'s Bio";
        ctitle=document.title;
        getbiodata(true);
    }

    function tocap(name){
        if (!name){return "";}
        return name.charAt(0).toUpperCase()+name.slice(1);
    }

    function getbiodata(anon){
        var cred="same-origin";
        if (!anon){cred="omit";}
        var url=domain+"api/biocontext/"+roomname;
        fetch(url,{ credentials: cred,referrer: domain+roomname+"/"}).then(
            function(response) {
                if (response.status !== 200){
                    if (anon){
                        getbiodata(false);
                        return;
                    }
                    document.location.href=domain+roomname+"/";
                    return;
                }
                response.json().then(function(data) {
                    biodata=data;
                    buildbio();
                    afterrebuild();
                });
            });
    }

    function removebionode(){
        if (document.getElementsByClassName("BioContents")[0].getElementsByTagName("table")[0].getElementsByTagName("tr")[2]){
            document.getElementsByClassName("BioContents")[0].getElementsByTagName("table")[0].getElementsByTagName("tr")[2].remove();
            removebionode();
        }
    }

    function buildbio(){
        if (biodata.wish_list){
            wprof("Wish List:",biodata.wish_list,"k");
        }
        wprof("About Me:",biodata.about_me,"k");
        if (biodata.photo_sets[0]){
            wprof("Photo/video:","<a href='"+domain+"photo_videos/photoset/detail/"+roomname+"/"+biodata.photo_sets[0].id+"' target=_blank> Open in new tab.</a>","k");
        }
        if (biodata.social_medias[0]){
            wprof("Social Media:","Available on cam page.","k");
        }
        if (biodata.body_decorations){
            wprof("Body Decorations:",tocap(biodata.body_decorations),"k");
        }
        if (biodata.smoke_drink){
            wprof("Smoke / Drink:",tocap(biodata.smoke_drink),"k");
        }
        if (biodata.body_type){
            wprof("Body Type:",tocap(biodata.body_type),"k");
        }
        if (biodata.languages){
            wprof("Language(s):",tocap(biodata.languages),"k");
        }
        if (biodata.time_since_last_broadcast){
            wprof("Last Broadcast:",biodata.time_since_last_broadcast,"k");
        }
        if (biodata.location){
            wprof("Location:",tocap(biodata.location),"k");
        }
        if(biodata.interested_in[0]||biodata.interested_in[1]||biodata.interested_in[2]||biodata.interested_in[3]){
            wprof("Interested In:",tocap(biodata.interested_in[0])+" "+tocap(biodata.interested_in[1])+" "+tocap(biodata.interested_in[2])+" "+tocap(biodata.interested_in[3]),"k");
        }
        wprof("I Am:",tocap(biodata.sex),"k");
        if (biodata.display_age){
            wprof("Age:",biodata.display_age,"k");
        }
        if (biodata.display_birthday){
            wprof("Birth Date:",biodata.display_birthday,"k");
        }
        wprof("Followers:",biodata.follower_count,"k");
        if (biodata.real_name){
            wprof("Real Name:",tocap(biodata.real_name),"k");
        }
        document.querySelector('[data-testid="bio-tab-real-name-value"]').parentNode.remove();
    }

    function getnewhls(anon,clicked,next){
        if (hlsfetching==true){return;}
        hlsfetching=true;
        var cred="same-origin";
        if (!anon){cred="omit";}
        var oldmsg=document.getElementById("hls").innerHTML;
        if(clicked){
            document.getElementById("hls").innerHTML="Updating....";
        }else{
            document.getElementById("hls").innerHTML="Checking....";
        }
        var url=domain+"get_edge_hls_url_ajax/";
        var csrftoken= readCookie("csrftoken");
        var edge="";
        if (videoSrc!=""){
            edge=videoSrc.split("/")[2];
        }
        var data = new FormData();
        data.append( "room_slug", roomname );
        data.append( "jpeg", 1 );
        if (next==1){
            data.append( "bandwidth", "high" );
            data.append( "current_edge", edge );
            data.append( "exclude_edge", "" );
        }
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,{
            credentials: cred,
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+roomname+"/",
            body: data
        }).then(function(response){
            if (response.status !== 200) {
                if (anon){
                    hlsfetching=false;
                    getnewhls(false,clicked,next);
                    return;
                }
                document.getElementById("hls").innerHTML=oldmsg;
                if (next==2){testalarm2();}
                hlsfetching=false;
                return;
            }
            response.json().then(function(data){
                var oldstatus=document.getElementById("rstatus").innerHTML;
                document.getElementById("rstatus").innerHTML=data.room_status;
                roomstatus=data.room_status;
                room_status=data.room_status;
                videoSrc=data.url;
                if (!next){
                    if ((pageType!="ppage")||(pageType!="profile")){
                        if ((oldstatus !="private")&&(data.room_status == "private")){
                            newinfo(1);
                        }
                    }
                }
                if (data.room_status != "private"){
                    if (document.getElementById("premium")){
                        document.getElementById("premium").style.display="none";
                    }
                }
                document.getElementById("hls").innerHTML=oldmsg;
                if (pageType=="ppage"){
                        if(!next){
                            var cansee=true;
                            var couldsee=false;
                            if (data.url==""){cansee=false;}
                            if (oldstatus=="public"){couldsee=true;}
                            if (oldstatus.includes("watching")){couldsee=true;}
                            if (couldsee != cansee){newinfo(1);}
                    }
                }
                if (clicked){navigator.clipboard.writeText(videoSrc);}
                hlsfetching=false;
                if (next==1){createimage();}
                if (next==2){testalarm2();}
                if (next==3){startvid2();}
            });
        });
    }

    function getregion(again){
        for(i=0;i < region.length;i++) {
            if (!localStorage.getItem("region_"+region[i])){
               localStorage.removeItem("regloaded");
            }
        }
        if (localStorage.getItem("regloaded")=="bar"){
            loadregion();
            return;
        }
        if (localStorage.getItem("regloaded")){
            for(i=0;i < region.length;i++) {
                regioarray=JSON.parse(localStorage.getItem("region_"+region[i]));
                 if (regioarray.indexOf(roomname)!=-1){
                    document.getElementById("regioninfo").innerHTML=niceregion[i];
                    if (regioarray[regioarray.indexOf(roomname)+1].length==2){
                        document.getElementById("flaginfo").innerHTML=regioarray[regioarray.indexOf(roomname)+1];
                     }else{
                        document.getElementById("flaginfo").parentNode.parentNode.style.display="none";
                    }
                     regiofetch=false;
                     document.getElementById("userview").style.display="initial";
                     return;
                }
            }
            if ((room_status=="offline")||(room_status=="away")){
                document.getElementById("regioninfo").parentNode.parentNode.style.display="none";
                document.getElementById("flaginfo").parentNode.parentNode.style.display="none";
                regiofetch=false;
                document.getElementById("userview").style.display="initial";
                return;
            }
            if(!again){
                loadregion();
                return;
            }
        }else{
            if(!again){
                loadregion();
                return;
            }
        }
        regiofetch=false;
        document.getElementById("userview").style.display="initial";
        document.getElementById("regioninfo").parentNode.parentNode.style.display="none";
        document.getElementById("flaginfo").parentNode.parentNode.style.display="none";
    }

    function loadregion(){
        regioarray=[];
        if (localStorage.getItem("regloaded")){
            regioarray=JSON.parse(localStorage.getItem("region_"+region[rcount]));
        }
        getregiondata();
    }

    function getregiondata(){
        var url=domain+"api/public/affiliates/onlinerooms/?limit=500&offset="+regoffset*500+"&region="+region[rcount]+"&wm=DEieF&client_ip=212.77.7.51";
        fetch(url,{ credentials: "omit"}).then(
            function(response) {
                if (response.status !== 200) {
                    return;
                }
                response.json().then(function(data){
                    if (data.results != null){
                        var regiolist=data.results;
                        for (n=0; n<regiolist.length; n++){
                            var name=regiolist[n].username;
                            if (regioarray.indexOf(name)==-1){
                                var flag=regiolist[n].country;
                                regioarray.push(name);
                                if (flag.length==2){
                                    regioarray.push(flag);
                                }
                            }
                        }
                        var pages=Math.ceil(data.count/500);
                        regoffset++;
                        if (regoffset!=pages){
                            getregiondata();
                            return;
                        }else{
                            regioarray.push("");
                            localStorage.setItem("region_"+region[rcount],JSON.stringify(regioarray));
                            rcount++;
                            regoffset=0;
                            if (rcount!=region.length){
                                loadregion();
                            }else{
                                rcount=0;
                                localStorage.setItem("regloaded","foo");
                                getregion(true);
                            }
                        }
                    }
                });
            });
    }

    function bantoggle(){
        if (document.getElementById("banlist").style.display=="none"){
            document.getElementById("banlist").style.display="block";
            banusers=[];
            getbanlist(1);
        }else{
            document.getElementById("banusers").innerHTML="";
            document.getElementById("unbanbut").removeEventListener("click", unbanit );
            document.getElementById("permbut").removeEventListener("click", permban );
            document.getElementById("banlist").style.display="none";
        }
    }

    function getbanlist(page){
        var url=domain+"api/ts/chat/ban-list/?page="+page;
        var nowdate=new Date();
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    return;
                }
                response.json().then(function(data){
                    var selectnode=document.getElementById("banusers");
                    var option=document.createElement('option');
                    option.textContent="Select a user.";
                    option.value=0;
                    selectnode.appendChild(option);
                    var banlist=data.ban_dict.bans;
                    for (n=0; n<banlist.length; n++){
                        var expdate=new Date(banlist[n].expires_at);
                        var expwhen=expdate-nowdate;
                        var expdays=Math.ceil(expwhen/86400000);
                        option=document.createElement('option');
                        option.textContent=banlist[n].username;
                        if (expdays>100){
                            option.textContent=option.textContent+" 🔒";
                        }else{
                            option.textContent=option.textContent+" ("+expdays+" days)";
                        }
                        option.value=banlist[n].id;
                        selectnode.appendChild(option);
                        banusers.push(banlist[n].username);
                    }
                    if (data.ban_dict.current_page!=data.ban_dict.page_count){
                        page++;
                        getbanlist(page);
                        return;
                    }
                    localStorage.setItem("ignoredusers",banusers.toString());
                    document.getElementById("unbanbut").addEventListener("click", unbanit );
                    document.getElementById("permbut").addEventListener("click", permban );
                });
            });
    }

    function unbanit(){
        var banid=document.getElementById("banusers").options[document.getElementById("banusers").selectedIndex].value;
        if (banid==0){return;}
        var url=domain+"edit_room_ban/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "banid", banid);
        data.append( "action", "remove_ban");
        data.append( "room_username", username);
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,{
            credentials: "same-origin",
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+username+"/",
            body: data
        }).then(function(response){
            if (response.status !== 200) {
                alert("Error "+response.status);
                return;
            }
            document.getElementById("banusers").innerHTML="";
            banusers=[];
            getbanlist(1);
       });
    }

    function permban(){
        var banid=document.getElementById("banusers").options[document.getElementById("banusers").selectedIndex].value;
        if (banid==0){return;}
        if (document.getElementById("banusers").options[document.getElementById("banusers").selectedIndex].textContent.split(" ").length<3){return;}
        var url=domain+"edit_room_ban/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "banid", banid);
        data.append( "action", "ban_perm");
        data.append( "room_username", username);
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,{
            credentials: "same-origin",
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+username+"/",
            body: data
        }).then(function(response){
            if (response.status !== 200) {
                alert("Error "+response.status);
                return;
            }
            document.getElementById("banusers").innerHTML="";
            banusers=[];
            getbanlist(1);
       });
    }

    function unfollowthispage(){
        var thumbholder=document.getElementsByClassName("RoomCardGrid")[0];
        roomthumbs=thumbholder.getElementsByClassName("RoomCard");
        nrt=roomthumbs.length;
        if(confirm("Do you want to unfollow these "+thumbholder.querySelectorAll('[title="Unfollow"]').length+" rooms?\n(and earase the notes)")){
            thumbobserver1.disconnect();
            document.getElementById("unfollowit").removeEventListener("click",unfollowthispage);
            unfollowroom2();
        }
    }

    function unfollowroom(){
        setTimeout(unfollowroom2,600);
    }

    function unfollowroom2(){
        document.getElementById("unfollowit").innerHTML="<a href=#>WAIT... "+nrt+"</a>";
        nrt--;
        if (nrt<0){
            var page=parseInt(document.location.href.split("page=")[1]);
            if (page){page--;}
            document.location.href=domain+"followed-cams/offline/?page="+page;
        }
        followstar=roomthumbs[nrt].querySelector('[data-testid="follow-star"]');
        var name=roomthumbs[nrt].querySelector('[class="RoomCardUserDetails__username"]').innerHTML;
        if (followstar.title=="Unfollow"){
            unfollowpage(name);
        }else{
            followpage(name);
        }

    }

    function followpage(name){
        var url=domain+"follow/follow/"+name+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "location", "FollowButton" );
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+roomname+"/",
            body: data
        }).then(function(){
            followstar.title="Unfollow";
            unfollowroom();
        });
    }

    function unfollowpage(name){
        var url=domain+"follow/unfollow/"+name+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "location", "FollowButton" );
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            body: data
        }).then(function(response){
            if (response.status !== 200) {
                alert("Unfollowing failed.");
                return;
            }
            clearnote(name);
        });
    }

    function clearnote(name){
        var url=domain+"api/notes/for_user/"+name+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "text", "" );
        fetch(url,
              {
            method: "POST",
            headers: {
                'x-csrftoken': csrftoken,
                'x-requested-with': 'XMLHttpRequest'
            },
            body: data
        }).then(function(){
            if (name==roomname){makeban2(name);return;}//for ban
            roomthumbs[nrt].remove();
            unfollowroom();
        });
    }

    function getignorelist(){
        if (!login){return;}
        if (localStorage.getItem("ignoredusers")){
            checkignore();
            return;
        }
        getignoreusers(1);
    }

    function getignoreusers(page){
        var url=domain+"api/ts/chat/ban-list/?page="+page;
        fetch(url,{ credentials: "same-origin"}).then(
            function(response) {
                if (response.status !== 200) {
                    return;
                }
                response.json().then(function(data){
                    var banlist=data.ban_dict.bans;
                    for (n=0; n<banlist.length; n++){
                        banusers.push(banlist[n].username);
                    }
                    if (data.ban_dict.current_page!=data.ban_dict.page_count){
                        page++;
                        getignoreusers(page);
                        return;
                    }
                    localStorage.setItem("ignoredusers",banusers.toString());
                    checkignore();
                });
            });
    }

    function checkignore(){
        if (roomname==""){return;}
        banusers=localStorage.getItem("ignoredusers").split(",");
        if (banusers.indexOf(roomname)!=-1){
            document.location.href=domain;
        }

        if (roomname=="roomlogin"){
            if (banusers.indexOf(currpage.split("/")[4])!=-1){
                document.location.href=domain;
            }
        }
        if(pageType=="ppage"){
            if (currpage.split("model=").length==1){return;}
            if (roomname==username){return;}
            if (banusers.indexOf(currpage.split("model=")[1].split("&")[0])!=-1){
                document.location.href=domain;
            }
        }
    }

    function banignore(){
        if ((roomname==username)||(roomname==stor)||(roomname=="p")){
            alert("Sorry, i can not let you do that.");
            return;
        }
        makeban(roomname);

    }

    function makeban(bname){
        if(!confirm("Do you want to ban/ignore "+bname+" ?\n"+bname+" will never be able to contact you and you will never be able to visit this room again.")){return;}
        unfollowpage(bname);//retour op makeban2
    }

    function makeban2(bname){// earase DM
        var url=domain+"api/messaging/delete-conversation/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "csrfmiddlewaretoken", csrftoken );
        data.append( "to_username", bname );
        fetch(url,{
            credentials: "same-origin",
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+"messages/",
            body: data
        }).then(function(){
            makeban3(bname);
        });
    }

    function makeban3(bname){
        var url=domain+"roomban/"+bname+"/"+username+"/";
        var csrftoken= readCookie("csrftoken");
        var data = new FormData();
        data.append( "csrfmiddlewaretoken", csrftoken );
        fetch(url,{
            credentials: "same-origin",
            method: "POST",
            headers: {
                'x-requested-with': 'XMLHttpRequest'
            },
            referrer: domain+username+"/",
            body: data
        }).then(function(response){
            if (response.status !== 200) {
                alert("Error "+response.status);
                return;
            }
            response.json().then(function(data){
                banusers=localStorage.getItem("ignoredusers").split(",");
                banusers.push(bname);
                localStorage.setItem("ignoredusers",banusers.toString());
                setTimeout(function(){document.location.href=domain;},200);
            });
        });
    }

    function csCheck(model){
        if (csBusy){return;}
        csBusy=true;
        setCsStatus("");
        var scStatus="unkown";
        url="https://www.camsoda.com/api/v1/chat/react/"+model+"?"+new Date().getTime();
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    setCsStatus("error "+response.status);
                    return;
                }
                var result=JSON.parse(response.responseText);
                scStatus=result.chat.status;
                if (scStatus=="online"){
                    scStatus="Online - playlist copied.";
                    var playlist="https://"+result.stream.edge_servers[0]+"/"+result.stream.stream_name+"_v1/index.m3u8?token="+result.stream.token;
                    navigator.clipboard.writeText(playlist);
                }
                if (scStatus==""){
                    scStatus="Account disabled or hidden.";
                }
                if (result.user.blockedAt != null){
                    scStatus="Account is banned till "+result.user.blockedTill.split("T")[0];
                }
                if (result.user.isDeleted){
                    scStatus="Account deleted.";
                }
                setCsStatus(scStatus);
            },
            ontimeout: function(){
                setCsStatus("Timeout error");
            }
        });
    }

    function setCsStatus(csStatus){
        if(document.getElementById("csresult")){
            document.getElementById("csresult").innerHTML=csStatus;
        }else{
            document.getElementById("csStatus").innerHTML=" "+csStatus;
        }
        setTimeout(function(){csBusy=false;},1000);
    }

    function scCheck(model){
        if (scBusy){return;}
        scBusy=true;
        setScStatus("");
        url="https://stripchat.com/api/front/users/user-ids/"+model;
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                 if (response.status !== 200){
                    setScStatus("error "+response.status);
                    return;
                }else{
                    var result=JSON.parse(response.responseText);
                    scCheck2(result.id);
                }
            },
            ontimeout: function(){
                setScStatus("Timeout error");
            }
        });
    }

    function scCheck2(id){
        var scStatus="unkown";
        url="https://stripchat.com/api/front/v2/models/"+id+"/cam?"+new Date().getTime();
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    setScStatus("error "+response.status);
                    return;
                }else{
                    var result=JSON.parse(response.responseText);
                    scStatus=result.user.user.status;
                    if (scStatus=="off"){
                        scStatus="Offline";
                    }
                    if (scStatus=="virtualPrivate"){
                        scStatus="Private";
                    }
                    if (scStatus=="p2p"){
                        scStatus="Exclusive private";
                    }
                    if (scStatus==""){
                        scStatus="Disabled or hidden.";
                    }
                    if (scStatus=="public"){
                        scStatus = "Online - playlist copied.";
                        var scId=result.user.user.id;
                        var playlist="https://edge-hls.growcdnssedge.com/hls/"+scId+"/master/"+scId+"_480p.m3u8";
                        navigator.clipboard.writeText(playlist);
                    }
                    if (result.user.isDeleted){
                        scStatus="Account is deleted.";
                    }
                    if (!result.user.isActive){
                        scStatus="Account is deactivated.";
                    }
                    if (result.user.blockedAt != null){
                        scStatus="Account is banned.";
                    }
                    if (result.user.isGeoBanned == true){
                        scStatus="Your region is banned.";
                    }
                    setScStatus(scStatus);
                }
            },
            ontimeout: function(){
                setScStatus("Timeout error");
            }
        });
    }

    function setScStatus(scStatus){
        if(document.getElementById("scresult")){
            document.getElementById("scresult").innerHTML=scStatus;
        }else{
            document.getElementById("scStatus").innerHTML=" "+scStatus;
        }
        setTimeout(function(){scBusy=false;},1000);
    }

    function smCheck(model){
        if (smBusy){return;}
        smBusy=true;
        setSmStatus("");
        var smStatus="Error";
        url="https://manifest-server.naiadsystems.com/live/s:"+model+".json";
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    smStatus="Offline";
                }
                if (response.status == 403){
                    smStatus="Private";
                }
                if (response.status == 200){
                    smStatus="Online - playlist copied.";
                    var result=JSON.parse(response.responseText);
                    var playlist=result.formats["mp4-hls"].manifest;
                    navigator.clipboard.writeText(playlist);
                }
                setSmStatus(smStatus);
            },
            ontimeout: function(){
                setSmStatus("Timeout error");
            }
        });
    }

    function setSmStatus(smStatus){
        if(document.getElementById("smresult")){
            document.getElementById("smresult").innerHTML=smStatus;
        }else{
            document.getElementById("smStatus").innerHTML=" "+smStatus;
        }
        setTimeout(function(){smBusy=false;},1000);
    }

    function bcCheck(model){
        if (bcBusy){return;}
        bcBusy=true;
        setBcStatus("");
        var bcStatus="Online - playlist copied.";
        url="https://bongacams.com/tools/amf.php";
        GM_xmlhttpRequest({
            method: "POST",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            data: "method=getRoomData&args%5B%5D="+model+"&args%5B%5D=false&args%5B%5D=false",
            referrer: "https://bongacams.com/"+model,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                "X-Requested-With": "XMLHttpRequest",
            },
            credentials: "omit",
            onload: function(response) {
                    if (response.status !== 200){
                        setBcStatus("error "+response.status);
                        return;
                    }else{
                        var result=JSON.parse(response.responseText);
                         if (result.status=="error"){
                            setBcStatus("Model not found");
                            return;
                        }
                        var show=result.performerData.showType;
                        if (show!="public"){bcStatus="Private";}
                        if (show=="group"){bcStatus="Groupshow";}
                        if (result.performerData.isAway==true){bcStatus="Away";}
                        if (result.performerData.isOnline==false){bcStatus="Offline";}
                        if (bcStatus=="Online - playlist copied."){
                            var edge=result.localData.videoServerUrl;
                            var playlist="https:"+edge+"/hls/stream_"+result.performerData.displayName+"/playlist.m3u8";
                            navigator.clipboard.writeText(playlist);
                        }
                        setBcStatus(bcStatus);
                    }
            },
            ontimeout: function(){
                setBcStatus("Timeout error");
            }
        });
    }

    function setBcStatus(bcStatus){
        if(document.getElementById("bcresult")){
            document.getElementById("bcresult").innerHTML=bcStatus;
        }else{
            document.getElementById("bcStatus").innerHTML=" "+bcStatus;
        }
        setTimeout(function(){bcBusy=false;},1000);
    }

    function c4Check(model){
        if (c4Busy){return;}
        c4Busy=true;
        setC4Status("");
        url="https://webchat.cam4.com/requestAccess?roomname="+model;
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    setC4Status("error "+response.status);
                    return;
                }
                var result=JSON.parse(response.responseText);
                if (result.status=="roomOffline"){
                    setC4Status("Offline");
                    return;
                }
                if (result.privateStream==true){
                    setC4Status("Private");
                    return;
                }
                getC4Video(model);
            },
            ontimeout: function(){
                setC4Status("Timeout error");
            }
        });
    }

    function setC4Status(c4Status){
        if(document.getElementById("c4result")){
            document.getElementById("c4result").innerHTML=c4Status;
        }else{
            document.getElementById("c4Status").innerHTML=" "+c4Status;
        }
        setTimeout(function(){c4Busy=false;},1000);
    }

    function getC4Video(model){
        url="https://cam4.com/rest/v1.0/profile/"+model+"/streamInfo";
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    setC4Status("error "+response.status);
                    return;
                }
                var result=JSON.parse(response.responseText);
                if (result.canUseCDN==false){
                    setC4Status("Private");
                    return;
                }
                if (!result.cdnURL){
                    setC4Status("Connecting");
                    return;
                }
                var playlist=result.cdnURL;
                navigator.clipboard.writeText(playlist);
                setC4Status("Online - playlist copied.");
            },
            ontimeout: function(){
                setC4Status("Timeout error");
            }
        });
    }

    function mfcCheck(model){
        if (mfcBusy){return;}
        mfcBusy=true;
        setMfcStatus("");
        url="https://api-edge.myfreecams.com/usernameLookup/"+model;
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    setMfcStatus("error "+response.status);
                    return;
                }
                var result=JSON.parse(response.responseText);
                if (result.result.message != "user found"){
                    setMfcStatus("User not found");
                    return;
                }
                if (!result.result.user.sessions[0]){
                    setMfcStatus("Offline");
                    return;
                }
                var status=result.result.user.sessions[0].vstate;
                if (status==0){
                    var modelnr=result.result.user.id;
                    var videoserver=result.result.user.sessions[0].server_name;
                    var phase=result.result.user.sessions[0].phase;
                    getmfcvideo(modelnr,videoserver,phase);
                    return;
                }
                if (status==12){
                    setMfcStatus("Private");
                    return;
                }
                if (status==13){
                    setMfcStatus("Group show");
                    return;
                }
                if (status==14){
                    setMfcStatus("Club show");
                    return;
                }
                if (status==2){
                    setMfcStatus("Not broadcasting");
                    return;
                }
                if (status==90){
                    setMfcStatus("Online - webcam off");
                    return;
                }
                setMfcStatus("Unknown status "+status);
            },
            ontimeout: function(){
                setMfcStatus("Timeout error");
            }
        });
    }

    function setMfcStatus(mfcStatus){
        if(document.getElementById("mfcresult")){
            document.getElementById("mfcresult").innerHTML=mfcStatus;
        }else{
            document.getElementById("mfcStatus").innerHTML=" "+mfcStatus;
        }
        setTimeout(function(){mfcBusy=false;},1000);
    }

    function getmfcvideo(modelnr,videoserver,phase){
        modelnr=modelnr+100000000;
        var servernr=videoserver.split("ideo")[1];
        url="https://edgevideo.myfreecams.com/llhls/NxServer/"+servernr+"/ngrp:mfc_"+phase+modelnr+".f4v_cmaf/playlist.m3u8?nc=0.6190622874050598&v=1.97.23";
        GM_xmlhttpRequest({
            method: "GET",
            timeout: 5000,
            mozAnon: true,
            anonymous: true,
            url: url,
            onload: function(response) {
                if (response.status !== 200){
                    setMfcStatus("Connecting or away");
                    return;
                }
                data=response.responseText;
                var chunk="chunklist"+data.split("chunklist")[1].split("m3u8")[0]+"m3u8";
                var playlist="https://"+videoserver+".myfreecams.com/NxServer/ngrp:mfc_"+phase+modelnr+".f4v_cmaf/"+chunk+"?nc=0.813118007341&v=1.96";
                setMfcStatus("Online - playlist copied.");
                navigator.clipboard.writeText(playlist);
            },
            ontimeout: function(){
                setMfcStatus("Timeout error");
            }
        });
    }

})();