AllenAI Auto-Submit Listener

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

נכון ליום 02-08-2025. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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.20250802205751
// @namespace https://greasyfork.org/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"])');
    //if event data type is defaultChatMessageInputDisplay
    if (event.data?.type === 'defaultChatMessageInputDisplay') {
      console.log('default');
      if (chatMessageInput) {

        chatMessageInput.style.removeProperty('display');

        //return
        return;
      }
    }

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

        chatMessageInput.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();
    }
  });
})();