phind

Listen for postMessage from parent, log to console, enter it into the chat input, and submit

  1. // ==UserScript==
  2. // @name phind
  3. // @description Listen for postMessage from parent, log to console, enter it into the chat input, and submit
  4. // @match https://www.phind.com/*
  5. // @version 0.0.1.20250521215436
  6. // @namespace https://gf.qytechs.cn/users/1435046
  7. // ==/UserScript==
  8.  
  9. (function () {
  10. 'use strict';
  11.  
  12. window.addEventListener("message", (event) => {
  13.  
  14. if (event.data && event.data.type === 'newChatButtonClicked') {
  15. // Click the "New Chat" button
  16. const newChatButton = document.querySelector('button#new-chat-button');
  17. if (newChatButton) newChatButton.click();
  18. return;
  19. }
  20.  
  21. if (event.data?.type === "prompt") {
  22. const input = document.getElementById("chat-input");
  23. const button = document.getElementById("send-message-button");
  24.  
  25. input.innerText = event.data.content;
  26.  
  27. const observer = new MutationObserver(() => {
  28. if (!button.hasAttribute("disabled")) {
  29. button.click();
  30. observer.disconnect(); // stop observing once clicked
  31. }
  32. });
  33.  
  34. observer.observe(button, { attributes: true, attributeFilter: ["disabled"] });
  35. }
  36. });
  37. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址