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-05-16 提交的版本,查看 最新版本

// ==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.20250516101342
// @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;
}

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