garywill / BigSearch

Browser extension. Definitly more than a GET/POST sender. Handily use search engines via a Flexible Tool! UI has Vimium-like feature 🌐🔍 (Pure-client. No 3rd-party server needed) 大术专搜 既专又广 手敲几下 纵横去往
GNU Affero General Public License v3.0
247 stars 16 forks source link

对话搜索无法触发输入和搜索 #16

Open xubuild opened 10 months ago

xubuild commented 10 months ago

尝试添加kimi,打开新网页后,无法正常触发输入和搜索。在用的油猴脚本使用粘贴方式可以正常触发。

站点:https://kimi.moonshot.cn/

以下配置无法触发输入和搜索

"kimi": {
    "dname": "kimi",
    "addr": "https://kimi.moonshot.cn",
    "ajax": [
      3000,
      "[data-testid='msh-chatinput-editor']",
      500,
      "[data-testid='msh-chatinput-send-button']"
    ],
    "action": "https://kimi.moonshot.cn/chat"
  },

使用js脚本可以完成输入和搜索

  function saveTextToClipboard(text) {
      navigator.clipboard.writeText(text)
          .then(() => {
              console.log('文本已成功保存到剪贴板');
          })
          .catch((error) => {
              console.error('保存文本到剪贴板时出现错误:', error);
          });
  }

  function triggerPasteEvent(element, value) {
      const event = new ClipboardEvent('paste', {
          dataType: 'text/plain',
          clipboardData: new DataTransfer(),
          bubbles: true,
          cancelable: true,
      });

      event.clipboardData.setData('text/plain', value);

      element.dispatchEvent(event);
  }

  var arxiv_paper = urlParams.get('arxiv');
  var editorElement = document.querySelector('[data-testid="msh-chatinput-editor"]');

  if (!editorElement && retryCount < maxRetries) {
      retryCount++;
      setTimeout(getElementWithRetry, retryInterval);
  } else if (editorElement) {
      editorElement.focus();
      saveTextToClipboard(arxiv_paper);

      // 获取剪贴板中的值
      navigator.clipboard.readText().then((clipboardValue) => {
          triggerPasteEvent(document.querySelector('[data-testid="msh-chatinput-editor"]'), clipboardValue);
          setTimeout(function () {
              document.querySelector('button[data-testid="msh-chatinput-send-button"]').click();

          }, 500);
      });

  }

同样的bing copilot也无法完成输入和搜索: https://www.bing.com/search?form=MY0291&OCID=MY0291&q=Bing+AI&showconv=1

"bing_chat": {
    "dname": "bing_chat",
    "addr": "https://www.bing.com/search?form=MY0291&OCID=MY0291&q=Bing+AI&showconv=1",
    "ajax": [
      5000,
      "#searchbox",
      500,
      "[aria-label='Submit']"
    ],
    "action": "https://www.bing.com/search?q=Bing+AI&showconv=1"
  }

谢谢!

garywill commented 10 months ago

kimi那个网页的主页(我没有账号,只能看主页)的输入框[data-testid='msh-chatinput-editor']不是<input><textarea>,是个<div>

这种情况还没有添加 看你贴出的那个脚本,如果要像它那样在content script读剪贴板然后粘贴,应该有要求我们的扩展有权限才行

我想下先,应该怎么处理这种用<div>来当输入框的情况。你有什么好建议也可以说下


那个copilot我没有账号,不显示#searchbox,我目前没法检查