Unlock Nyan model

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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);
        })
    };
})();