给deepseek网站添加q查询参数:chat.deepseek.com/?q={query}

从URL中提取q查询参数,填入对话框,提交搜索

目前为 2025-02-07 提交的版本。查看 最新版本

// ==UserScript==
// @name         给deepseek网站添加q查询参数:chat.deepseek.com/?q={query}
// @namespace    http://tampermonkey.net/
// @version      2025-2-7
// @description  从URL中提取q查询参数,填入对话框,提交搜索
// @author       smilingpoplar
// @match        https://chat.deepseek.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=deepseek.com
// @license      MIT
// ==/UserScript==

(() => {
    'use strict';
    const query = new URLSearchParams(window.location.search).get('q');
    if (!query) return;
    const input = document.querySelector('#chat-input');
    if (!input) return console.error('找不到输入框');

    const getReactProps = el => el[Object.keys(el).find(k => k.startsWith('__reactProps$'))];

    getReactProps(input)?.onChange?.({
        target: { value: query },
        currentTarget: { value: query },
        preventDefault: () => { },
        stopPropagation: () => { }
    });
    input.value = query;

    setTimeout(() => {
        getReactProps(input)?.onKeyDown?.({
            key: 'Enter',
            keyCode: 13,
            shiftKey: false,
            target: input,
            currentTarget: input,
            preventDefault: () => { },
            stopPropagation: () => { },
        });
    }, 500);
})();