AllenAI Auto-Submit Listener

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

  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.20250516101342
  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.  
  24. if (event.data?.type === 'newChatButtonClicked') {
  25. const newChatLink = document.querySelector('a[aria-label="Create a new thread"]');
  26. if (newChatLink) {
  27. newChatLink.click();
  28. }
  29. return;
  30. }
  31.  
  32. if (event.data.type !== 'prompt' || event.data.content === 'recaptcha-setup') return;
  33.  
  34. const message = event.data.content;
  35.  
  36. // find the MUI/React textarea
  37. const textarea = document.querySelector(
  38. 'textarea[name="content"], textarea[aria-label="Message OLMo"]'
  39. );
  40. if (!textarea) return;
  41.  
  42. // inject into React state
  43. setNativeValue(textarea, message);
  44.  
  45. // find and click the submit button
  46. const sendButton = document.querySelector('button[aria-label="Submit prompt"]');
  47. if (sendButton) {
  48. sendButton.click();
  49. }
  50. });
  51. })();