// ==UserScript== // @name Rizz Your Waifu // @version 1.3.6 // @author kevoting // @description Views deleted messages and auto swipes // @match https://beta.character.ai/* // @icon https://www.google.com/s2/favicons?sz=64&domain=character.ai // @grant none // @run-at document-start // @namespace https://greasyfork.org/users/1077492 // @downloadURL none // ==/UserScript== (function() { const STREAMING_URL = "https://beta.character.ai/chat/streaming/"; const CANCEL_URL = "https://beta.character.ai/chat/history/msgs/cancel/"; const NEO_TURNS_URL = /https:\/\/neo\.character\.ai\/turns\/.*/g; const SENTRY_URL = "sentry.io"; const E_VERSION = "1.3.6"; const fetchFn = window.fetch; const sendSocketfn = window.WebSocket.prototype.send; const PROTOCOL_LEGACY = "LEGACY"; const PROTOCOL_NEO = "NEO"; var current_protocol = PROTOCOL_LEGACY; var readyqueue = []; var last_user_msg_uuid = null; var last_params = null; var mainelem = null; var lastheaders = null; var lastbody = null; var override_primary = null; var ishided = false; var allow_generating = true; var activerequests = 0; var req_version = 0; var okmessages = 0; var templates = { "msg": null }; var warned = false; /*Chat2 support*/ var neo_socket = null; var neo_waiting_for_turn = false; var neo_waiting_for_delete = false; var neo_payload_origin = ""; var neo_capture_next_request = false; var neo_captured_next_request = ""; var neo_readyqueue = []; var neo_requests = new Map(); var neo_last_request_id = ""; var neo_last_turn = null; var neo_swiper = null; //https://gist.github.com/scwood/3bff42cc005cc20ab7ec98f0d8e1d59d function uuidV4() { const uuid = new Array(36); for (let i = 0; i < 36; i++) { uuid[i] = Math.floor(Math.random() * 16); } uuid[14] = 4; // set bits 12-15 of time-high-and-version to 0100 uuid[19] = uuid[19] &= ~(1 << 2); // set bit 6 of clock-seq-and-reserved to zero uuid[19] = uuid[19] |= (1 << 3); // set bit 7 of clock-seq-and-reserved to one uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; return uuid.map((x) => x.toString(16)).join(''); } function findElement(elemData, innerHtmlData) { var allElements = document.querySelectorAll(elemData); for (var i = 0; i < allElements.length; i++) { if (allElements[i].innerHTML.indexOf(innerHtmlData) != -1) { return allElements[i]; } } return undefined; } window.WebSocket.prototype.send = function(...args) { if (this.url == "wss://neo.character.ai/ws/") { if (neo_socket == null || (neo_socket != null && neo_socket != this)) { if (neo_socket != null) { neo_socket.removeEventListener("message", neoSocketMessage); neo_socket.removeEventListener("close", neoSocketDeadLikeMeIn5Years); } neo_socket = this; neo_socket.addEventListener("message", neoSocketMessage); neo_socket.addEventListener("close", neoSocketDeadLikeMeIn5Years); } } try { var json = JSON.parse(args[0]); switch (json.command) { case "create_and_generate_turn": { if (!neo_waiting_for_turn) { neo_payload_origin = json.origin_id; neo_waiting_for_turn = true; let newver = ++req_version; req_version = newver; neo_last_request_id = json.request_id; } current_protocol = PROTOCOL_NEO; setStatus(true, true); break; } case "generate_turn_candidate": { if (neo_capture_next_request) { neo_capture_next_request = false; neo_last_request_id = json.request_id; neo_captured_next_request = json.request_id; return; } break; } } } catch (ex) { alert("RIP"); console.error(ex); } sendSocketfn.call(this, ...args); } function neoSocketMessage(e) { var json = JSON.parse(e.data); if (json.hasOwnProperty("command")) { switch (json.command) { case "add_turn": { if (json.hasOwnProperty("turn") && (!json.turn.author.hasOwnProperty("is_human") || !json.turn.author.is_human)) { if (neo_waiting_for_turn) { neo_waiting_for_turn = false; activerequests = 0; okmessages = 1; neo_requests = new Map(); neo_last_turn = json.turn; neo_swiper = neoSwiperController(); var msgbox = mainelem.querySelector(".details"); msgbox.innerHTML = ""; setAllowGenerating(true); } } break; } case "update_turn": { let request = neo_requests.get(json.request_id); if (request !== undefined) { request.bubble.websocketEvent(json.command, json); } else { console.log("no request id", json.request_id); } break; } case "neo_error": { let request = neo_requests.get(json.request_id); if (request !== undefined) { request.bubble.neoError(json); } break; } case "remove_turns_response": { if (neo_waiting_for_delete) { neo_waiting_for_delete = false; try { setTimeout(function() { document.querySelector('[class="btn py-0"][type="button"]').click(); }, 100); } catch (ex) { console.log("no send button"); } } break; } } } } function neoSocketDeadLikeMeIn5Years(e) { neo_socket = null; neo_requests.values().forEach(function(request) { request.bubble.informDisconnect(e.code); }); } function neoSwiperController() { var version = req_version + 0; var state = 0; var data = null; setStatus(true, false); return new Promise((resolve, reject) => { var tmer = null; function check() { if (req_version != version) { resolve(true); return; } if (!neo_capture_next_request) { if (activerequests < 2 && allow_generating) { createNeoSwipe(); } switch (state) { case 0: { if (neo_readyqueue.length > 0) { data = neo_readyqueue.shift(); state = 1; } break; } case 1: { state = 0; data.request_id = neo_captured_next_request; neo_socket.dispatchEvent(new MessageEvent("message", { bubbles: true, cancelable: false, data: JSON.stringify(data) })); break; } } } tmer = setTimeout(check, 100); } tmer = setTimeout(check, 100); }); } function createNeoSwipe() { if (neo_last_turn == null) { return; } var payload = { "command": "generate_turn_candidate", "request_id": uuidV4(), "payload": { "character_id": neo_last_turn.author.author_id, "turn_key": neo_last_turn.turn_key, }, "origin_id": neo_payload_origin }; var bubble = new bubbleDOMController(0); var msgbox = mainelem.querySelector(".details"); msgbox.appendChild(bubble.dom); neo_requests.set(payload.request_id, { "payload": payload.payload, "bubble": bubble }); neo_socket.send(JSON.stringify(payload)); activerequests++; } function createNeoSwipeEdit(bubble, newRaw) { if (neo_last_turn == null) { return; } var payload = { "command": "edit_turn_candidate", "request_id": uuidV4(), "payload": { "new_candidate_raw_content": newRaw, "turn_key": neo_last_turn.turn_key, }, "origin_id": neo_payload_origin }; neo_requests.set(payload.request_id, { "payload": payload.payload, "bubble": bubble }); neo_socket.send(JSON.stringify(payload)); } function removeTurns(turns) { var payload = { "command": "remove_turns", "request_id": neo_last_request_id, "payload": { "chat_id": neo_last_turn.turn_key.chat_id, "turn_ids": turns }, "origin_id": neo_payload_origin }; neo_socket.send(JSON.stringify(payload)); neo_waiting_for_delete = true; } async function handlefetch(...args) { if (args[0] == STREAMING_URL && (mainelem != null)) { current_protocol = PROTOCOL_LEGACY; var json = JSON.parse(args[1].body); var isClean = false; var mode = getCurrentMode(); lastheaders = args[1].headers; lastbody = json; if (json.hasOwnProperty("parent_msg_uuid")) { if (json.parent_msg_uuid == null) { isClean = true; } else { if (json.parent_msg_uuid == last_user_msg_uuid) { if (mode == "nsfw") { if (!warned) { warned = true; alert("Please note that if you swipe then submit the answer, it will become the chosen answer and if you choose the old one again it won't work. You should not use swipes like this with this extension."); } } else { if (activerequests == 0) { //requestSwipes(args[1], req_version); //Not needed because the stop button } } return constructAwaiter(); } } if (mode == "nsfw") { //Nothing to do in normal mode if (json.primary_msg_uuid == null) { if (override_primary != null) { json.primary_msg_uuid = override_primary; args[1].body = JSON.stringify(json); override_primary = null; } } } } else { //Weird CAI bug, happens when swipe alert("Dev fuck up, extension dead?"); return constructAwaiter(); } if (isClean) { var firstrequest = tryGetNewMessage(args[1], 0, mode); setStatus(true, true); setAllowGenerating(true); return constructAwaiter(); } } else { if (args[0].indexOf(SENTRY_URL) != -1) { return new Promise((resolve, reject) => { reject(); }); } } let response = fetchFn(...args); return response; } var f = async (...args) => { return handlefetch(...args); } class EventEmitter { on(name, callback) { var callbacks = this[name]; if (!callbacks) this[name] = [callback]; else callbacks.push(callback); } dispatch(name, event) { var callbacks = this[name]; if (callbacks) callbacks.forEach(callback => callback(event)); } } class bubbleDOMController { constructor(attempt = 0) { this.dom = templates.msg.cloneNode(true); this.botname = this.dom.querySelector(".botname"); this.botmsg = this.dom.querySelector(".botmsg"); this.rawmsg = this.dom.querySelector(".rawmsg"); this.reqstatus = this.dom.querySelector(".reqstatus"); this.replyid = this.dom.querySelector(".replyid"); this.streamcontroller = null; this.errored = false; this.sendedtoui = false; this.stopped = false; this.isediting = false; this.status = 0; this.lastchunk = null; this.lastdata = null; let btns = this.dom.querySelector(".topbtns").getElementsByClassName("abtn"); for (let i = 0; i < btns.length; i++) { btns[i].addEventListener("click", this.onBtnClick.bind(this)); } btns = this.dom.querySelector(".bottombtns").getElementsByClassName("abtn"); for (let i = 0; i < btns.length; i++) { btns[i].addEventListener("click", this.onBtnClick.bind(this)); } this.botname.innerText = ""; this.botmsg.innerText = ""; this.botmsg.style.display = "none"; this.rawmsg.innerText = ""; this.reqstatus.innerText = (attempt > 0) ? ("Got error, retry... x" + attempt) : "Waiting for the server..."; this.dom.querySelector("textarea").addEventListener("input", this.grow.bind(this)); this.updateBtnStatusses(); this.grow(); } assignController(controller) { var self = this; this.streamcontroller = controller; controller.events.on("chunk", function(chunk) { if (self.dom == null) { return; } if (chunk.hasOwnProperty("src_char")) { if (self.status == 0) { self.status = 1; } self.lastchunk = chunk; self.botname.innerText = chunk.src_char.participant.name; self.botmsg.innerText = chunk.replies[0].text; self.rawmsg.innerText = chunk.replies[0].text; self.updateBtnStatusses(); self.grow(); } }); controller.events.on("result", function(status) { if (self.dom == null) { return; } switch (status.status) { case "errored": { self.status = 2; self.errored = true; self.reqstatus.innerText = status.error; break; } case "done": { if (!self.errored) { self.status = 3; self.reqstatus.innerText = "OK"; self.replyid.innerText = "#" + okmessages; } break; } } self.updateBtnStatusses(); }); } websocketEvent(eventType, data) { var self = this; switch (eventType) { case "update_turn": { if (data.hasOwnProperty("turn")) { if (self.status == 0) { self.status = 1; } self.lastdata = data; self.botname.innerText = data.turn.author.name; var finished = false; if (self.isediting) { let result = data.turn.candidates.filter((candidate) => candidate.candidate_id == data.turn.primary_candidate_id); if (result.length != 0) { self.status = 3; self.reqstatus.innerText = "Edited"; this.dom.classList.remove("warned"); self.updateBtnStatusses(); self.grow(); data.turn.candidates = result; self.lastdata = data; } else { this.dom.classList.remove("warned"); this.dom.classList.add("errored"); self.reqstatus.innerText = "Script error: Failed"; self.errored = true; self.status = 2; } return; } if (data.turn.candidates[0].hasOwnProperty("safety_truncated")) { self.status = 3; self.reqstatus.innerText = "Filtered"; this.dom.classList.add("warned"); } if (data.turn.candidates[0].hasOwnProperty("raw_content")) { self.botmsg.value = data.turn.candidates[0].raw_content; self.rawmsg.innerText = data.turn.candidates[0].raw_content; } else { this.dom.classList.remove("warned"); this.dom.classList.add("errored"); self.errored = true; self.status = 2; } if (data.turn.candidates[0].hasOwnProperty("is_final")) { if (self.status == 1) { self.status = 3; self.reqstatus.innerText = "OK"; } finished = true; okmessages++; this.replyid.innerText = "#" + okmessages; } if (finished) { activerequests = Math.max(0, activerequests - 1); } self.updateBtnStatusses(); self.grow(); } break; } } } grow() { var elem = this.dom.querySelector("textarea"); elem.style.height = "5px"; elem.style.height = (elem.scrollHeight) + "px"; } informHTTPError(code) { this.dom.classList.add("errored"); this.reqstatus.innerText = "HTTP " + code; } informDisconnect(code) { if (this.status == 1 || this.status == 0) { this.dom.classList.add("errored"); this.reqstatus.innerText = "Error: Ended by disconnect: " + code; this.status = 2; this.errored = true; activerequests = Math.max(0, activerequests - 1); } } neoError(neoErrorData) { if (this.status == 1 || this.status == 0) { this.dom.classList.add("errored"); this.reqstatus.innerText = "Error from server: (" + neoErrorData.error_code + ") " + neoErrorData.comment; this.status = 2; this.errored = true; activerequests = Math.max(0, activerequests - 1); if (neoErrorData.error_code == 403) { setAllowGenerating(false); this.reqstatus.innerText = "Denied by server - Possible swipe limit reached"; mainelem.querySelector("[data-tag=deleteresend]").style.display = "block"; } if (neoErrorData.error_code == 429) { setAllowGenerating(false); mainelem.querySelector("[data-tag=deleteresend]").style.display = "block"; } } } updateBtnStatusses() { let btns = this.dom.querySelector(".topbtns").getElementsByClassName("abtn"); for (var i = 0; i < btns.length; i++) { btns[i].style.display = "none"; } this.dom.querySelector(".bottombtns").style.display = "none"; switch (this.status) { case 1: { //this.dom.querySelector("[data-tag=stopgen]").style.display = "block"; break; } case 2: { this.dom.classList.add("errored"); this.dom.querySelector("[data-tag=remove]").style.display = "block"; break; } case 3: { this.rawmsg.style.display = "block"; this.botmsg.style.display = "none"; if (!this.sendedtoui) { this.dom.querySelector("[data-tag=sendui]").style.display = "block"; if (!this.isediting && current_protocol == PROTOCOL_NEO) { this.dom.querySelector("[data-tag=editcan]").style.display = "block"; } } break; } case 4: { if (this.stopped) { let btn = this.dom.querySelector("[data-tag=stopgen]"); btn.style.display = "block"; btn.innerText = "Stopped"; } break; } case 5: { if (!this.sendedtoui) { this.dom.querySelector(".bottombtns").style.display = "flex"; } break; } case 6: { if (!this.sendedtoui) { this.isediting = true; this.dom.querySelector(".bottombtns").style.display = "flex"; let btn = this.dom.querySelector("[data-tag=editsave]"); btn.innerText = "Saving..."; btn = this.dom.querySelector("[data-tag=editcancel]"); btn.style.display = "none"; this.rawmsg.innerText = this.botmsg.value; createNeoSwipeEdit(this, this.botmsg.value); } break; } } } selfDestroy() { if (this.dom != null) { this.dom.parentNode.removeChild(this.dom); this.dom = null; } } onBtnClick(e) { var self = this; e.stopImmediatePropagation(); if (neo_waiting_for_turn) { alert("You need to wait m8"); return; } switch (e.target.getAttribute("data-tag")) { case "remove": { self.selfDestroy(); break; } case "sendui": { if (!self.sendedtoui) { self.sendedtoui = true; if (current_protocol == PROTOCOL_LEGACY) { override_primary = self.lastchunk.replies[0].uuid; readyqueue.push(self.streamcontroller.stream); } else { neo_capture_next_request = true; neo_readyqueue.push(self.lastdata); } swipeNext(); } break; } case "stopgen": { //Never finished if (!self.stopped) { cancelMessage(lastbody.history_external_id, self.lastchunk.replies[0].uuid, self.lastchunk.replies[0].text.length).then(function() { self.status = 4; }); self.stopped = true; } break; } case "editcan": { self.status = 5; self.rawmsg.style.display = "none"; self.botmsg.style.display = "flex"; self.dom.querySelector("textarea").removeAttribute("readonly"); self.grow(); break; } case "editcancel": { self.status = 3; self.dom.querySelector("textarea").setAttribute("readonly", ""); self.botmsg.value = self.lastdata.turn.candidates[0].raw_content; self.grow(); break; } case "editsave": { self.isediting = true; self.status = 6; self.dom.querySelector("textarea").setAttribute("readonly", ""); self.grow(); break; } } self.updateBtnStatusses(); } } function tryGetNewMessage(args, attempt, mode) { var bubble = new bubbleDOMController(attempt); var msgbox = mainelem.querySelector(".details"); msgbox.innerHTML = ""; msgbox.appendChild(bubble.dom); if (attempt == 0) { last_user_msg_uuid = null; } else { var json = JSON.parse(args.body); json.retry_last_user_msg_uuid = last_user_msg_uuid; args.body = JSON.stringify(json); } var req = createAndCancel(args, mode == "nsfw"); let newver = ++req_version; req_version = newver; readyqueue = []; okmessages = 0; req.then(function(result) { bubble.selfDestroy(); if (mode == "sfw") { result.req.then(function(response) { readyqueue.push(response.body); }); } else { setStatus(false, false); setAllowGenerating(true); } var chunk = result.chunk; var modified = JSON.parse(JSON.stringify(args)); if (!(chunk.last_user_msg_uuid == null) && !(chunk.last_user_msg_uuid == "")) { last_user_msg_uuid = chunk.last_user_msg_uuid; } var modifiedjson = JSON.parse(modified.body); modifiedjson.parent_msg_uuid = chunk.last_user_msg_uuid; modified.body = JSON.stringify(modifiedjson); requestSwipes(modified, newver); }); req.catch(function(chunk) { bubble.selfDestroy(); if (typeof(chunk) == "object" && chunk.hasOwnProperty("last_user_msg_uuid")) { last_user_msg_uuid = chunk.last_user_msg_uuid; setTimeout(function() { tryGetNewMessage(args, attempt + 1, mode); }, Math.min(2000, 5 + (attempt * 10))); } else { alert("Unexpected fatal error. Please reload the page"); } }); return req; } function requestSwipes(body, version) { last_params = body; for (var i = 0; i < 5; i++) { setTimeout(function() { createAndRegister(body, version); }, 1000 + (i * 50)); } } function swipeNext() { document.querySelector(".swiper-button-next").click(); //may cause errors in future } function constructAwaiter() { return new Promise((resolve, reject) => { var tmer = null; function check() { if (readyqueue.length > 0) { clearInterval(tmer); let res = new Response(readyqueue.shift(), { "status": 200 }); setStatus(false, false); resolve(res); } } tmer = setInterval(check, 100); }); } function setStatus(disableMode, disableControl) { try { if (disableMode) { mainelem.querySelector("#cmode").classList.add("modechanger_disabled"); } else { mainelem.querySelector("#cmode").classList.remove("modechanger_disabled"); } if (disableControl) { mainelem.querySelector("#ccontrol").classList.add("modechanger_disabled"); } else { mainelem.querySelector("#ccontrol").classList.remove("modechanger_disabled"); } } catch (ex) {} } function constructStreamController(response) { let reader = response.body.getReader(); let emitter = new EventEmitter(); var lastchunk = null; var chunkcount = 0; let stream = new ReadableStream({ start(controller) { function pump() { reader.read().then(({ done, value }) => { if (done) { controller.close(); if (chunkcount == 0) { emitter.dispatch("result", { "status": "errored", "error": "Empty response" }); } else { emitter.dispatch("result", { "status": "done" }); } return; } let text = new TextDecoder().decode(value); if (chunkcount == 0 && ((text.length == 0) || (text.charCodeAt(0) == 60))) //< { controller.close(); emitter.dispatch("result", { "status": "errored", "error": "Unexpected response" }); return; } let clean = text.split(String.fromCharCode(10)); let chunks = []; for (var i = 0; i < clean.length; i++) { try { chunks.push(JSON.parse(clean[i])); chunkcount++; } catch (ex) {} } if (chunks.length != 0) { let chunk = chunks[chunks.length - 1]; if (last_user_msg_uuid != null) { chunk.last_user_msg_uuid = last_user_msg_uuid; } if (chunk.hasOwnProperty("abort")) { emitter.dispatch("result", { "status": "errored", "error": chunk.error, "last_user_msg_uuid": chunk.last_user_msg_uuid }); if (lastchunk != null) { lastchunk.is_final_chunk = true; value = new TextEncoder().encode(JSON.stringify(lastchunk) + String.fromCharCode(13, 10)); emitter.dispatch("chunk", lastchunk); } } else { lastchunk = chunk; value = new TextEncoder().encode(JSON.stringify(lastchunk) + String.fromCharCode(13, 10)); emitter.dispatch("chunk", chunk); if (chunk.is_final_chunk) { emitter.dispatch("result", { "status": "done" }); } } } controller.enqueue(value); pump(); }) } pump(); } }); return { "stream": stream, "events": emitter }; } function cancelMessage(history, uuid, letters) { let newopts = {}; newopts.method = "POST"; newopts.headers = lastheaders; newopts.body = JSON.stringify({ "history_id": history, "msg_uuid": uuid, "num_letters": letters }); var req = fetchFn(CANCEL_URL, newopts); return req; } function createAndRegister(params, version) { if (version == req_version) { if (activerequests >= 2 || !allow_generating) { return; } let max = 100; if (okmessages >= max) { return; } activerequests++; var req = createAndBuild(params); req.then(function(chunk) { activerequests = Math.max(0, activerequests - 1); okmessages++; createAndRegister(params, version); }); req.catch(function(err) { activerequests = Math.max(0, activerequests - 1); if (err.status != 429) { createAndRegister(params, version); } }); } } function createAndBuild(params) { return new Promise((resolve, reject) => { var req = fetchFn(STREAMING_URL, params); var lastchunk = null; var bubble = new bubbleDOMController(); mainelem.querySelector(".details").appendChild(bubble.dom); req.then(function(res) { if (res.ok) { let controller = constructStreamController(res); bubble.assignController(controller); controller.events.on("chunk", function(chunk) { lastchunk = chunk; if (chunk.is_final_chunk) { resolve(chunk); } }); controller.events.on("result", function(result) { switch (result.status) { case "errored": { reject({ "status": 200, "error": new Error(result.error) }); break; } case "done": { resolve(lastchunk); } } }); } else { bubble.informHTTPError(res.status); reject({ "status": res.status, "error": null }); } }); req.catch(function(error) { reject({ "status": 0, "error": error }); }); }); } function createAndCancel(params, sendcancel) { return new Promise((resolve, reject) => { var req = fetchFn(STREAMING_URL, params); var lastchunk = null; var sendedcancel = !sendcancel; req.then(function(res) { let controller = constructStreamController(res.clone()); controller.events.on("chunk", function(chunk) { lastchunk = chunk; if (chunk.is_final_chunk) { resolve({ "chunk": chunk, "req": req }); } else { if (!sendedcancel) { cancelMessage(lastbody.history_external_id, chunk.replies[0].uuid, 1).catch(function(e) { reject(new Error("Failed to cancel")); }).then(function() { sendedcancel = true }); } } }); controller.events.on("result", function(result) { switch (result.status) { case "errored": { reject(result); break; } case "done": { resolve({ "chunk": lastchunk, "req": req }); } } }); }); req.catch(function(error) { reject(error); }); }); } function getCurrentMode() { var value = mainelem.querySelector('input[name="drone"]:checked').value; return value; } function switchVisibility() { ishided = !ishided; var width = mainelem.clientWidth; if (!ishided) { mainelem.querySelector(".ptrk_hide").removeAttribute("hided"); mainelem.style.transform = ""; } else { mainelem.querySelector(".ptrk_hide").setAttribute("hided", ""); mainelem.style.transform = "translateX(" + width + "px)"; } } function onFunctionButton(e) { switch (e.target.getAttribute("data-tag")) { case "stop_gen": { setAllowGenerating(false); break; } case "resume_gen": { setAllowGenerating(true); if (last_params != null && current_protocol == PROTOCOL_LEGACY) { requestSwipes(last_params, req_version); } break; } case "deleteresend": { setAllowGenerating(false); setStatus(true, true); removeTurns([neo_last_turn.turn_key.turn_id]); break; } } } function setAllowGenerating(allow) { if (allow) { mainelem.querySelector("[data-tag=resume_gen]").style.display = "none"; mainelem.querySelector("[data-tag=stop_gen]").style.display = "block"; mainelem.querySelector("[data-tag=deleteresend]").style.display = "none"; allow_generating = true; } else { mainelem.querySelector("[data-tag=deleteresend]").style.display = "none"; mainelem.querySelector("[data-tag=stop_gen]").style.display = "none"; mainelem.querySelector("[data-tag=resume_gen]").style.display = "block"; allow_generating = false; } } f.prototype = fetchFn.prototype; window.fetch = f; var timer = null; window.addEventListener("load", function() { timer = setTimeout(function() { try { var style = document.createElement('style'); style.innerHTML = ` .ptrk_main {position: fixed; margin: 0; z-index: 9999; background-color: rgba(33, 37, 41, 0.85); right: 0px; top: 0px; height: 100%; padding: 18px; color: white; font-size: 13px; transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28); user-select: none; width: 470px; box-sizing: border-box; font-family: 'Noto Sans'; } .ptrk_main a {color: #1491f3; } .ptrk_hide {width: 30px; height: 150px; left: -30px; top: 50%; border-bottom-left-radius: 5px; border-top-left-radius: 5px; position: absolute; cursor: pointer; background-color: rgba(33, 37, 41, 0.85); transition: transform 1s ease; } .ptrk_hide[hided]:after {transform: rotate(135deg); } .ptrk_hide:after {content: ''; width: 12px; height: 12px; top: 47%; left: 25%; position: absolute; transform: rotate(-45deg); border-right: 2px solid #5f6365; border-bottom: 2px solid #5f6365; } .ptrk_main .modechanger_disabled {opacity: 0.3; pointer-events: none; cursor: no-allowed; } .ptrk_main legend, fieldset {float: initial; line-height: initial; font-size: initial; margin-bottom: initial; padding: initial; width: initial; background: initial; border: initial; border-color: initial; background-color: initial; font-size: 12px; padding-inline-start: 5px; padding-inline-end: 5px; } .ptrk_main label {background: initial; background-color: initial; font-size: 12px; } .ptrk_main fieldset {display: flex; justify-content: center; margin-bottom: 10px; border: 1px solid rgb(59 59 63) !important; border-radius: 3px; font-size: 12px; } .ptrk_main textarea {display: block; width: 100%; color: white; padding: 10px; margin-bottom: 3px; margin-top: 3px; box-sizing: border-box; font-family: inherit; font-size: 12px; background: unset; overflow: hidden; border: 1px solid #8e8e8e !important; } .ptrk_main textarea[readonly] {padding:0;border: 1px solid rgba(255,255,255,0) !important; } .ptrk_main .details {display: relative; overflow-y: scroll; width: 100%; } .ptrk_main .details p {margin: 0; margin-top: 0.5em; font-size: 12px; user-select: text; } .ptrk_main .errored {background: #4f3432 !important; } .ptrk_main .warned {background: #48402e !important; } .ptrk_main .details .mbubble {padding: 10px; border-radius: 3px; margin: 6px; background: rgb(56 59 63); cursor: pointer; position: relative; } .ptrk_main .details .topbtns {position: absolute; width: 100%; right: 10px; display: flex; justify-content: flex-end; height: 30px; } .ptrk_main .bottombtns {width: 100%; height: 30px; right: 10px; display: flex; justify-content: flex-end; } .ptrk_main .midbtns {width: 100%; height: 30px; right: 10px; display: flex; justify-content: center; } .ptrk_main .abtn {cursor: pointer; padding: 6px; border-radius: 3px; font-weight: bold; z-index: 2; margin: 2px; background: rgb(95 99 101); } .ptrk_main .abtn:active {background: rgb(118 123 125); } .ptrk_main input[type=radio] {position: absolute; opacity: 0; width: 0; height: 0; } .ptrk_main input[type=radio]+label {filter: grayscale(1.0); background: rgb(56 59 63); border-radius: 2px; padding: 5px; cursor: pointer; display: flex; margin: 3px; min-width: 56px; font-size: 12px; align-items: center; justify-content: center; flex-direction: column; } .ptrk_main input[type=radio]:checked+label {filter: none; background: rgb(77 81 84); !important; } .ptrk_main small {font-size: 12px; } .ptrk_icon {height: 23px; position: absolute; z-index: 9999; background-color: #212529; font-family: 'Arial'; left: 20px; padding: 6px; top: 20px; border-radius: 5px; color: white; opacity: 0.5; transition: all 0.2s; } .ptrk_icon:hover {opacity: 1.0; cursor: pointer } @media (max-width:500px) {.ptrk_main {width: 80%; } } `; document.body.appendChild(style); var maindom = document.createElement('div'); maindom.classList.add("ptrk_main"); maindom.innerHTML = `
Mode
Responses
Edit
Go
Send to UI
Remove
Stop gen
%botname

%STATUS
Cancel
Save
Resume generating
0.9.0
Updates `; mainelem = maindom; var msgtemplate = maindom.querySelector(".ptrk_main .details .mbubble"); templates.msg = msgtemplate.cloneNode(true); msgtemplate.parentNode.removeChild(msgtemplate); let btns = mainelem.querySelectorAll("#ccontrol .abtn"); for (let i = 0; i < btns.length; i++) { btns[i].addEventListener("click", onFunctionButton); } mainelem.querySelector(".ptrk_hide").addEventListener("click", switchVisibility); mainelem.querySelector("#eversion").innerText = E_VERSION; document.body.appendChild(maindom); setStatus(false, true); } catch (ex) {} }, 1); }); })();