ChatGPT 模型切换器(支持 GPT-4 Mobile 及所有可用模型)

通过启用 GPT-4 Mobile 模型,解除 ChatGPT 网页端对 GPT-4 模型使用次数的限制。同时还可启用其他模型进行切换,提供更多的灵活性。一般来说,该脚本不会与其他流行的 ChatGPT 脚本产生冲突。

当前为 2023-07-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT Model Switcher (Supports GPT-4 Mobile and All Available Models)
  3. // @name:zh-CN ChatGPT 模型切换器(支持 GPT-4 Mobile 及所有可用模型)
  4. // @name:zh-TW ChatGPT 模型切换器(支持 GPT-4 Mobile 及所有可用模型)
  5. // @namespace https://github.com/hydrotho/ChatGPT_Model_Switcher
  6. // @copyright 2023, Hydrotho (https://github.com/hydrotho)
  7. // @version 1.2.0
  8. // @description Override GPT-4 usage limits in the ChatGPT web interface by enabling the GPT-4 Mobile model. Additional models can also be enabled for switching, providing more flexibility. Generally, this script does not conflict with other popular ChatGPT scripts.
  9. // @description:zh-CN 通过启用 GPT-4 Mobile 模型,解除 ChatGPT 网页端对 GPT-4 模型使用次数的限制。同时还可启用其他模型进行切换,提供更多的灵活性。一般来说,该脚本不会与其他流行的 ChatGPT 脚本产生冲突。
  10. // @description:zh-TW 通过启用 GPT-4 Mobile 模型,解除 ChatGPT 网页端对 GPT-4 模型使用次数的限制。同时还可启用其他模型进行切换,提供更多的灵活性。一般来说,该脚本不会与其他流行的 ChatGPT 脚本产生冲突。
  11. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAH1UExURUxpcXeqn3WqnHWonHSpnHWonHWpnG22knWpnHWpnHSmm3apm3SpnHWonHWpnHSonHWpnHWpm3apnXWpnHWpm3WpnP///8fc19fm43mrn67Nxf7///r8+6HFvNPk4JS8ssXb1XirnsDY0sPa1Pj7+qbHv5i/tXeqnvz9/X6uoo65roq2q+Tu7P3+/qrKwqDEu9bm4vP39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EGCTzGwH6MA3Tew9u0Tp1HBmYOT+u+xZ62nl4AB91uGRQ+ZWAZ53HQqgMwgn3n6BC90+bl0nLJB51qH+QaphUD3EWuHVNuuhiQwlrPaS3n6zhEW+2G3I3TkSE3A5XalG860o/j/sSkcGAf62tS8MdvFfe3Oyf2tugyhBRB3qC/XuF/ADFWVOUHhFSXG4rXA78BYbiLJDUXqsMAAABXelRYdFJhdyBwcm9maWxlIHR5cGUgaXB0YwAAeJzj8gwIcVYoKMpPy8xJ5VIAAyMLLmMLEyMTS5MUAxMgRIA0w2QDI7NUIMvY1MjEzMQcxAfLgEigSi4A6hcRdPJCNZUAAAAASUVORK5CYII=
  12. // @grant none
  13. // @author Hydrotho
  14. // @match http*://chat.openai.com/*
  15. // @supportURL https://github.com/hydrotho/ChatGPT_Model_Switcher/issues
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. "use strict";
  21.  
  22. let useModelSwitcher = localStorage.getItem("useModelSwitcher") !== "false";
  23. let selectedModel = localStorage.getItem("selectedModel") || "GPT-4 (Mobile)";
  24.  
  25. const modelMapping = {
  26. "GPT-3.5": "text-davinci-002-render-sha",
  27. "GPT-4": "gpt-4",
  28. "GPT-4 Code Interpreter": "gpt-4-code-interpreter",
  29. "GPT-4 Web Browsing": "gpt-4-browsing",
  30. "GPT-4 Plugins": "gpt-4-plugins",
  31. "GPT-3.5 (Mobile)": "text-davinci-002-render-sha-mobile",
  32. "GPT-4 (Mobile)": "gpt-4-mobile",
  33. };
  34.  
  35. const CONVERSATION_API_URL =
  36. "https://chat.openai.com/backend-api/conversation";
  37. const MODELS_API_URL =
  38. "https://chat.openai.com/backend-api/models?history_and_training_disabled=false";
  39.  
  40. const ARKOSE_TOKEN_URLS = [
  41. "https://ai.fakeopen.com/api/arkose/token",
  42. "https://arkose-token.tms.im"
  43. ];
  44.  
  45. async function getArkoseToken() {
  46. const urls = [...ARKOSE_TOKEN_URLS];
  47. while (urls.length > 0) {
  48. const randomIndex = Math.floor(Math.random() * urls.length);
  49. const url = urls.splice(randomIndex, 1)[0];
  50.  
  51. try {
  52. const response = await fetch(url);
  53. if (response.ok) {
  54. const data = await response.json();
  55. if (data && "token" in data) {
  56. return data.token;
  57. } else {
  58. throw new Error("Token not present in response.");
  59. }
  60. }
  61. } catch (error) {
  62. console.error(
  63. `Error encountered while fetching arkose_token from ${url}: `,
  64. error
  65. );
  66. }
  67. }
  68.  
  69. console.error("Failed to fetch arkose_token from all URLs.");
  70. return null;
  71. }
  72.  
  73. async function handleModelsApiUrlResponse(fetchPromise) {
  74. return fetchPromise.then((response) => {
  75. if (response.ok) {
  76. response
  77. .clone()
  78. .json()
  79. .then((data) => {
  80. const accessibleModels = data.models.map((model) => model.slug);
  81. Object.keys(modelMapping).forEach((model) => {
  82. const mappedSlug = modelMapping[model];
  83. const selectOption = document.querySelector(
  84. `#modelSelect option[value="${model}"]`
  85. );
  86. if (selectOption && !accessibleModels.includes(mappedSlug)) {
  87. selectOption.disabled = true;
  88. if (selectedModel === model) {
  89. selectedModel = "GPT-3.5";
  90. localStorage.setItem("selectedModel", selectedModel);
  91. document.querySelector("#modelSelect").value = selectedModel;
  92. }
  93. }
  94. });
  95. });
  96. }
  97. return response;
  98. });
  99. }
  100.  
  101. window.fetch = new Proxy(window.fetch, {
  102. apply: async function (target, that, args) {
  103. let resource = args[0];
  104. let options = args[1];
  105.  
  106. if (useModelSwitcher && resource === CONVERSATION_API_URL) {
  107. const requestBody = JSON.parse(options.body);
  108. requestBody.model = modelMapping[selectedModel];
  109.  
  110. if (
  111. requestBody.model.startsWith("gpt-4") &&
  112. requestBody.arkose_token === null
  113. ) {
  114. requestBody.arkose_token = await getArkoseToken();
  115. } else if (
  116. requestBody.model.startsWith("text-davinci-002-render-sha") &&
  117. requestBody.arkose_token !== null
  118. ) {
  119. requestBody.arkose_token = null;
  120. }
  121.  
  122. options = { ...options, body: JSON.stringify(requestBody) };
  123. args[0] = resource;
  124. args[1] = options;
  125. }
  126.  
  127. const fetchPromise = Reflect.apply(target, that, args);
  128.  
  129. if (resource.includes(MODELS_API_URL)) {
  130. return handleModelsApiUrlResponse(fetchPromise);
  131. }
  132.  
  133. return fetchPromise;
  134. },
  135. });
  136.  
  137. function createSwitchElement() {
  138. const switchLabel = document.createElement("label");
  139. switchLabel.className = "switch";
  140. switchLabel.title = "Check to enable the model switcher";
  141.  
  142. const switchCheckbox = document.createElement("input");
  143. switchCheckbox.type = "checkbox";
  144. switchCheckbox.id = "useModelSwitcherCheckbox";
  145. switchCheckbox.checked = useModelSwitcher;
  146. switchCheckbox.addEventListener("change", (event) => {
  147. useModelSwitcher = event.target.checked;
  148. localStorage.setItem("useModelSwitcher", useModelSwitcher);
  149. });
  150.  
  151. const switchSlider = document.createElement("span");
  152. switchSlider.className = "slider round";
  153.  
  154. switchLabel.appendChild(switchCheckbox);
  155. switchLabel.appendChild(switchSlider);
  156.  
  157. return switchLabel;
  158. }
  159.  
  160. function createModelSelectElement() {
  161. const selectContainer = document.createElement("div");
  162. selectContainer.style.position = "relative";
  163.  
  164. const select = document.createElement("select");
  165. select.id = "modelSelect";
  166. select.addEventListener("change", (event) => {
  167. selectedModel = event.target.value;
  168. localStorage.setItem("selectedModel", selectedModel);
  169. });
  170.  
  171. for (const model in modelMapping) {
  172. const option = document.createElement("option");
  173. option.text = model;
  174. option.value = model;
  175. select.appendChild(option);
  176. }
  177.  
  178. select.value = selectedModel;
  179.  
  180. const selectArrow = document.createElement("div");
  181. selectArrow.style.cssText = `
  182. position: absolute;
  183. top: 50%;
  184. right: 8px;
  185. transform: translateY(-50%);
  186. width: 12px;
  187. height: 12px;
  188. background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333" width="18px" height="18px"%3E%3Cpath d="M7 10l5 5 5-5z"/%3E%3Cpath d="M0 0h24v24H0z" fill="none"/%3E%3C/svg%3E');
  189. background-repeat: no-repeat;
  190. background-position: center;
  191. pointer-events: none;
  192. `;
  193.  
  194. selectContainer.appendChild(select);
  195. selectContainer.appendChild(selectArrow);
  196.  
  197. return selectContainer;
  198. }
  199.  
  200. function createModelSwitcherContainer() {
  201. const container = document.createElement("div");
  202. container.style.cssText = `
  203. position: fixed;
  204. top: 10px;
  205. right: 18px;
  206. background-color: rgb(32, 33, 35);
  207. border: 1px solid #ddd;
  208. padding: 10px;
  209. border-radius: 5px;
  210. z-index: 9999;
  211. transition: 0.3s;
  212. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  213. display: flex;
  214. align-items: center;
  215. opacity: 0.5;
  216. `;
  217.  
  218. container.addEventListener("mouseenter", () => {
  219. container.style.opacity = "1";
  220. });
  221.  
  222. container.addEventListener("mouseleave", () => {
  223. container.style.opacity = "0.5";
  224. });
  225.  
  226. const switchElement = createSwitchElement();
  227. const modelSelectElement = createModelSelectElement();
  228.  
  229. container.appendChild(switchElement);
  230. container.appendChild(modelSelectElement);
  231.  
  232. return container;
  233. }
  234.  
  235. const container = createModelSwitcherContainer();
  236. document.body.appendChild(container);
  237.  
  238. const style = document.createElement("style");
  239. style.textContent = `
  240. .switch {
  241. position: relative;
  242. display: inline-block;
  243. width: 40px;
  244. height: 20px;
  245. margin-right: 10px;
  246. }
  247.  
  248. .switch input {
  249. opacity: 0;
  250. width: 0;
  251. height: 0;
  252. }
  253.  
  254. .slider {
  255. position: absolute;
  256. cursor: pointer;
  257. top: 0;
  258. left: 0;
  259. right: 0;
  260. bottom: 0;
  261. background-color: #ccc;
  262. transition: .5s;
  263. border-radius: 35px;
  264. }
  265.  
  266. .slider:before {
  267. position: absolute;
  268. content: "";
  269. height: 16px;
  270. width: 16px;
  271. left: 2px;
  272. bottom: 2px;
  273. background-color: white;
  274. transition: .5s;
  275. border-radius: 50%;
  276. }
  277.  
  278. input:checked + .slider {
  279. background-color: #2196F3;
  280. }
  281.  
  282. input:focus + .slider {
  283. box-shadow: 0 0 1px #2196F3;
  284. }
  285.  
  286. input:checked + .slider:before {
  287. transform: translateX(20px);
  288. }
  289.  
  290. .slider.round {
  291. border-radius: 35px;
  292. }
  293.  
  294. .slider.round:before {
  295. border-radius: 50%;
  296. }
  297.  
  298. select {
  299. color: #000000;
  300. background-color: #ffffff;
  301. padding: 5px;
  302. border: none;
  303. border-radius: 5px;
  304. appearance: none;
  305. -webkit-appearance: none;
  306. -moz-appearance: none;
  307. background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333" width="18px" height="18px"%3E%3Cpath d="M7 10l5 5 5-5z"/%3E%3Cpath d="M0 0h24v24H0z" fill="none"/%3E%3C/svg%3E');
  308. background-repeat: no-repeat;
  309. background-position: right center;
  310. padding-right: 20px;
  311. text-overflow: ellipsis;
  312. white-space: nowrap;
  313. overflow: hidden;
  314. }
  315. `;
  316.  
  317. document.head.appendChild(style);
  318. })();