AllenAI Message Listener

Listens for postMessage events on playground.allenai.org and enters into chat input

当前为 2025-05-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AllenAI Message Listener
// @description  Listens for postMessage events on playground.allenai.org and enters into chat input
// @match        https://playground.allenai.org/*
// @version 0.0.1.20250511173624
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==
 
(function() {
    'use strict';
 
    window.addEventListener('message', event => {
if (typeof event.data !== 'string' || event.data === 'recaptcha-setup') return;

        // 1. Read the incoming message
        const message = event.data;
 
        // 2. Locate the chat input (by name or aria-label)
        const textarea = document.querySelector(
            'textarea[name="content"], textarea[aria-label="Message OLMo"]'
        );
        if (!textarea) return; // not on screen yet
 
        // 3. Insert the text and notify any framework listeners
        textarea.value = message;
        textarea.dispatchEvent(new Event('input', { bubbles: true }));
    });
})();