DeepSeek Traits

A recreation of OpenAI's ChatGPT Traits feature. By default does nothing. Configure via userscript.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DeepSeek Traits
// @name:zh-CN   深度搜索特性
// @namespace    http://tampermonkey.net/
// @version      2025-01-24
// @description  A recreation of OpenAI's ChatGPT Traits feature. By default does nothing. Configure via userscript.
// @description:zh-CN 复制OpenAI的ChatGPT特性功能,默认无操作,需通过用户脚本配置
// @author       https://github.com/xskutsu
// @match        *://*.deepseek.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @icon         https://www.google.com/s2/favicons?sz=64&domain=deepseek.com
// @license      MIT
// ==/UserScript==

(function () {
    "use strict";
    const locale = {
        en: {
            set: "Set DeepSeek Traits",
            clear: "Clear DeepSeek Traits",
            prompt: "Enter traits for DeepSeek:",
            updated: "Traits Updated!",
            confirm: "Are you sure you want to clear DeepSeek Traits?",
            cleared: "Traits cleared!",
            instruct: "When you respond to this message by the user, please follow these DeepSeek Traits (instructions, guidelines, desires) provided by the user: "
        },
        zh: {
            set: "设置DeepSeek特性",
            clear: "清除DeepSeek特性",
            prompt: "输入DeepSeek的特性:",
            updated: "特性已更新!",
            confirm: "确定要清除DeepSeek特性吗?",
            cleared: "特性已清除!",
            instruct: "当您回复用户的此消息时,请遵循用户提供的这些DeepSeek特质(指示、指南、需求):"
        }
    };
    const t = locale[navigator.language.startsWith('zh') ? 'zh' : 'en'];

    let DeepSeekTraits = GM_getValue("traits", "");

    GM_registerMenuCommand(t.set, function () {
        const traits = prompt(t.prompt, GM_getValue("traits", "")).trim().replace(/[\n\r\t]/gm, "");
        if (traits.length !== 0) {
            GM_setValue("traits", traits);
            DeepSeekTraits = traits;
            alert(t.updated);
        }
    });

    GM_registerMenuCommand(t.clear, function () {
        if (confirm(t.confirm)) {
            GM_setValue("traits", "");
            DeepSeekTraits = "";
            alert(t.cleared);
        }
    });

    function isJson(str) {
        try {
            JSON.parse(str);
        } catch (e) {
            return false;
        }
        return true;
    }

    const originalSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function(body, ...args) {
        if (isJson(body) && DeepSeekTraits.length !== 0) {
            const data = JSON.parse(body);
            if (data.hasOwnProperty("prompt")) {
                data.prompt = `${t.instruct}"${DeepSeekTraits}"\n\nUser:\n${data.prompt}`;
                body = JSON.stringify(data);
            }
        }
        originalSend.call(this, body, ...args);
    };
})();