使用 Alfred webSearch 快速启动 ChatGPT

需求

  • 实现 alfred 搜索框中,使用 gpt + {query} 向 chatGPT提问

  • 由于 chatGPT 不支持 URL 传参交互,只能用一些 hack 的方法。

快速上手

前提

  1. chrome 中安装了油猴插件
  2. 已安装 Alfred

1 在油猴中安装以下脚本

// ==UserScript==
// @name         ChatGPT Helper_2
// @namespace    none
// @version      0.1
// @description  ChatGPT Helper
// @author       lihaji
// @match        https://chat.openai.com/*
// @run-at       document-idle
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant        none
// ==/UserScript==


(function() {
    'use strict';
    const textareaSelector = '#__next textarea';
    const buttonSelector = '#__next textarea + button';

    const textareaElement = document.querySelector(textareaSelector);
    const buttonElement = document.querySelector(buttonSelector);
    // console.log(buttonElement)

    const hash = location.hash;

    textareaElement.innerHTML = decodeURIComponent(hash.replace(/^#/, ''));
    textareaElement.value = decodeURIComponent(hash.replace(/^#/, ''));
    buttonElement.disabled = false;
    // buttonElement.click();
    var event = new Event('input', { bubbles: true });
    // 触发输入事件
    textareaElement.dispatchEvent(event);

    setTimeout(function(){
        console.log(buttonElement);
        buttonElement.click();
    },1000);

})();

2 在 Alfred 中添加搜索规则

在这里插入图片描述

3 测试

在这里插入图片描述

实现原理

  1. 脚本或首先获取 id__next 的容器下的 textarea (即输入框),然后将 hash 部分的字符添加到 textarea , 再点击发送按钮。
  2. 当前版本的 chatGPT 中直接修改 textareavalue 无法激活发送按钮,需要模拟一次输入操作才可以激活按钮。

原方法来自nuomiphp,由于 chatGPT更新,该脚本已失效,故有以上修改。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值