Greasy Fork

ChatGPT 头像更改器

让你的ChatGPT的头像和名称变成自己想象的!

// ==UserScript==
// @name         ChatGPT 头像更改器
// @version      0.0.2
// @description  让你的ChatGPT的头像和名称变成自己想象的!
// @author       小阿狼是也
// @license           MIT
// @match             *://chat.openai.com/chat/*
// @match             *://chat.openai.com/chat/
// @icon         data:image/svg+xml,<svg width="96" height="96" viewBox="0 0 96 96" fill="none" style="color:rgba(255,139,255,1);fill:rgba(25,55,24,1)" xmlns="http://www.w3.org/2000/svg"> <rect width="96" height="96"/><path d="M78.8303 41.4616C79.637 39.0379 79.9168 36.4697 79.651 33.9291C79.3852 31.3885 78.5798 28.9339 77.2888 26.7296C75.3745 23.3959 72.4506 20.7564 68.9389 19.1921C65.4273 17.6277 61.5095 17.2193 57.7507 18.0258C56.0552 16.1152 53.9712 14.5888 51.6382 13.5487C49.3051 12.5086 46.7768 11.9788 44.2224 11.9948C40.3794 11.9857 36.6328 13.1972 33.5226 15.4546C30.4125 17.7119 28.0995 20.8985 26.917 24.5551C24.4136 25.0679 22.0486 26.1094 19.9801 27.61C17.9117 29.1105 16.1876 31.0355 14.923 33.2561C12.9938 36.5809 12.1704 40.4326 12.5717 44.2556C12.973 48.0787 14.5782 51.6755 17.1558 54.5272C16.3487 56.9509 16.0686 59.519 16.3342 62.0596C16.5998 64.6003 17.405 67.0549 18.6958 69.2592C20.6102 72.593 23.5341 75.2325 27.0457 76.7968C30.5573 78.3612 34.4752 78.7695 38.2339 77.963C39.9291 79.874 42.0131 81.4007 44.3462 82.4408C46.6793 83.4809 49.2078 84.0105 51.7623 83.9941C55.6081 84.0053 59.358 82.794 62.4706 80.5351C65.5832 78.2762 67.8974 75.0865 69.079 71.4267C71.5826 70.9144 73.9478 69.8731 76.0163 68.3725C78.0849 66.8719 79.8089 64.9467 81.073 62.7257C82.9995 59.4007 83.8204 55.5498 83.4173 51.7282C83.0143 47.9065 81.4081 44.3116 78.8303 41.4616ZM51.9099 79.2873C48.3273 79.2873 45.5538 78.1873 43.1309 76.1646C43.2402 76.105 43.4318 76 43.5567 75.9233L57.8927 67.6425C58.2527 67.438 58.5517 67.1412 58.7587 66.7827C58.9658 66.4242 59.0735 66.0169 59.0708 65.6029V45.392L65.1316 48.8908C65.1633 48.9068 65.1905 48.9303 65.211 48.9593C65.2316 48.9882 65.2447 49.0217 65.2494 49.0569V65.7902C65.248 73.3826 58.9274 79.2873 51.9099 79.2873ZM22.778 66.9059C21.197 64.1743 20.6272 60.9736 21.1684 57.8643C21.2749 57.9281 21.4608 58.0417 21.5942 58.1183L35.9302 66.3991C36.2874 66.6082 36.6938 66.7184 37.1076 66.7184C37.5215 66.7184 37.9279 66.6082 38.285 66.3991L55.7877 56.293V63.2906C55.7898 63.3264 55.783 63.3621 55.7679 63.3946C55.7528 63.427 55.7298 63.4552 55.7011 63.4766L41.209 71.844C38.1091 73.6293 34.4277 74.112 30.9724 73.1862C27.517 72.2604 24.5701 70.0018 22.778 66.9059ZM19.001 35.6094C20.5754 32.8745 23.0615 30.7803 26.0242 29.6933C26.0242 29.8168 26.0242 30.0354 26.0242 30.1873V46.7489C26.0212 47.1626 26.1287 47.5696 26.3356 47.9279C26.5424 48.2862 26.8411 48.5828 27.2009 48.7872L44.7021 58.8919L38.6427 62.3907C38.6127 62.4103 38.5784 62.4222 38.5428 62.4254C38.5072 62.4287 38.4713 62.4231 38.4383 62.4092L23.9448 54.0347C20.8494 52.2436 18.5907 49.2981 17.6639 45.8441C16.7371 42.39 17.218 38.7094 19.001 35.6094ZM68.7909 47.196L51.2882 37.0899L57.3476 33.5925C57.3776 33.5729 57.4119 33.561 57.4475 33.5577C57.4832 33.5545 57.519 33.5601 57.552 33.574L72.0455 41.9442C74.2647 43.2275 76.0724 45.1162 77.2572 47.3894C78.4421 49.6626 78.955 52.2263 78.7359 54.7804C78.5169 57.3344 77.575 59.7733 76.0204 61.8116C74.4658 63.8498 72.3628 65.4032 69.9576 66.2898V49.2329C69.961 48.8204 69.8548 48.4145 69.6498 48.0566C69.4448 47.6987 69.1483 47.4017 68.7909 47.196ZM74.8219 38.1118C74.7154 38.0465 74.5295 37.9344 74.3961 37.8578L60.0601 29.577C59.7027 29.3685 59.2964 29.2586 58.8827 29.2586C58.469 29.2586 58.0627 29.3685 57.7053 29.577L40.2026 39.6831V32.6855C40.2006 32.6497 40.2075 32.6141 40.2226 32.5816C40.2377 32.5492 40.2606 32.521 40.2892 32.4995L54.7813 24.1392C57.0015 22.859 59.5404 22.2375 62.1008 22.3474C64.6613 22.4574 67.1375 23.2941 69.2398 24.7599C71.3421 26.2257 72.9836 28.2598 73.9721 30.6243C74.9606 32.9888 75.2554 35.5859 74.8219 38.1118ZM36.9082 50.5898L30.8473 47.091C30.8152 47.0756 30.7876 47.0522 30.767 47.0232C30.7464 46.9941 30.7335 46.9603 30.7295 46.9249V30.1873C30.7312 27.6237 31.463 25.1137 32.8394 22.951C34.2158 20.7882 36.1797 19.0623 38.5014 17.9752C40.823 16.8881 43.4063 16.4848 45.9488 16.8125C48.4914 17.1402 50.8879 18.1854 52.858 19.8256C52.7487 19.8853 52.5585 19.9903 52.4322 20.0669L38.0962 28.3478C37.7367 28.5525 37.4381 28.8491 37.2311 29.2073C37.0241 29.5655 36.9161 29.9723 36.9181 30.386L36.9082 50.5898ZM40.1998 43.4928L47.9952 38.9904L55.7905 43.49V52.4918L47.9952 56.9899L40.1998 52.4904V43.4928Z" fill="currentColor"/></svg>
// @require           https://unpkg.com/[email protected]/dist/sweetalert2.min.js
// @resource          swalStyle https://unpkg.com/[email protected]/dist/sweetalert2.min.css
// @grant             unsafeWindow
// @grant             GM_registerMenuCommand
// @namespace https://greasyfork.org/users/756710
// ==/UserScript==

(function () {
    var ChatPGT_StyleModed = localStorage.getItem('ChatPGT_StyleMode');
    const customClass = {
        container: 'panai-container',
        popup: 'panai-popup',
        header: 'panai-header',
        title: 'panai-title',
        closeButton: 'panai-close',
        icon: 'panai-icon',
        image: 'panai-image',
        content: 'panai-content',
        htmlContainer: 'panai-html',
        input: 'panai-input',
        inputLabel: 'panai-inputLabel',
        validationMessage: 'panai-validation',
        actions: 'panai-actions',
        confirmButton: 'panai-confirm',
        denyButton: 'panai-deny',
        cancelButton: 'panai-cancel',
        loader: 'panai-loader',
        footer: 'panai-footer'
    };
    var ChatPGT_StyleMode = JSON.parse(ChatPGT_StyleModed)
    if(ChatPGT_StyleModed==null){
        const config = {
            user:false,
            user_name:"小阿狼是也",
            user_avatar:"https://q.qlogo.cn/g?b=qq&nk=2893265066&s=640",
            chat:false,
            chat_name:"酪蛋白AI",
            chat_avatar:"https://apic.douyucdn.cn/upload/avatar_v3/201908/f2b54d0e48b649fd821574e5a72a09c0_big.jpg",
        }
        var confied = JSON.stringify(config)
        localStorage.setItem('ChatPGT_StyleMode', confied);
    }
    window.onload = function () {
        //实时替换
        if(ChatPGT_StyleMode.user ===true ||ChatPGT_StyleMode.chat ===true){
            setInterval(() => {
                var mainlength = document.querySelectorAll('[data-testid*="conversation-turn"]').length
                for (let i = 0; i < mainlength; i+=2) {
                    if(ChatPGT_StyleMode.user === true){
                        //更改【用户】的头像
                        var You_main_img = document.querySelectorAll('[data-testid*="conversation-turn"] .rounded-sm')[i]
                        You_main_img.src = ChatPGT_StyleMode.user_avatar;

                        //更改【用户】的名字
                        var You_main_text = document.querySelectorAll('[data-testid*="conversation-turn"] .font-semibold.select-none')[i]
                        You_main_text.innerText = ChatPGT_StyleMode.user_name
                    }
                    if(ChatPGT_StyleMode.chat === true){
                        //更改【ChatGPT】的头像
                        var main_img = document.querySelectorAll('[data-testid*="conversation-turn"] .gizmo-shadow-stroke')[i+1]
                        main_img.innerHTML = `<img alt="User" loading="lazy" width="24" height="24" decoding="async" data-nimg="1" class="rounded-sm" src="${ChatPGT_StyleMode.chat_avatar}" style="color: transparent;">`

                        //更改【ChatGPT】的名字
                        var main_text = document.querySelectorAll('[data-testid*="conversation-turn"] .font-semibold.select-none')[i+1]
                        main_text.innerText = ChatPGT_StyleMode.chat_name
                    }
                }

            }, 50)

        }

    }

    let main = {
        registerMenuCommand() {
            GM_registerMenuCommand('设置', () => {
                let html = `<div style="font-size: 1em;">
                              <label class="panai-setting-label">用户<input type="checkbox" id="User"} class="panai-setting-checkbox" ${ChatPGT_StyleMode.user ? 'checked' : ''}></label>
                              <label class="panai-setting-label">用户昵称<input type="text" id="User-Name"} value="${ChatPGT_StyleMode.user_name}"></label>
                              <label class="panai-setting-label">用户头像<input type="text" id="User-Avatar"} value="${ChatPGT_StyleMode.user_avatar}"></label>
                              <label class="panai-setting-label">ChatCPT<input type="checkbox" id="Chat"} class="panai-setting-checkbox" ${ChatPGT_StyleMode.chat ? 'checked' : ''}></label>
                              <label class="panai-setting-label">ChatCPT昵称<input type="text" id="Chat-Name"} value="${ChatPGT_StyleMode.chat_name}"></label>
                              <label class="panai-setting-label">ChatCPT头像<input type="text" id="Chat-Avatar"} value="${ChatPGT_StyleMode.chat_avatar}"></label>
                            </div>`;
                Swal.fire({
                    title: 'ChatGPT 头像更改器',
                    html,
                    icon: 'info',
                    showCloseButton: true,
                    confirmButtonText: '保存',
                    customClass
                }).then((res) => {
                    if (res.isConfirmed) {
                        var config = {
                            user:document.getElementById('User').checked,
                            user_name:document.getElementById('User-Name').value,
                            user_avatar:document.getElementById('User-Avatar').value,
                            chat:document.getElementById('Chat').checked,
                            chat_name:document.getElementById('Chat-Name').value,
                            chat_avatar:document.getElementById('Chat-Avatar').value,
                        }
                        var confied = JSON.stringify(config)
                        localStorage.setItem('ChatPGT_StyleMode', confied);
                        window.location.href = '?timestamp=' + new Date().getTime();

                    }
                });
            });
        },
        isTopWindow() {
            return window.self === window.top;
        },
        init() {
            this.isTopWindow() && this.registerMenuCommand();
        },
    }
    main.init();
})();