Unlock Nyan model

Can make CAI+ "Nyan" model the default ai model for chats

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Unlock Nyan model
// @namespace    https://github.com/irsat000/cai-unlock-nyan
// @version      2025-03-02
// @description  Can make CAI+ "Nyan" model the default ai model for chats
// @author       İrşat Akdeniz
// @match        https://character.ai/chat/*
// @icon         https://character.ai/favicon.ico
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    function getAccessToken() {
        const meta = document.querySelector('meta[cai_token]');
        const tokenFromMeta = meta?.getAttribute('cai_token');
        if (tokenFromMeta) return tokenFromMeta;
        else null;
    }

    GM_registerMenuCommand('Make Nyan default', makeNyanDefault);

    function makeNyanDefault () {
        const AccessToken = getAccessToken();
        if (!AccessToken) {
            alert("Token not found, you need CAI Tools for resources.");
            return;
        }
        fetch("https://plus.character.ai/chat/user/update_settings/", {
            "headers": {
                "accept": "application/json, text/plain, */*",
                "authorization": AccessToken,
                "content-type": "application/json",
            },
            "body": JSON.stringify({
                "modelPreferenceSettings": {
                    "defaultModelType": "MODEL_TYPE_SMART"
                }
            }),
            "method": "POST",
        }).then(res => {
            if (res.ok) {
                alert("SUCCESS! Nyan model is set to default. Refresh the page!");
            } else {
                throw new Error("Request rejected with code: " + res.statusCode)
            }
        }).catch((error) => {
            alert("Couldn't set to Nyan: " + error.message);
        })
    };
})();