AllenAI Message Listener

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

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

  1. // ==UserScript==
  2. // @name AllenAI Message Listener
  3. // @description Listens for postMessage events on playground.allenai.org and enters into chat input and sends
  4. // @match https://playground.allenai.org/*
  5. // @grant none
  6. // @version 0.0.1.20250511172442
  7. // @namespace https://greasyfork.org/users/1435046
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. window.addEventListener('message', event => {
  14. // 1. Read the incoming message
  15. const message = event.data;
  16.  
  17. // 2. Locate the chat input (by name or aria-label)
  18. const textarea = document.querySelector(
  19. 'textarea[name="content"], textarea[aria-label="Message OLMo"]'
  20. );
  21. if (!textarea) return; // not on screen yet
  22.  
  23. // 3. Insert the text and notify any framework listeners
  24. textarea.value = message;
  25. textarea.dispatchEvent(new Event('input', { bubbles: true }));
  26.  
  27. // 4. Click the send button
  28. const sendBtn = document.querySelector('button[type="submit"][aria-label="Submit prompt"]');
  29. if (sendBtn) sendBtn.click();
  30. });
  31. })();