KeepChatGPT
KeepChatGPT copied to clipboard
byeModer 和 byeConversationNotFound 中的 fetch
- 在 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 中出现。 - 在 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?
我把 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 中测试成功)。
谢谢反馈。