Greasy Fork

Greasy Fork is available in English.

grok Paste

Paste text into Grok textarea from main page

当前为 2025-08-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         grok Paste
// @description  Paste text into Grok textarea from main page
// @match        *://grok.com/*
// @version 0.0.1.20250803132444
// @namespace http://greasyfork.icu/users/1435046
// ==/UserScript==

(function () {
  'use strict';

  window.addEventListener("message", event => {
    const data = event.data;

    if (event.data && event.data.type === 'reasonButtonClicked') {
      document.querySelector('button[aria-label="Think"]').click();
      return;
    }

    if (event.data?.type === 'newChatButtonClicked') {
      const customNewChatButton = document.querySelector('a[href="/"]');
      if (customNewChatButton) customNewChatButton.click();
    }

    //grab style element
    let grokCssStyleId = document.getElementById('grokCssStyleId');

    let chatMessageInput = document.querySelector('div:has(> div > form > div > div > div > textarea[aria-label="Ask Grok anything"])');
    let chatMessageInputRule = 'div:has(> div > form > div > div > div > textarea[aria-label="Ask Grok anything"]) {display: none !important};';


    let chatMessageInputBackdrop = document.querySelector('.chat-input-backdrop');
    let header = document.querySelector('div:has(> div > div > button[aria-label="Toggle sidebar"] > svg > path[d="M3 12h18"])');

    //if event data type is defaultChatMessageInputDisplay
    if (event.data?.type === 'defaultChatMessageInputDisplay') {
      console.log('default');
      if (chatMessageInput) {

        //delete the rule here
        grokCssStyleId.innerHTML = grokCssStyleId.innerHTML.replace(`${chatMessageInputRule}`, '')

        chatMessageInputBackdrop && chatMessageInputBackdrop.style.removeProperty('display');
        header.style.removeProperty('display');

        //return
        return;
      }
    }

    if (event.data?.type === 'customizeChatMessageInputDisplay') {
      console.log('customize');
      if (chatMessageInput) {

        grokCssStyleId.innerHTML += `${chatMessageInputRule}`

        console.log(chatMessageInputBackdrop);

        chatMessageInputBackdrop && (chatMessageInputBackdrop.style.display = 'none');
        header.style.display = 'none';

        //return
        return;
      }
    }


    if (event.data.type === "prompt" && event.data.content.trim()) {
      const textarea = document.querySelector('textarea[aria-label="Ask Grok anything"]');
      if (textarea) {
        const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
        nativeInputValueSetter.call(textarea, event.data.content); // Set like the browser would

        // Now trigger a React-compatible InputEvent
        const inputEvent = new InputEvent('input', {
          bubbles: true,
          cancelable: true,
          inputType: 'insertText',
          data: event.data.content,
        });

        textarea.dispatchEvent(inputEvent);

        document.querySelector('button[aria-label="Submit"]').click();
      }
    }
  });
})();