// ==UserScript== // @name GPT4 Model Switcher // @namespace https://github.com/LShang001 // @description 切换 OpenAI GPT-4 使用的模型(gpt-4 和 gpt-4-mobile)。 // @author LShang // @license MIT // @match https://chat.openai.com/* // @match https://chat.zhile.io/* // @version 1 // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; let isScriptEnabled = localStorage.getItem('isScriptEnabled') === 'true'; let modelInUse = isScriptEnabled ? 'gpt-4-mobile' : 'gpt-4'; const style = document.createElement('style'); style.innerHTML = ` .toggle-button { position: fixed; bottom: 10px; right: 10px; z-index: 9999; display: flex; align-items: center; gap: 10px; padding: 5px; background-color: #242424; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } .toggle-button span { color: white; font-size: 16px; } .toggle-button input { display: none; } .slider { cursor: pointer; background-color: #ccc; transition: 0.4s; border-radius: 34px; width: 60px; height: 34px; position: relative; } .slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; transition: 0.4s; border-radius: 50%; } input:checked + .slider { background-color: #4CAF50; } input:checked + .slider:before { transform: translateX(26px); } `; document.head.appendChild(style); const toggleButton = document.createElement('label'); toggleButton.className = 'toggle-button'; const toggleText = document.createElement('span'); toggleText.textContent = 'Model: ' + modelInUse; toggleButton.appendChild(toggleText); const toggleInput = document.createElement('input'); toggleInput.type = 'checkbox'; toggleInput.checked = isScriptEnabled; toggleInput.addEventListener('change', toggleScript); toggleButton.appendChild(toggleInput); const slider = document.createElement('span'); slider.className = 'slider'; toggleButton.appendChild(slider); document.body.appendChild(toggleButton); function toggleScript() { isScriptEnabled = !isScriptEnabled; localStorage.setItem('isScriptEnabled', isScriptEnabled); modelInUse = isScriptEnabled ? 'gpt-4-mobile' : 'gpt-4'; toggleText.textContent = 'Model: ' + modelInUse; } const originalFetch = window.fetch; function modifiedFetch(url, init) { if (!isScriptEnabled) { return originalFetch(url, init); } try { if (init && init.method === 'POST' && init.body && init.headers['Content-Type'] === 'application/json') { let data = JSON.parse(init.body); if (data.hasOwnProperty('model')) { data.model = data.model === 'gpt-4' ? 'gpt-4-mobile' : 'gpt-4'; init.body = JSON.stringify(data); } } return originalFetch(url, init); } catch (e) { console.error('在处理请求时出现错误:', e); return originalFetch(url, init); } } window.addEventListener('load', () => { window.fetch = modifiedFetch; }); })();