ChatGPT is GPT4 by default(PLUS only available)

ChatGPT switch The default is GPT4

目前為 2023-04-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                 ChatGPT is GPT4 by default(PLUS only available)
// @name:zh-CN           ChatGPT默认为GPT4(仅PLUS可用)
// @description          ChatGPT switch The default is GPT4
// @description:zh-cn   ChatGPT switch The default is GPT4
// @version             0.1.1
// @icon               https://chat.openai.com/favicon.ico
// @match              https://chat.openai.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @namespace https://greasyfork.org/zh-CN/scripts/464284-chatgpt-is-gpt4-by-default-plus-only-available
// @license MIT
// ==/UserScript==

(function () {
  'use strict';
  const BUTTONS_GROUPS = ['Default (GPT-3.5)', 'Legacy (GPT-3.5)', 'GPT-4']
  let menus = []

  const getOtherInfo = () => {
    const defaultValue = GM_getValue('defaultModel')
    return BUTTONS_GROUPS.filter((buttonText) => buttonText !== defaultValue).map((buttonText) => `Model${buttonText}`);
  }

  // 注册脚本菜单
  const registerMenuCommand = () => {
    const onHandle = (value) => {
      GM_setValue('defaultModel', value)
      registerMenuCommand()
    }
    if (!GM_getValue('defaultModel')) GM_setValue('defaultModel', 'GPT-4')
    const defaultValue = GM_getValue('defaultModel')
    menus.forEach(menu => GM_unregisterMenuCommand(menu))
    menus = BUTTONS_GROUPS.map((buttonText) => GM_registerMenuCommand(`切换默认为:${buttonText}${defaultValue === buttonText ? '(当前)' : ''}`, () => onHandle(buttonText)))
  }

  const clickListItemByTextContent = (textContent) => {
    const listItems = document.getElementsByTagName('li');
    for (let listItem of listItems) {
      if (listItem.textContent === textContent) {
        listItem.click();
        return;
      }
    }
  };

  const switchModel = () => {
    const model = `${GM_getValue('defaultModel')}`
    setTimeout(() => clickListItemByTextContent(model), 0);
  };

  const callback = (mutationRecords) => {
    const BUTTON_INFOS = getOtherInfo();
    for (const mutationRecord of mutationRecords) {
      if (mutationRecord.addedNodes.length) {
        for (const addedNode of mutationRecord.addedNodes) {
          if (addedNode.nodeType === Node.ELEMENT_NODE) {
            const buttons = addedNode.querySelectorAll('button');
            for (let button of buttons) {
              if (BUTTON_INFOS.includes(button.textContent)) {
                button.click();
                switchModel();
                return;
              }
            }
          }
        }
      }
    }
  };
  registerMenuCommand()
  const observer = new MutationObserver(callback);
  observer.observe(document.getElementById('__next'), {
    childList: true,
    subtree: true,
  });
})();