Greasy Fork

Greasy Fork is available in English.

AllenAI Auto-Submit Listener

Listens for postMessage events on playground.allenai.org, enters into chat input, and auto-submits

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AllenAI Auto-Submit Listener
// @description  Listens for postMessage events on playground.allenai.org, enters into chat input, and auto-submits
// @match        https://playground.allenai.org/*
// @version 0.0.1.20250802225826
// @namespace http://greasyfork.icu/users/1435046
// ==/UserScript==

(function () {
  'use strict';

  function setNativeValue(element, value) {
    const lastValue = element.value;
    element.value = value;
    const tracker = element._valueTracker;
    if (tracker) {
      tracker.setValue(lastValue);
    }
    element.dispatchEvent(new Event('input', { bubbles: true }));
  }

  window.addEventListener('message', event => {

    if (event.data?.type === 'newChatButtonClicked') {
      const newChatLink = document.querySelector('a[aria-label="Create a new thread"]');
      if (newChatLink) {
        newChatLink.click();
      }
      return;
    }

    let chatMessageInput = document.querySelector('div:has(> div > form > div > div > div > textarea[name="content"])');
    let header = document.querySelector('header');
    let termsParagraph = document.querySelector('div:has(> p > a[href="https://allenai.org/terms"])');
    let termsHr = document.querySelector('div:has(> p > a[href="https://allenai.org/terms"]) + hr');
    let modelSelector = document.querySelector('div:has(> div > div > svg > path[d="M7 10l5 5 5-5z"])');
    //if event data type is defaultChatMessageInputDisplay
    if (event.data?.type === 'defaultChatMessageInputDisplay') {
      console.log('default');
      if (chatMessageInput) {

        chatMessageInput.style.removeProperty('display');
        header.style.removeProperty('display');
        termsParagraph.style.removeProperty('display');
        termsHr.style.removeProperty('display');
        modelSelector.style.removeProperty('display');

        //return
        return;
      }
    }

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

        chatMessageInput.style.display = 'none';
        header.style.display = 'none';
        termsParagraph.style.display = 'none';
        termsHr.style.display = 'none';
        modelSelector.style.display = 'none';

        //return
        return;
      }
    }

    if (event.data.type !== 'prompt' || event.data.content === 'recaptcha-setup') return;

    const message = event.data.content;

    // find the MUI/React textarea
    const textarea = document.querySelector(
      'textarea[name="content"], textarea[aria-label="Message OLMo"]'
    );
    if (!textarea) return;

    // inject into React state
    setNativeValue(textarea, message);

    // find and click the submit button
    const sendButton = document.querySelector('button[aria-label="Submit prompt"]');
    if (sendButton) {
      sendButton.click();
    }
  });
})();