DeepSeek Traits

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
    };
})();