stepfun Paste

a

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         stepfun Paste
// @description  a
// @match        *://stepfun.ai/*
// @version 0.0.1.20260211154918
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function () {
  'use strict';

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

    if (event.data?.type === 'newChatButtonClicked') {
      const customNewChatButton = document.querySelector('button:has(> svg.custom-icon-newtopic-outline > path[d^="M24 6.5C14.2576 6.5"])');
      if (customNewChatButton) customNewChatButton.click();
    }

    let stepfunCssStyleId = document.getElementById('stepfunCssStyleId');

    let chatMessageInput = document.querySelector('div:has(> div > div > div > div > div > div > textarea[class*="Publisher_textarea"])');
    let chatMessageInputRule = 'div:has(> div > div > div > div > div > div > textarea[class*="Publisher_textarea"]) {display: none !important;}';

    let suggestionDiv = document.querySelector('div:has(> div > div > button > div > svg.custom-icon-image-edit-new-outline)');

    let suggestionDivRule = 'div:has(> div > div > button > div > svg.custom-icon-image-edit-new-outline) {display: none !important;}';

    let suggestionDiv2Rule = 'div[class*="transition-opacity"]:has(> div[class*="items-start"] > div[class*="flex"] > div[class*="grid"] > button[class*="rounded-xl"] > div[class*="truncate"]) {display: none !important;}';

    let newChatSuggestionDivRule = 'div:has(> div > button > div > svg.custom-icon-img-outline > path[d*="M4.5 12C4.5 7.85787"]) {display: none !important;}';

    let header = document.querySelector('header');

    let headerRule = 'header {display: none !important;}';

    //if event data type is defaultChatMessageInputDisplay

    if (event.data?.type === 'defaultChatMessageInputDisplay') {

      console.log('default');

      if (chatMessageInput) {

        stepfunCssStyleId.innerHTML = stepfunCssStyleId.innerHTML.replace(`${chatMessageInputRule}`, '');
        stepfunCssStyleId.innerHTML = stepfunCssStyleId.innerHTML.replace(`${suggestionDivRule}`, '');
        stepfunCssStyleId.innerHTML = stepfunCssStyleId.innerHTML.replace(`${suggestionDiv2Rule}`, '');
        stepfunCssStyleId.innerHTML = stepfunCssStyleId.innerHTML.replace(`${newChatSuggestionDivRule}`, '');
        stepfunCssStyleId.innerHTML = stepfunCssStyleId.innerHTML.replace(`${headerRule}`, '');

        //return
        return;
      }
    }

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

        stepfunCssStyleId.innerHTML += `${chatMessageInputRule}`
        stepfunCssStyleId.innerHTML += `${suggestionDivRule}`
        stepfunCssStyleId.innerHTML += `${suggestionDiv2Rule}`
        stepfunCssStyleId.innerHTML += `${newChatSuggestionDivRule}`
        stepfunCssStyleId.innerHTML += `${headerRule}`

        //return
        return;
      }
    }

    if (event.data.type === "prompt" && event.data.content.trim()) {
      const textarea = document.querySelector('textarea[class*="Publisher_textarea"]');
      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);

        const sendButton = document.querySelector('button:has(> svg.custom-icon-send-outline > path[d^="M25.4874 10.6629C25.1081"])');
        if (!sendButton.classList.contains('cursor-not-allowed')) {
          sendButton.click();
        } else {
          const observer = new MutationObserver(() => {
            if (!sendButton.classList.contains('cursor-not-allowed')) {
              observer.disconnect();
              sendButton.click();
            }
          });
          observer.observe(sendButton, { attributes: true, attributeFilter: ['class'] });
        }
      }
    }
  });
})();