AllenAI Auto-Submit Listener

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

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

  1. // ==UserScript==
  2. // @name AllenAI Auto-Submit Listener
  3. // @description Listens for postMessage events on playground.allenai.org, enters into chat input, and auto-submits
  4. // @match https://playground.allenai.org/*
  5. // @version 0.0.1.20250512101351
  6. // @namespace https://greasyfork.org/users/1435046
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. 'use strict';
  11.  
  12. function setNativeValue(element, value) {
  13. const lastValue = element.value;
  14. element.value = value;
  15. const tracker = element._valueTracker;
  16. if (tracker) {
  17. tracker.setValue(lastValue);
  18. }
  19. element.dispatchEvent(new Event('input', { bubbles: true }));
  20. }
  21.  
  22. window.addEventListener('message', event => {
  23. // ignore non-string messages and internal recaptcha message
  24. if (typeof event.data !== 'string' || event.data === 'recaptcha-setup') return;
  25.  
  26. const message = event.data;
  27.  
  28. // find the MUI/React textarea
  29. const textarea = document.querySelector(
  30. 'textarea[name="content"], textarea[aria-label="Message OLMo"]'
  31. );
  32. if (!textarea) return;
  33.  
  34. // inject into React state
  35. setNativeValue(textarea, message);
  36.  
  37. // find and click the submit button
  38. const sendButton = document.querySelector('button[aria-label="Submit prompt"]');
  39. if (sendButton) {
  40. sendButton.click();
  41. }
  42. });
  43. })();