Legacy >>>> New

Enter old cai even if it was "closed" "Zedd - Find you"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Legacy >>>> New
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Enter old cai even if it was "closed" "Zedd - Find you"
// @match        https://old.character.ai/*
// @match        https://beta.character.ai/*
// @grant        none
// @icon         https://www.google.com/s2/favicons?sz=64&domain=plus.character.ai
// @namespace https://greasyfork.org/users/1077492
// @run-at      document-start
// ==/UserScript==

(function() {
    var tmer = null;

    async function fetchAndModify(url) {
        try {
            const response = await fetch(url);
            var scriptText = await response.text();

            var killswitch = "window.location.href=e.toString()";
            scriptText = scriptText.replaceAll(killswitch, "");
            const blob = new Blob([scriptText], { type: 'application/javascript' });
            const blobUrl = URL.createObjectURL(blob);

            const newScript = document.createElement('script');
            newScript.src = blobUrl;
            newScript.addEventListener("load", onLoad);
            document.head.appendChild(newScript);
        } catch (error) {
            alert('Error while modifying the page. Retry again or already patched');
        }
    }

    function onLoad() {

        var times = 0;
        var deleted = false;
        var tmer = setInterval(function() {
            var modals = document.querySelectorAll(".modal, .modal-backdrop");

            if (deleted) {
                clearInterval(tmer);
            }

            modals.forEach((modal) => {
                deleted = true;
                modal.parentNode.removeChild(modal);
            });
        }, 2000);
    }

    async function getWholePage(url) {
        try {
            const response = await fetch(url);
            if (!response.ok) {
                throw new Error('response not ok');
            }

            const htmlText = await response.text();

            const parser = new DOMParser();
            const doc = parser.parseFromString(htmlText, 'text/html');

            const headElements = doc.head.children;
            const headElementsArray = Array.from(headElements);
            headElementsArray.forEach(element => {
                if (element.tagName === 'SCRIPT' && element.src.indexOf("js/main") != -1) {
                    fetchAndModify(element.src);
                    return;
                }
                document.head.appendChild(element);
            });

            return headElementsArray;
        } catch (error) {
            alert('Error loading the page. Retry again or already patched');
        }
    }

    function start() {
        document.head.innerHTML = ""; //Stop everything.
        getWholePage('https://plus.character.ai/chat/4');
    }
    start();
})();