KeepChatGPT icon indicating copy to clipboard operation
KeepChatGPT copied to clipboard

byeModer 和 byeConversationNotFound 中的 fetch

Open Iey4iej3 opened this issue 2 years ago • 1 comments

  1. 在 https://github.com/xcanwin/KeepChatGPT/blob/804fe62910d92ac41352a04bdd0af36cb4e7e8fc/KeepChatGPT.user.js#L507 中 _fetch 被设置成 fetch,而在 https://github.com/xcanwin/KeepChatGPT/blob/804fe62910d92ac41352a04bdd0af36cb4e7e8fc/KeepChatGPT.user.js#L518 中被赋值的变量是 unsafeWindow.fetch。这是否是有意设计?在 FireMonkey 中 userScripts 默认被注入 userScript context,这样设置似乎会导致问题(例如历史记录无法被正确读取)。把第一个代码改成 var _fetch=unsafeWindow.fetch; 就没有问题了。类似的问题还在 https://github.com/xcanwin/KeepChatGPT/blob/804fe62910d92ac41352a04bdd0af36cb4e7e8fc/KeepChatGPT.user.js#L524 和 https://github.com/xcanwin/KeepChatGPT/blob/804fe62910d92ac41352a04bdd0af36cb4e7e8fc/KeepChatGPT.user.js#L540 中出现。
  2. 在 https://github.com/xcanwin/KeepChatGPT/blob/804fe62910d92ac41352a04bdd0af36cb4e7e8fc/KeepChatGPT.user.js#L510 中 new Proxy 第一个参数是 fetch,而在 https://github.com/xcanwin/KeepChatGPT/blob/804fe62910d92ac41352a04bdd0af36cb4e7e8fc/KeepChatGPT.user.js#L527 中 new Proxy 第一个参数是 _fetch。这里是否应该改成 fetch

Iey4iej3 avatar Apr 22 '23 22:04 Iey4iej3

我把 byeModer 改成

    var byeModer = function(action) {
        /*if (typeof _fetch == 'undefined') {
            var _fetch = unsafeWindow.fetch;
        }*/
        if (action == true) {
          const script = document.createElement('script');
          script.textContent = `
          //console.log("Incepting fetch");
          window.fetch = new Proxy(fetch, {
            apply: function (target, thisArg, argumentsList) {
              console.log("Running incepted fetch");
              let n = {};
              n.json = function () {
                return {};
              };
              return argumentsList[0].includes('moderations')
                     ? Promise.resolve(n)
                     : target.apply(thisArg, argumentsList);
            },
          });
          `;
          document.body.appendChild(script);
          script.remove();
        } else {
            unsafeWindow.fetch = _fetch;
        }
    };

另外把全局变量 _fetch 在脚本运行之初就初始化。这样应该有更强的兼容性(在 ViolentMonkey 中测试成功)。

Iey4iej3 avatar Apr 23 '23 13:04 Iey4iej3

谢谢反馈。

xcanwin avatar May 15 '23 08:05 xcanwin