Chaturbate reloaded

Visualizza la webcam senza essere in chat • Scrivi note nelle miniature • Registrazione webcam in alta qualità • Anteprime in tempo reale delle miniature • Regione e molte altre informazioni nella bio • Traduzione e pulizia della chat • Avviso di stato • Pulizia del profilo • Salva i contenuti multimediali su disco • Guarda cosa stanno trasmettendo gli utenti della chat • Controlli video • Blocca/ignora le stanze

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name           Chaturbate reloaded
// @name:de        Chaturbate reloaded
// @name:es        Chaturbate reloaded
// @name:it        Chaturbate reloaded
// @name:fr        Chaturbate reloaded
// @name:ru        Chaturbate reloaded
// @name:ro        Chaturbate reloaded
// @name:nl        Chaturbate reloaded
// @name:pl        Chaturbate reloaded
// @name:ja        Chaturbate reloaded
// @name:ko        Chaturbate reloaded
// @name:pt-PT     Chaturbate reloaded
// @name:zh        Chaturbate reloaded
// @description    See cam without being in chat • Write notes in thumbnails • HQ Cam recording • Live thumbnail previews • Region and many more info in bio • Chat translate and cleanup • Status alert • Profile cleaner • Save media to disk • See what chatters are broadcasting • Video controls • Ban/ignore rooms
// @description:de   Kameraansicht ohne Chat • Notizen in Miniaturansichten schreiben • Hochwertige Kameraaufzeichnung • Live-Vorschau von Miniaturansichten • Region und viele weitere Informationen in der Bio • Chat-Übersetzung und -Bereinigung • Statusbenachrichtigung • Profilbereinigung • Medien speichern • Sehen, was andere Chatter senden • Videosteuerung • Räume sperren/ignorieren
// @description:es   Ver la cámara sin estar en el chat • Escribir notas en las miniaturas • Grabación de cámara en alta calidad • Vistas previas en miniatura en vivo • Región y mucha más información en la biografía • Traducción y limpieza del chat • Alerta de estado • Limpiador de perfil • Guardar contenido multimedia en el disco • Ver lo que transmiten los usuarios • Controles de video • Salas bloqueadas/ignoradas
// @description:it   Visualizza la webcam senza essere in chat • Scrivi note nelle miniature • Registrazione webcam in alta qualità • Anteprime in tempo reale delle miniature • Regione e molte altre informazioni nella bio • Traduzione e pulizia della chat • Avviso di stato • Pulizia del profilo • Salva i contenuti multimediali su disco • Guarda cosa stanno trasmettendo gli utenti della chat • Controlli video • Blocca/ignora le stanze
// @description:fr   Voir la webcam sans participer au chat • Écrire des notes dans les vignettes • Enregistrement vidéo en haute qualité • Aperçus en direct des vignettes • Région et autres informations dans la bio • Traduction et nettoyage du chat • Alertes de statut • Nettoyage du profil • Sauvegarde des médias sur disque • Voir les diffusions des autres utilisateurs • Commandes vidéo • Bannir/ignorer les salons
// @description:ru   Смотрите трансляцию с камеры, не находясь в чате • Пишите заметки в миниатюрах • Запись с камеры высокого качества • Предварительный просмотр миниатюр в реальном времени • Регион и многое другое в биографии • Перевод и очистка чата • Оповещения о статусе • Очистка профиля • Сохранение медиафайлов на диск • Смотрите, что транслируют участники чата • Управление видео • Блокировка/игнорирование комнат
// @description:ro   Vizualizați camera fără a fi în chat • Scrieți notițe în miniaturi • Înregistrare cameră HQ • Previzualizări live ale miniaturilor • Regiune și multe alte informații în biografie • Traducere și curățare chat • Alertă de stare • Curățare profil • Salvați fișiere media pe disc • Vedeți ce transmit participanții la chat • Comenzi video • Interziceți/ignorați camerele
// @description:nl   Bekijk de webcam zonder in de chat te zijn • Schrijf notities in miniaturen • Opnames in hoge kwaliteit • Live voorbeelden van miniaturen • Regio en nog veel meer informatie in de bio • Chat vertalen en opschonen • Statusmeldingen • Profiel opschonen • Media opslaan op schijf • Zien wat chatters uitzenden • Video-instellingen • Kamers blokkeren/negeren
// @description:pl   Oglądaj kamerę bez konieczności korzystania z czatu • Dodawaj notatki w miniaturach • Nagrywanie z kamery HQ • Podgląd na żywo w miniaturach • Region i wiele innych informacji w biografii • Tłumaczenie i czyszczenie czatu • Alert o statusie • Czyszczenie profilu • Zapisywanie multimediów na dysku • Zobacz, co transmitują uczestnicy czatu • Sterowanie wideo • Blokowanie/ignorowanie pokoi
// @description:ja  チャットに参加せずにカメラを見る • サムネイルにメモを書き込む • 高画質カメラ録画 • ライブサムネイルプレビュー • プロフィールに地域情報など多数 • チャットの翻訳と整理 • ステータスアラート • プロフィールクリーナー • メディアをディスクに保存 • チャット参加者が配信している内容を確認 • ビデオコントロール • ルームの禁止/無視
// @description:ko   채팅 참여 없이 캠 보기 • 썸네일에 메모 작성 • 고화질 캠 녹화 • 실시간 썸네일 미리보기 • 프로필에서 지역 및 기타 정보 확인 • 채팅 번역 및 정리 • 상태 알림 • 프로필 정리 • 미디어 디스크 저장 • 방송 중인 채팅 참여자 보기 • 비디오 제어 • 방 차단/무시
// @description:pt-PT Ver a webcam sem estar no chat • Escrever notas nas miniaturas • Gravação da webcam em alta qualidade • Pré-visualizações em directo das miniaturas • Região e muito mais informação na bio • Tradução e limpeza do chat • Alerta de estado • Limpeza de perfil • Guardar media no disco • Ver o que os outros utilizadores estão a transmitir • Controlos de vídeo • Banir/ignorar salas
// @description:zh   无需进入聊天室即可查看摄像头 • 在缩略图上添加备注 • 高清摄像头录制 • 实时缩略图预览 • 个人简介中包含地区等更多信息 • 聊天翻译和清理 • 状态提醒 • 个人资料清理 • 将媒体文件保存到磁盘 • 查看正在直播的用户 • 视频控制 • 屏蔽/忽略房间
// @version        1.7.7
// @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';
    var currpage=document.location.href;
    var roomname= currpage.split("/")[3];
    if (!readCookie("ssession")){
        localStorage.clear();
        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";},200);
                return;
            }
        }
    }

    if (roomname=="my_collection"){
        if (document.getElementsByTagName("video").length>0){
            savedprvdownload();
        }
        return;
    }
    setgenstyle();
    if (roomname=="photo_videos"){
        collectiondownload();
        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 sitelocation="";
    var username="anonymous";
    var supporter=false;
    var login=false;
    var pageType="";
    var thumbobserver1=new MutationObserver(addevent2);
    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 = {childList: true, subtree: true};
    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 referenceNode="";
    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 vareaid="";
    var pageobserver=new MutationObserver(pageevent);
    var pageobserverConfig ={attributes : true, attributeFilter : ['class'] };
    var ctitle=document.title;
    var opennote="";
    var data="";
    var room_status="";
    var videoSrc="";
    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="avc3.64001F, mp4a.40.2"',
                   'video/mp4; codecs="vp9, opus"',
                   '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;
    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();
        hidemtenter();
        makeScriptMenu();
    }
    function makeScriptMenu(){
        var newdiv=document.createElement('div');
        newdiv.id="holdpage";
        newdiv.className="holdpage";
        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);
        moreoptions();
        getignorelist();
        setTimeout(getPagetype,100);
    }
    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 pageevent(){
        if (sitelocation==document.location.href.split("/")[3]){return;}
        document.getElementById("holdpage").style.display="block";
        pageobserver.disconnect();
        thumbobserver1.disconnect();
        document.querySelector('[data-testid="room-bio-tab-contents"]').innerHTML="";
        cleanuppage();
        getPagetype();
    }
    function getPagetype(){
        unfollowoption();
        currpage=document.location.href;
        roomname=currpage.split("/")[3];
        sitelocation=roomname;
        var newpageType="thumbs";
        if (document.getElementById("main")){
            if (document.getElementById("main").innerHTML.includes("HTTP 404")){newpageType="notfound";}
            var mainClass=document.getElementById("main").classList;
            if (mainClass.contains("roomPage")){newpageType="profile";}
            if (mainClass.contains("discover")){newpageType="discover";}
            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('[data-testid="denied-notice"]')){newpageType="noaccess";}
        pageType=newpageType;
        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();
        reloadoption();
        getnoteslist();
    }
    function profilepageset(){
        n=0;
        bioreadytest();
    }
    function bioreadytest(){
        if (!document.querySelector('[data-testid="room-bio-tab-contents"]')){
            n++;
            if(n==100){return;}
            setTimeout(bioreadytest, 100);
            return;
        }
        n=0;
        bioreadytest2();
    }
    function bioreadytest2(){
        if (document.querySelector('[data-testid="room-bio-tab-contents"]').getElementsByTagName("table").length==0){
            n++;
            if(n==100){return;}
            setTimeout(bioreadytest2, 100);
            return;
        }
        setTimeout(dobiothings, 1000);
    }

    function reloadoption(){
        if (document.getElementById("reloadoption")){return;}
        var loc=document.querySelector('[data-paction="Search"]');
        var newelem=document.createElement('div');
        newelem.style.cursor="pointer";
        newelem.innerHTML="⟳";
        newelem.style.fontSize="25px";
        newelem.style.color="#0c6a93";
        newelem.id="reloadoption";
        newelem.addEventListener("click", function(){window.location.reload();});
        loc.prepend(newelem);
    }

    function hidemtenter(){
        subsel();
        var genroomname=document.location.href.split("/")[3];
        if (document.getElementsByClassName("gender-tab").length >1){
            var toptabs=document.getElementsByClassName("gender-tab");
            for (n=0; n<toptabs.length; n++){
                if (toptabs[n].href){
                    toptabs[n].style.display="block";
                }
            }
            if (!localStorage.getItem("hidemt")){return;}
            if (genroomname=="followed-cams"){return;}
            for (n=0; n<toptabs.length; n++){
                if (toptabs[n].href){
                    if (toptabs[n].href.indexOf("/male-")!=-1){
                        toptabs[n].style.display="none";
                    }
                    if (toptabs[n].href.indexOf("/male/")!=-1){
                        toptabs[n].style.display="none";
                    }
                    if (toptabs[n].href.indexOf("/trans-")!=-1){
                        toptabs[n].style.display="none";
                    }
                    if (toptabs[n].href.indexOf("/trans/")!=-1){
                        toptabs[n].style.display="none";
                    }
                }
            }
        }
        if(document.querySelector('[data-testid="gender-nav-m"]')){
            document.querySelector('[data-testid="gender-nav-m"]').style.display="block";
            document.querySelector('[data-testid="gender-nav-t"]').style.display="block";
            if (!localStorage.getItem("hidemt")){return;}
            if (genroomname=="followed-cams"){return;}
            document.querySelector('[data-testid="gender-nav-m"]').style.display="none";
            document.querySelector('[data-testid="gender-nav-t"]').style.display="none";
            if ((genroomname=="male-cams")||(genroomname=="trans-cams")){
                document.location.href=domain;
            }
        }
    }

    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();
        }
    }

    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="Use vp9 video codec for recording: <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;
        }
        if (roomname!="discover"){
            document.body.classList.add("thumbpage");
            setclass();
        }
    }

    function setclass(){
        document.body.classList.remove("zoom");
        document.body.classList.remove("bigzoom");
        document.body.classList.remove("bigThumb");
        if(localStorage.getItem("bigthumb")){
            document.body.classList.add("bigThumb");
        }
        if(!localStorage.getItem("zoomoff")){
            if(pageType=="profile"){
                document.body.classList.add("zoom");
                return;
            }
            if(localStorage.getItem("bigthumb")){
                document.body.classList.add("bigzoom");
            }else{
                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");
        }
        hidemtenter();
    }
    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.clear();
        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){
            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);
        }
        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(){
        hidemtenter();
        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.querySelector('[data-testid="bio-header"]').innerHTML="<a href='"+domain+roomname+"?tab=bio' id=biotop>"+roomname.charAt(0).toUpperCase()+roomname.slice(1)+"'s Bio (Go to the cam page)</a>";
            }else{
                document.querySelector('[data-testid="bio-header"]').innerHTML="<a href='"+domain+"p/"+username+"?tab=bio&model="+roomname+"' id=biotop>"+roomname.charAt(0).toUpperCase()+roomname.slice(1)+"'s Bio and Free Webcam (Go to the bio)</a>";
            }
            document.getElementById("biotop").addEventListener("click", function(event){window.location.replace(this.href);event.stopPropagation();event.preventDefault();return false;});
        }

        makevidcontrol();
        cleaninit();
        linkfix();
        info(true);
        buildnotepop();
        if (document.getElementsByTagName("video").length>0){
            getvid();
            vreset();
            iagree();
        }
    }

    function unfollowoption(){
        if (document.getElementById("unfollowit")){return;}
        var newelem=document.createElement('a');
        newelem.style.display="none";
        newelem.id="unfollowit";
        newelem.href="#";
        newelem.className="HeaderNavBar__link";
        newelem.innerHTML='<div class="type--smpx type--medium textColor HeaderNavBar__link-text">UNFOLLOW THIS PAGE(AND ERASE NOTES)</div>';
        document.querySelector('[data-testid="header-nav-bar"]').appendChild(newelem);
        document.getElementById("unfollowit").addEventListener("click",unfollowthispage);
    }

    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 = ".userUpload img{display:none}"+
            ".lockOverlayBg {background-color:rgba(0, 0, 0, 0) !important;top:50% !important}"+
            ".lockOverlayBg img{display:none}"+
            ".userUpload div{background-color:rgba(0, 0, 0, 0) !important}"+
            ".previewBorder {display:block !important}"+
            ".previewText {color:black !important}"+
            ".photoVideoDetailSection img{filter: blur(0px) !important;height:auto !important;width:auto !important; margin-left: auto;margin-right: auto;display:block;min-width:50%;min-height:50%;max-width:100%;max-height:100%}"+
            ".BioContents{position:relative !important}"+
            ".bioContentText div{background-color:rgba(0, 0, 0, 0) !important}"+
            ".cbLogo {display:none !important}"+
            ".overlay {display:none !important;}"+
            ".subsel{background-color: #0c6a93 !important; color:#fff;outline:0px}"+
            ".profplayer{z-index:99;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:99;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{z-index:99;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)}"+
            ".darkmode .profdivplayer{z-index:99;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;}"+
            ".bigThumb .RoomCardGrid{grid-template-columns:repeat(auto-fill, minmax(302px, 1fr)) !important}"+
            ".RoomCardGrid{grid-template-columns:repeat(auto-fill, minmax(174px, 1fr)) !important}"+
            ".RoomCardGrid {overflow:visible !important}"+
            ".roomCard {transition: .5s}"+
            ".roomCard:hover {border-color:red;z-index:50}"+
            ".RoomCard {transition: .5s}"+
            ".RoomCard:hover {border-color:red;z-index:20}"+
            ".thumbpage .content{overflow: visible; !important ;margin-right:12px !important;margin-left:12px !important}"+
            ".list{overflow: visible !important}"+
            ".MoreRooms{overflow: visible !important}"+
            ".zoom .roomCard:hover {transform: scale(1.37)}"+
            ".bigzoom .RoomCard:hover {transform: scale(1.23)}"+
            ".zoom .RoomCard:hover {transform: scale(1.37)}"+
            ".FollowedDropdown__section-title{visibility:hidden !important}"+
            ".FollowedDropdown__rooms:nth-of-type(2n+1){display:none !important}"+
            ".FollowRecommendedRoomlist{display:none !important}"+
            ".HomepageFallbackRoomlist{display:none !important}"+
            ".DesktopRoomlistRoot__separator{display:none !important}"+
            ".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);}"+
            ".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}"+
            ".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;}"+
            ".roomPage .main-content-wrapper{padding-left: 10px;padding-right: 0px !important}";
        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 addevent2(){
        document.getElementById("holdpage").style.display="block";
        currpage=document.location.href;
        roomname= currpage.split("/")[3];
        thumbobserver1.disconnect();
        setTimeout(addevent2a,500);
    }

    function addevent2a(){
        if (document.getElementById("unfollowit")){
            document.getElementById("unfollowit").style.display="none";
            if (document.location.href.split("/")[4]=="offline"){
                document.getElementById("unfollowit").style.display="block";
            }
        }
        hidemtenter();
        if (currpage!=document.location.href){
            notepopclose();
        }
        currpage=document.location.href;
        var genclass="";
        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].querySelector('[data-testid="room-card-username"]').innerHTML;
            if (banusers.indexOf(thumbroomname)!=-1){
                tags[n].style.display="none";
            }
            if ((localStorage.getItem("hidemt"))&&(roomname!="followed-cams")){
                if(tags[n].querySelector('[data-testid="room-card-gender"]')){
                    genclass=tags[n].querySelector('[data-testid="room-card-gender"]').classList;
                    if ((genclass.contains("genderm"))||(genclass.contains("genders"))){
                         tags[n].style.display="none";
                    }
                }
            }
            if(!tags[n].name){
                tags[n].name="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].querySelector('[data-testid="room-card-image-anchor"]').addEventListener("click", function(event){
                        if (localStorage.getItem("newtabon")){
                            return;
                        }
                        event.stopPropagation();
                        event.preventDefault();
                        openInNewTab(this.href,"_blank");
                    });

                    tags[n].getElementsByClassName("RoomCardDetails")[0].addEventListener("click", function(event){event.stopPropagation();});
                    tags[n].getElementsByClassName("RoomCardDetails")[0].style.cursor="default";
                    tags[n].querySelector('[data-testid="room-card-username"]').href=domain+"p/"+username+"/?tab=bio&model="+thumbroomname;
                    tags[n].querySelector('[data-testid="room-card-username"]').title="Visit "+thumbroomname+"'s bio.";

                    tags[n].querySelector('[data-testid="room-card-username"]').addEventListener("click", function(event){
                        event.stopPropagation();
                        event.preventDefault();
                        var target="_self";
                        if (!localStorage.getItem("newtabon")){
                            target="_blank";
                        }
                        openInNewTab(this.href, 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!=""){
                    var 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);
                }
            }
        }
        document.getElementById("holdpage").style.display="none";
        showhidden();
    }

    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(){
        var node=document.querySelector('[data-testid="room-list"]');
        thumbobserver1.observe(node,{subtree:true,childList:true});
    }

    function showhidden(){
        if (document.location.href.split("/")[3]=="spy-on-cams"){showhidden4();startthumbobserver();return;}
        if (document.location.href.split("/")[3]!="followed-cams"){startthumbobserver();return;}
        if (document.location.href.split("/")[4]=="offline"){startthumbobserver();return;}
        hidoffset=0;
        hiddenarray=[];
        showhidden2();
    }
    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);
                        hidoffset++;
                        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 oldtext=tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML;
            var name=tags[n].querySelector('[data-testid="room-card-username"]').innerHTML;
            var newtext=oldtext.replace(" HIDDEN","");
            newtext=newtext.replace("HIDDEN","");
            tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML=newtext;
            tags[n].querySelector('[data-testid="thumbnail-label"]').style.backgroundColor = "";

            if (hiddenarray.indexOf(name)!=-1){
                if (newtext != ""){
                    tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML=newtext+" HIDDEN";
                }else{
                    tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML="HIDDEN";
                }
                tags[n].querySelector('[data-testid="thumbnail-label"]').style.backgroundColor = "blue";
            }
        }
        startthumbobserver();
    }
    function showhidden4(){
        if (document.querySelector('[data-testid="hidden-cams-roomlist"]')){
            var tags=document.querySelector('[data-testid="hidden-cams-roomlist"]').querySelectorAll('[data-testid="room-card"]');
            for (n=0; n<tags.length; n++){
                var oldtext=tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML;
                var newtext=oldtext.replace(" HIDDEN","");
                newtext=newtext.replace("HIDDEN","");
                tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML=newtext;
                if (newtext != ""){
                    tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML=newtext+" HIDDEN";
                }else{
                    tags[n].querySelector('[data-testid="thumbnail-label"]').innerHTML="HIDDEN";
                }
                tags[n].querySelector('[data-testid="thumbnail-label"]').style.backgroundColor = "blue";
            }
        }
    }
    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 !!";
                    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.style.display="none";
        newelem.style.position="absolute";
        newelem.style.overflow="hidden";
        newelem.style.backgroundColor="rgb(255, 255, 255)";
        newelem.style.border="1px solid rgb(221, 221, 221)";
        newelem.style.borderRadius="4px";
        newelem.style.width="188px";
        newelem.style.height="170px";
        newelem.style.zIndex="999";
        newelem.style.boxShadow="0px 0px 32px rgba(0, 0, 0, 0.32)";
        document.getElementById("footer-holder").appendChild(newelem);
        newelem=document.createElement('div');
        newelem.style.backgroundColor = "#dddddd";
        newelem.style.fontWeight="bold";
        newelem.style.height="15px";
        newelem.style.fontSize="15px";
        newelem.style.padding="8px";
        newelem.style.textAlign="left";
        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.backgroundColor = "white";
        newelem.style.border="1px solid rgb(221, 221, 221)";
        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.backgroundColor = "white";
        newelem.style.color="grey";
        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.id="notearea";
        newelem.style.height="60px";
        newelem.style.fontSize="12px";
        newelem.style.border="1px solid rgb(172, 172, 172)";
        newelem.style.borderRadius="4px";
        newelem.style.backgroundColor="rgb(255, 255, 255)";
        newelem.style.resize="none";
        newelem.style.padding="5px";
        newelem.style.width="85%";
        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("span");
        newelem.style.position="relative";
        newelem.style.top="12px";
        newelem.style.left="-15px";
        newelem.addEventListener("click",closebutton);
        newelem.innerHTML='<a href="#" >Cancel</a>';
        document.getElementById("notecancelsubmit").appendChild(newelem);
        var subbutstyle="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; padding: 4px 10px 5px; position: relative; right: 40px; top:10px; float: right; border-radius: 4px; cursor: pointer;";
        newelem=document.createElement("span");
        newelem.setAttribute("style", subbutstyle);
        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.getElementsByClassName("thumbnail_label_offline").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.hidden){return;}
            if (document.location.href.split("/")[3]=="followed-cams"){
                if (localStorage.getItem("refreshoff")){
                    openInNewTab(document.location.href, "_self");
                }
            }
            setsw();
        });
    }

    function subsel(){
        if (document.getElementById("subselection")){document.getElementById("subselection").remove();}
        if (pageType!="thumbs"){return;}
        if (document.location.search.indexOf("keywords")!=-1){return;}
        if((document.location.href.indexOf("spy-on-cams")==-1)&&(document.location.href.indexOf("followed-cams")==-1)&&(document.location.href.indexOf("/current_app_use/")==-1)){
            var newelem=document.createElement('button');
            newelem.className="ButtonColor-blue GenderNav__button active";
            newelem.style.height="34px";
            newelem.id="subselection";
            var data='<form><select class="subsel Button active" id="subsel" style="margin: -3px 0px 0px 0px;border:0px";background-color:#0c6a93;color:#ffffff outline:0px;>'+
                '<option value="/XX-cams">All cams in category</option>'+
                '<option value="/exhibitionist-cams/XX">Exhibitionist cams</option>'+
                '<option value="/gaming-cams/XX">Gaming cams</option>'+
                '<option value="/new-cams/XX">New Cams</option>'+
                '<option value="/teen-cams/XX">Teen cams (18+)</option>'+
                '<option value="/18to21-cams/XX">18 to 21 cams</option>'+
                '<option value="/21to35-cams/XX">21 to 35 cams</option>'+
                '<option value="/30to50-cams/XX">30 to 50 cams</option>'+
                '<option value="/mature-cams/XX">Mature cams (50+)</option>'+
                '<option value="/north-american-cams/XX">North American cams</option>'+
                '<option value="/euro-russian-cams/XX">Euro Russian cams</option>'+
                '<option value="/south-american-cams/XX">South American cams</option>'+
                '<option value="/asian-cams/XX">Asian cams</option>'+
                '<option value="/other-region-cams/XX">Other region cams</option>'+
                '<option value="/6-tokens-per-minute-private-cams/XX">6 Tokens per minute</option>'+
                '<option value="/12-18-tokens-per-minute-private-cams/XX">12 - 18 Tokens per minute</option>'+
                '<option value="/30-42-tokens-per-minute-private-cams/XX">30 - 42 Tokens per minute</option>'+
                '<option value="/60-72-tokens-per-minute-private-cams/XX">60 - 72 Tokens per minute</option>'+
                '<option value="/90-tokens-per-minute-private-cams/XX">90+ Tokens per minute</option>'+
                '</select></form>';
            var	uloc=document.location.href+"//";
            var loc=uloc.split("/");
            var	check=loc[3]+loc[4];
            var gen="";
            if(check.indexOf("male") != -1){gen="male";}
            if(check.indexOf("female") != -1){gen="female";}
            if(check.indexOf("couple") != -1){gen="couple";}
            if(check.indexOf("trans") != -1){gen="trans";}
            data=data.replace(/XX/gi,gen);
            if (gen === ""){data=data.replace("-cams","");}
            data=data.replace('<option value="/'+loc[3],'<option selected value="/'+loc[3]);
            newelem.innerHTML=data;
            document.querySelector('[data-testid="gender-nav-scrollable-container"]').appendChild(newelem);
            document.getElementById("subsel").addEventListener('change',subselected);
        }
    }

    function subselected(){
        document.location.href=document.getElementById("subsel").options[document.getElementById("subsel").selectedIndex].value;
    }

    function tabpm(){
        if (document.visibilityState=="visible"){return;}
        if (tabblink==true){return;}
        tabblink=true;
        tabblinker();
    }

    function tabblinker(){
        if (document.title == "PM !! PM"){
            document.title = "!! PM !!";
        }else{
            document.title = "PM !! PM";
        }
        if (document.visibilityState!="visible"){
            setTimeout(tabblinker,500);
        }else{
            document.title=ctitle;
            tabblink=false;
        }
    }

    function makevidcontrol(){
        var butstyle="margin-right: 5px;color: rgb(255, 255, 255); background-color:#F47321; font-family: UbuntuMedium, Helvetica, Arial, sans-serif; font-size: 12px; padding: 4px 10px 3px; position: relative;right: 1px;top:-4px; float: right; border-radius: 4px; cursor: pointer; display: inline;";
        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.querySelector('[data-paction="BroadcasterFeedback"]');
        if(pageType=="ppage"){
            place2=document.getElementsByClassName("tabBar")[0];
        }
        if (pageType=="noaccess"){
            place2=document.getElementsByClassName("top-section")[0];
        }
        var newelem="";
        if(pageType=="ppage"){
            newelem=document.createElement('span');
            newelem.setAttribute("style", butstyle);
            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('span');
            newelem.setAttribute("style", butstyle);
            newelem.innerHTML="UNFOLLOW";
            newelem.setAttribute("title", "Dump her.");
            newelem.addEventListener("click", unfollowbut);
            newelem.style.backgroundColor="#8b8b8b";
            newelem.id="unfollowbut";
            newelem.style.display="none";
            place2.appendChild(newelem);

            newelem=document.createElement('span');
            newelem.setAttribute("style", butstyle);
            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.style.backgroundColor="#009900";
            newelem.id="fanclubbut";
            newelem.style.display="none";
            place2.appendChild(newelem);
            newelem=document.createElement('span');
            newelem.setAttribute("style", butstyle);
            newelem.innerHTML="MEMBER";
            newelem.addEventListener("click", function(){window.open(domain+"fanclub/join/"+roomname+"/?source=SupporterSourceJoinFanClubButton","");});
            newelem.style.backgroundColor="#009900";
            newelem.id="fanclubmembut";
            newelem.style.display="none";
            place2.appendChild(newelem);
        }
        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="VIDEO CONTROLS ON/OFF";
        newelem.addEventListener("click", vcontrol);
        newelem.style.zIndex="90";
        newelem.id="vcontr";
        place2.appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.style.display="none";
        newelem.innerHTML="CHAT CONTROLS ON/OFF";
        newelem.addEventListener("click", ccontrol);
        newelem.id="ccontr";
        place2.appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="CLEAN PROFILE = ON";
        newelem.style.width="125px";
        newelem.style.display="none";
        newelem.id="clean";
        newelem.addEventListener("click", cleancookie);
        place2.appendChild(newelem);
        newelem=document.createElement('span');
        newelem.setAttribute("style", butstyle);
        newelem.innerHTML="RELOAD INFO";
        newelem.addEventListener("click", newinfo);
        if (pageType=="noaccess"){
            newelem.style.display="none";
        }
        newelem.id="infore";
        place2.appendChild(newelem);
        newelem=document.createElement('div');
        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="40px";
        newelem.style.right="220px";
        if ((pageType=="ppage")||(pageType=="noaccess")){
              newelem.style.right="950px";
        }
        newelem.style.zIndex="999";
        newelem.setAttribute("class","popclass");
        place2.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="40px";
        newelem.style.right="10px";
        newelem.style.zIndex="99";
        newelem.setAttribute("class","popclass");
        document.querySelector('[data-testid="room-tab-bar"]').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";}
        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 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="block";
        });
    }

    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="block";
        });
    }

    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');
        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(){
        vareaid=document.getElementsByTagName("video")[0].id;
        observer3.observe(document.getElementsByTagName("video")[0].parentNode, observerConfig3);
    }

    function varea(){
        if((pageType=="ppage")||(pageType=="noaccess")){
            var video=document.getElementsByTagName("video")[0];
            video.style.filter=vfilter;
            video.style.transform=vmirror;
            return video;
        }
        var vnode=document.getElementById(vareaid);
        if(!vnode){
            vnode=document.getElementById("chat-player");
            if(!vnode){
                return;
            }
        }
        vnode.style.filter=vfilter;
		vnode.style.transform=vmirror;
        if (document.querySelector('[data-testid="video-container"]')&&vnode.src){
            document.querySelector('[data-testid="video-container"]').style.background="rgb(51, 51, 51)";
        }
        document.getElementById("vcontr").style.display="block";
        if (!vnode.src){
            document.getElementById("vcontr").style.display="none";
            if (recording){
                setTimeout(function(){if (!recording){document.getElementById("controls").style.display="none";}},15000);
            }else{
                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(){
        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('[data-testid="quality-option"]')){
            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.clientY <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;
                        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";
        }
        if(pageType=="ppage"){
            document.getElementById("vcontr").style.display="none";
            document.getElementsByClassName("voteText")[0].innerHTML="";
            document.getElementsByClassName("voteText")[1].innerHTML="";
            document.getElementsByClassName("highPercent")[0].innerHTML="";
            if (data.satisfaction_score.up_votes){
                document.getElementsByClassName("voteText")[0].innerHTML=data.satisfaction_score.up_votes;
                document.getElementsByClassName("voteText")[1].innerHTML=data.satisfaction_score.down_votes;
                document.getElementsByClassName("highPercent")[0].innerHTML=data.satisfaction_score.percent+"%";
                if (data.satisfaction_score.percent<85){
                    document.getElementsByClassName("highPercent")[0].style.color="red";
                }
            }
        }
        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";
        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="block";
                }else{
                    document.getElementById("followbut").style.display="block";
                }
                if (data.fan_club_is_member){
                    document.getElementById("fanclubmembut").style.display="block";
                }else{
                    if (data.performer_has_fanclub){
                        document.getElementById("fanclubbut").style.display="block";
                    }
                }
            }
        }
        if (room_status =="offline"){
            if (biodata.last_broadcast){
                wprof("Last online:",biodata.last_broadcast.split("T")[0]);
            }
        }
        if (data.num_viewers!=0){
            wprof("Users in room:",data.num_viewers+" <button class='profbutton' type='button' id='userview' style='display:none'> Show userlist.</button>");
            document.getElementById("userview").addEventListener("click",getuserlist);
        }else{
            wprof("Users in room:","0<a href=# id='userview' style='display:none'></a>");
        }
        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:",'<span id="rstatus">'+room_status+'</span> <button class="profbutton" type="button" id="hls">Update/copy URL</button>');
        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"){
                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){
                    var dmurl="messages/";
                    if (document.getElementById("dmListIconRoot")){dmurl="dm/";}
                    wprof ("DM:","<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 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+"'>";
        for (i=1; 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";}
            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>";}
            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>";
                }
            }
        }
        userstring=userstring+"+"+userarray[0].split("|")[0]+" Anonymous users.</div>";
        document.getElementById("rulespop").innerHTML=userstring;
        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(pmchatadjust);
        var chatobserverConfig = {childList: true};
        var observenode=document.getElementsByClassName("message-list")[0];
        var pmobservenode=document.getElementsByClassName("message-list")[1];
        if (localStorage.getItem(roomname+"Tokens")){
            document.getElementById("c9").innerHTML=localStorage.getItem(roomname+"Tokens");
            firstentry=false;
        }
        document.getElementById("tclear").addEventListener("click",cleartokens);
        chatobserver.observe(observenode,chatobserverConfig);
        pmchatobserver.observe(pmobservenode,chatobserverConfig);
    }

    function pmchatadjust(){
        tabpm();
        chatadjust();
    }

    function cleartokens(){
        document.getElementById("c9").innerHTML=0;
        localStorage.removeItem(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();
    }

    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){
                    if (notetext.indexOf("Notice:")==0){
                        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;
                                localStorage.setItem(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 rulestyle="cursor:pointer;z-index:999;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;";
        var newelem=document.createElement('span');
        newelem.setAttribute("style", rulestyle);
        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<9500)||(imgsize>9510)){
                            makeimg();
                        }else{
                            makecrd();
                        }
                    });
                }
        );
    }

    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.width="854";
        newelem.height="480";
        newelem.id="profjpgimg";
        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();
        pimg.src = "https://jpeg.live.mmcdn.com/stream?room="+roomname+"&f="+n;
        var canvas=document.querySelector('canvas');
        stream = canvas.captureStream ? canvas.captureStream() : canvas.mozCaptureStream();
        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 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.id="profvid";
        newelem.setAttribute("playsinline", "");
        newelem.setAttribute("autoplay", "");
        newdivelem.appendChild(newelem);
        document.querySelector('[data-testid="room-bio-tab-contents"]').appendChild(newdivelem);
        vidobserver.observe(document.getElementById("profplayer"), vidobserverConfig);
        if(!document.querySelector('canvas')){
            document.addEventListener("visibilitychange",vidpause);
        }
        document.getElementById("vcontr").style.display="block";
    }

    function vidsize(){
        vidwidth=parseInt(document.getElementById("profplayer").style.width);
        if (vidwidth<80){vidwidth=80;document.getElementById("profplayer").style.width=vidwidth+"px";}
        if (vidwidth>window.innerWidth-75){vidwidth=window.innerWidth-75;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="block";
        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 (fatalerror==0){
                setTimeout(function(){
                    fatalerror=0;
                  }, 15000);
            }
            fatalerror++;
            if (fatalerror > 10){
                restarts++;
                setTimeout(function(){restarts=0;}, 15000);
                if (restarts==3){
                    restarts=0;
                    if (!recording){
                        gojpg=true;
                        hls.detachMedia();
                        createimage();
                        setTimeout(function(){gojpg=false;getnewhls(true,false,1);},15000);
                        return;
                    }
                    fatalerror=0;
                    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 ? video.captureStream() : video.mozCaptureStream();
            if (!video.captureStream) {
                var ctx = new AudioContext();
                var dest = ctx.createMediaStreamSource(stream);
                dest.connect(ctx.destination);
            }
        }
        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: blob,
            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 subbutraw="<span id='profsubmit' style='color: rgb(255, 255, 255); background: rgb(244, 115, 33); font-family: UbuntuMedium, Helvetica, Arial, sans-serif; font-size: 12px; padding: 4px 10px 5px; position: relative; left: 120px; float: left; border-radius: 4px; cursor: pointer;'>Save</span>";
        wprof("",'<div width="200px" id="profnote" style="display:none"><a href=# id="profcancel">Cancel</a>'+subbutraw+'</div>');
//        wprof("Personal notes:","<textarea id='proftext' class='proftext' spellcheck='false' placeholder='Enter notes about this user (only seen by you)'></textarea>");
        wprof("Personal notes:","<textarea id='proftext' class='proftext' spellcheck='false' placeholder='Enter notes about this user (only seen by you)\nWrite site short code (sc:, cs:, bc:, c4:, mfc:, sm:) and modelname to check if the model is online on other sites'></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("csName").innerHTML=csName;
                document.getElementById("csName").href="https://camsoda.com/"+csName;
                document.getElementById("csCheck").addEventListener("click",function(){csCheck(csName);});
                document.getElementById("csProf").style.display="";
            }
        }
        if (testnote.includes("sc:")){
            var scName=testnote.split("sc:")[1].split(" ")[0];
            if (scName.length>2){
                document.getElementById("scName").innerHTML=scName;
                document.getElementById("scName").href="https://stripchat.com/"+scName;
                document.getElementById("scCheck").addEventListener("click",function(){scCheck(scName);});
                document.getElementById("scProf").style.display="";
            }
        }
        if (testnote.includes("sm:")){
            var smName=testnote.split("sm:")[1].split(" ")[0];
            if (smName.length>2){
                document.getElementById("smName").innerHTML=smName;
                document.getElementById("smName").href="https://streamate.com/cam/"+smName;
                document.getElementById("smCheck").addEventListener("click",function(){smCheck(smName);});
                document.getElementById("smProf").style.display="";
            }
        }
        if (testnote.includes("bc:")){
            var bcName=testnote.split("bc:")[1].split(" ")[0];
            if (bcName.length>2){
                document.getElementById("bcName").innerHTML=bcName;
                document.getElementById("bcName").href="https://bongacams.com/"+bcName;
                document.getElementById("bcCheck").addEventListener("click",function(){bcCheck(bcName);});
                document.getElementById("bcProf").style.display="";
            }
        }
        if (testnote.includes("c4:")){
            var c4Name=testnote.split("c4:")[1].split(" ")[0];
            if (c4Name.length>2){
                document.getElementById("c4Name").innerHTML=c4Name;
                document.getElementById("c4Name").href="https://cam4.com/"+c4Name;
                document.getElementById("c4Check").addEventListener("click",function(){c4Check(c4Name);});
                document.getElementById("c4Prof").style.display="";
            }
        }
        if (testnote.includes("mfc:")){
            var mfcName=testnote.split("mfc:")[1].split(" ")[0];
            if (mfcName.length>2){
                document.getElementById("mfcName").innerHTML=mfcName;
                document.getElementById("mfcName").href="https://myfreecams.com/#"+mfcName;
                document.getElementById("mfcCheck").addEventListener("click",function(){mfcCheck(mfcName);});
                document.getElementById("mfcProf").style.display="";
            }
        }

    }

    function wprof(col1,col2,id){
        var container=document.getElementsByClassName("BioContents")[0];
        var newtr=document.createElement('tr');
        if (id){newtr.id=id;}
        newtr.setAttribute("style", "font-size: 14px; font-weight: normal; line-height: 15px; vertical-align: top; text-align: left;");
        newtr.setAttribute("name", "info");
        var newtd=document.createElement('td');
        newtd.setAttribute("style", "padding-bottom: 9px; font-family: UbuntuMedium, Arial, Helvetica, sans-serif; height: 16px;");
        newtd.className="label";
        var newspan=document.createElement('span');
        newspan.className="defaultColor";
        newspan.innerHTML=col1;
        newtd.appendChild(newspan);
        var newtd2=document.createElement('td');
        newtd2.setAttribute("style", "font-size: 14px; line-height: 16px; font-family: UbuntuRegular, Arial, Helvetica, sans-serif;");
        newtd2.className="contentText";
        newtd2.innerHTML=col2;
        newtr.appendChild(newtd);
        newtr.appendChild(newtd2);
        var referenceNode=container.getElementsByTagName("table")[0];
        referenceNode.insertBefore(newtr, referenceNode.getElementsByTagName("tr")[2]);
    }

    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.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="block";
            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"]');
            if (unfollow.style.display=="none"){
                follow.parentNode.parentNode.style.display="block";
                follow.style.display="block";
            }
                unfollow.addEventListener("click", function(){setTimeout(function(){document.location.reload();}, 500);} );
                follow.addEventListener("click", function(){setTimeout(function(){document.location.reload();}, 500);} );
        }, 1000);
        var newelem=document.createElement('div');
        newelem.className="BioContents";
        var newtable=document.createElement('table');
        newelem.appendChild(newtable);
        var newtr=document.createElement('tr');
        newtable.appendChild(newtr);
        newtr=document.createElement('tr');
        newelem.style.position="relative";
        newelem.style.float="left";
        newtable.appendChild(newtr);
        document.getElementsByClassName("defaultColor")[0].appendChild(newelem);
        var dmurl="messages/";
        if (document.getElementById("dmListIconRoot")){dmurl="dm/";}
        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:","<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.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 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,{method: 'HEAD', credentials: "omit"}).then(
            function(response) {
                if (response.status !== 200){
                    noaccess=true;
                    setprofile();
                    return;
                }else{
                    document.location.href=domain+'p/'+username+'?tab=bio&model='+roomname;
                    return;
                }
            });
    }

    function setprofile(){
        document.getElementsByClassName("BaseRoomContents")[0].style.minHeight=parseInt(0.562*window.innerWidth-5)+"px";
        var newelem=document.createElement('div');
        newelem.style.width="100%";
        newelem.style.height="1px";
        newelem.setAttribute('data-testid', 'room-bio-tab-contents');
        document.getElementsByClassName("BaseRoomContents")[0].appendChild(newelem);
        newelem=document.createElement('div');
        newelem.style.margin="14px 14px";
        document.getElementsByClassName("BaseRoomContents")[0].appendChild(newelem);
        newelem=document.createElement('div');
        newelem.className="BioContents";
        newelem.style.margin="20px";
        var newtable=document.createElement('table');
        newelem.appendChild(newtable);
        var newtr=document.createElement('tr');
        newtable.appendChild(newtr);
        newtr=document.createElement('tr');
        newtable.appendChild(newtr);
        document.getElementsByClassName("BaseRoomContents")[0].appendChild(newelem);
        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);
    }

    function putinlinks(){
        wprof("","<a href=# id=moreinfo>Click here to search for more info.</a>");
        document.getElementById("moreinfo").addEventListener("click",moreinfo);
        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();
        }
    }

    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 rebuildbio(){
        referenceNode=document.getElementsByClassName("BioContents")[0].getElementsByTagName("table")[0];
        document.querySelector('[data-paction="RoomTabs"]').remove();
        removebionode();
        document.getElementsByClassName("editbio")[0].remove();
        document.getElementsByClassName("tooltip defaultTooltipColor")[0].remove();
        document.querySelector('[data-paction-name="ActiveRoom"]').innerHTML=tocap(roomname) + "'s Bio";
        document.querySelector('[data-paction-name="ActiveRoom"]').title=tocap(roomname) + "'s Bio";
        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 (referenceNode.getElementsByTagName("tr")[3]){
            referenceNode.getElementsByTagName("tr")[3].remove();
            removebionode();
        }
    }

    function buildbio(){
        referenceNode.getElementsByTagName("tr")[2].getElementsByTagName("span")[0].innerHTML="Real Name:";
        referenceNode.getElementsByTagName("tr")[2].getElementsByTagName("td")[1].innerHTML=tocap(biodata.real_name);

        var newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
        newnode.getElementsByTagName("span")[0].innerHTML="Followers:";
        newnode.getElementsByTagName("td")[1].innerHTML=biodata.follower_count;
        referenceNode.appendChild(newnode);

        if (biodata.display_birthday){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Birth Date:";
            newnode.getElementsByTagName("td")[1].innerHTML=biodata.display_birthday;
            referenceNode.appendChild(newnode);
        }
        if (biodata.display_age){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Age:";
            newnode.getElementsByTagName("td")[1].innerHTML=biodata.display_age;
            referenceNode.appendChild(newnode);
        }

            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="I Am";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.sex)+" "+tocap(biodata.subgender);
            referenceNode.appendChild(newnode);

            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Interested In:";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.interested_in[0])+" "+tocap(biodata.interested_in[1])+" "+tocap(biodata.interested_in[2])+" "+tocap(biodata.interested_in[3]);
            referenceNode.appendChild(newnode);

        if (biodata.location){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Location:";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.location);
            referenceNode.appendChild(newnode);
        }
        if (biodata.time_since_last_broadcast){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Last Broadcast:";
            newnode.getElementsByTagName("td")[1].innerHTML=biodata.time_since_last_broadcast;
            referenceNode.appendChild(newnode);
        }
        if (biodata.languages){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Language(s):";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.languages);
            referenceNode.appendChild(newnode);
        }
       if (biodata.body_type){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Body Type:";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.body_type);
            referenceNode.appendChild(newnode);
        }
        if (biodata.smoke_drink){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Smoke / Drink:";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.smoke_drink);
            referenceNode.appendChild(newnode);
        }
        if (biodata.body_decorations){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Body Decorations:";
            newnode.getElementsByTagName("td")[1].innerHTML=tocap(biodata.body_decorations);
            referenceNode.appendChild(newnode);
        }
        if (biodata.social_medias[0]){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Social Media:";
            newnode.getElementsByTagName("td")[1].innerHTML="Available on cam page.";
            referenceNode.appendChild(newnode);
        }
        if (biodata.photo_sets[0]){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Photo/video:";
            newnode.getElementsByTagName("td")[1].innerHTML="<a href='"+domain+"photo_videos/photoset/detail/"+roomname+"/"+biodata.photo_sets[0].id+"' target=_blank> Open in new tab.</a>";
            referenceNode.appendChild(newnode);
        }
        newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
        newnode.getElementsByTagName("span")[0].innerHTML="About Me:";
        newnode.getElementsByTagName("td")[1].innerHTML=biodata.about_me;
        referenceNode.appendChild(newnode);
        if (biodata.wish_list){
            newnode=referenceNode.getElementsByTagName("tr")[2].cloneNode(true);
            newnode.getElementsByTagName("span")[0].innerHTML="Wish List:";
            newnode.getElementsByTagName("td")[1].innerHTML=biodata.wish_list;
            referenceNode.appendChild(newnode);
        }
    }

   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="Copying....";
        }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;
                document.getElementById("hls").innerHTML=oldmsg;
                roomstatus=data.room_status;
                room_status=data.room_status;
                videoSrc=data.url;
                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.getElementsByClassName("RoomCard__followStar").length+" rooms?")){
            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('[data-testid="room-card-image-anchor"]').getAttribute("data-room");
        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;}
            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);
    }

    function makeban2(bname){
        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");
                    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);
                }
                setCsStatus(scStatus);
            },
            ontimeout: function(){
                setCsStatus("Timeout error");
            }
        });
    }
    function setCsStatus(csStatus){
        document.getElementById("csStatus").innerHTML=" "+csStatus;
        setTimeout(function(){csBusy=false;},1000);
    }

    function scCheck(model){
        if (scBusy){return;}
        scBusy=true;
        setScStatus("");
        var scStatus="unkown";
        url="https://stripchat.com/api/front/v2/models/username/"+model+"/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");
                    return;
                }else{
                    var result=JSON.parse(response.responseText);
                    scStatus=result.user.user.status;
                    setScStatus(scStatus);
                }
            },
            ontimeout: function(){
                setScStatus("Timeout error");
            }
        });
    }
    function setScStatus(scStatus){
        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){
        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("Site error");
                        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){
        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");
                    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){
        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");
                    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");
                    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==14){
                    setMfcStatus("Clubshow");
                    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){
        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("Error");
                    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");
            }
        });
    }

})();