bigonion 发表于 2022-12-13 13:59:59

本帖最后由 bigonion 于 2022-12-14 14:40 编辑

https://raw.githubusercontent.com/LiWeny16/chatGPT-tool-plus/main/source/%E8%87%B4%E8%B0%A2.png

bigonion 发表于 2022-12-13 14:01:24

本帖最后由 bigonion 于 2022-12-14 14:40 编辑

可以看看他脚本之前的版本,是用的onloadend来接收数据的

王一之 发表于 2022-12-13 14:03:23

cxxjackie 发表于 2022-12-12 22:41
stream不行的话用arraybuffer再手动转码?边接收边显示的话用onprogress?只是一点想法,没尝试过。 ...

不行吧,onprogress只是接收进度,arraybuffer那些都是等数据加载完成后再返回

stream的话是可以等服务器返回数据然后马上就读取到,服务器边写客户端边度,其他类型就是等服务器全部写完close后再一次性读出来

脚本猫还没支持stream,我去了解一下,之前没想过还会有这种场景

tfsn20 发表于 2022-12-13 14:49:35

bigonion 发表于 2022-12-13 13:57
哈哈哈哈哈哈你仔细看看他的脚本致谢一栏吧,是不是写着bigonion呢?

搜嘎,原来是哥哥的思路,ggnb{:4_94:}

cxxjackie 发表于 2022-12-13 20:42:53

王一之 发表于 2022-12-13 14:03
不行吧,onprogress只是接收进度,arraybuffer那些都是等数据加载完成后再返回

stream的话是可以等服务 ...

这样啊,我没怎么用过onprogress,不太了解。stream可以用arraybuffer读吗?可以的话好像支不支持也无所谓。

王一之 发表于 2022-12-13 22:29:15

cxxjackie 发表于 2022-12-13 20:42
这样啊,我没怎么用过onprogress,不太了解。stream可以用arraybuffer读吗?可以的话好像支不支持也无所 ...

重点不是stream可不可以用arraybuffer读,重要的是能不能中途读取出内容,例如下面这个网站:http://test-case.ggnb.top/stream

如果使用arraybuffer,那么只能等这个数据全部完全返回完毕后才能读取到数据,如果使用stream就可以服务器返回一点就读取出一点。

```js
// ==UserScript==
// @name         gm xhr stream
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @descriptiontry to take over the world!
// @author       You
// @match      https://bbs.tampermonkey.net.cn/
// @grant      GM_xmlhttpRequest
// @connect      test-case.ggnb.top
// ==/UserScript==

GM_xmlhttpRequest({
    url: "http://test-case.ggnb.top/stream",
    responseType: "arraybuffer",
    onloadstart(ev) {
      console.log('onloadstart', ev);
    },
    onprogress(ev) {
      console.log("onprogress", ev);
    },
    onload(ev) {
      console.log("onload", ev);
    }
});

GM_xmlhttpRequest({
    url: "http://test-case.ggnb.top/stream",
    responseType: "stream",
    onloadstart(ev) {
      /**
         * @type ReadableStream
         */
      const stream = ev.response;
      const reader = stream.getReader();

      reader.read().then(function read({ done, value }) {
            if (done) {
                return;
            }
            console.log('read', new TextDecoder().decode(value));
            reader.read().then(read);
      })

      console.log('onloadstart', ev);
    },
    onprogress(ev) {
      console.log("onprogress", ev);
    },
    onload(ev) {
      console.log("onload", ev);
    }
});
```

用tm执行,脚本猫等我研究研究stream然后加入😭

zhengbangbo 发表于 2022-12-14 08:15:57

bigonion 大佬太强了,哈哈。刚翻 (https://github.com/LiWeny16/chatGPT-tool-plus/blob/main/scriptCat/scriptCatforum2.md) 才知道大佬在写教学文章。

我去研究别的东西(GitHub 中的 GM_fetch 实现、工程化)去了,路走歪了,还是得扎扎实实看文档。

bigonion 发表于 2022-12-14 14:47:49

zhengbangbo 发表于 2022-12-14 08:15
bigonion 大佬太强了,哈哈。刚翻 (https://github.com/LiWeny16/chatGPT-tool-plus/blob/main/scr ...

zbb大佬好!!{:4_94:}

cxxjackie 发表于 2022-12-14 21:09:41

王一之 发表于 2022-12-13 22:29
重点不是stream可不可以用arraybuffer读,重要的是能不能中途读取出内容,例如下面这个网站:http:// ...

就是假如不支持stream(我试过了,旧版油猴也不支持),arraybuffer可以作为一个兼容方案吧,边下边读应该视为非必须的特性。

王一之 发表于 2022-12-14 21:28:45

cxxjackie 发表于 2022-12-14 21:09
就是假如不支持stream(我试过了,旧版油猴也不支持),arraybuffer可以作为一个兼容方案吧,边下边读应 ...

是的,可以的

对于楼主的场景表现就是会慢很多
页: 1 [2] 3
查看完整版本: 草履虫都能看懂的chatGPT-AI接入谷歌必应实战教学(一)开端