ChatGPT默认为GPT4(仅PLUS可用)

ChatGPT switch The default is GPT4

当前为 2023-04-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT is GPT4 by default(PLUS only available)
  3. // @name:zh-CN ChatGPT默认为GPT4(仅PLUS可用)
  4. // @description ChatGPT switch The default is GPT4
  5. // @description:zh-cn ChatGPT switch The default is GPT4
  6. // @version 0.1.1
  7. // @icon https://chat.openai.com/favicon.ico
  8. // @match https://chat.openai.com/*
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_unregisterMenuCommand
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @namespace https://greasyfork.org/zh-CN/scripts/464284-chatgpt-is-gpt4-by-default-plus-only-available
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19. const BUTTONS_GROUPS = ['Default (GPT-3.5)', 'Legacy (GPT-3.5)', 'GPT-4']
  20. let menus = []
  21.  
  22. const getOtherInfo = () => {
  23. const defaultValue = GM_getValue('defaultModel')
  24. return BUTTONS_GROUPS.filter((buttonText) => buttonText !== defaultValue).map((buttonText) => `Model${buttonText}`);
  25. }
  26.  
  27. // 注册脚本菜单
  28. const registerMenuCommand = () => {
  29. const onHandle = (value) => {
  30. GM_setValue('defaultModel', value)
  31. registerMenuCommand()
  32. }
  33. if (!GM_getValue('defaultModel')) GM_setValue('defaultModel', 'GPT-4')
  34. const defaultValue = GM_getValue('defaultModel')
  35. menus.forEach(menu => GM_unregisterMenuCommand(menu))
  36. menus = BUTTONS_GROUPS.map((buttonText) => GM_registerMenuCommand(`切换默认为:${buttonText}${defaultValue === buttonText ? '(当前)' : ''}`, () => onHandle(buttonText)))
  37. }
  38.  
  39. const clickListItemByTextContent = (textContent) => {
  40. const listItems = document.getElementsByTagName('li');
  41. for (let listItem of listItems) {
  42. if (listItem.textContent === textContent) {
  43. listItem.click();
  44. return;
  45. }
  46. }
  47. };
  48.  
  49. const switchModel = () => {
  50. const model = `${GM_getValue('defaultModel')}`
  51. setTimeout(() => clickListItemByTextContent(model), 0);
  52. };
  53.  
  54. const callback = (mutationRecords) => {
  55. const BUTTON_INFOS = getOtherInfo();
  56. for (const mutationRecord of mutationRecords) {
  57. if (mutationRecord.addedNodes.length) {
  58. for (const addedNode of mutationRecord.addedNodes) {
  59. if (addedNode.nodeType === Node.ELEMENT_NODE) {
  60. const buttons = addedNode.querySelectorAll('button');
  61. for (let button of buttons) {
  62. if (BUTTON_INFOS.includes(button.textContent)) {
  63. button.click();
  64. switchModel();
  65. return;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. };
  73. registerMenuCommand()
  74. const observer = new MutationObserver(callback);
  75. observer.observe(document.getElementById('__next'), {
  76. childList: true,
  77. subtree: true,
  78. });
  79. })();