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.0
  7. // @icon https://chat.openai.com/favicon.ico
  8. // @match https://chat.openai.com/*
  9. // @namespace https://greasyfork.org/zh-CN/scripts/464284-chatgpt-is-gpt4-by-default-plus-only-available
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. const BUTTONS_GROUPS = ['Default (GPT-3.5)', 'Legacy (GPT-3.5)', 'GPT-4']
  16. const DEFAULT_MODEL = 'GPT-4';
  17. const BUTTON_INFOS = BUTTONS_GROUPS.filter((buttonText) => buttonText !== DEFAULT_MODEL).map((buttonText) => `Model${buttonText}`);
  18.  
  19. const clickListItemByTextContent = (textContent) => {
  20. const listItems = document.getElementsByTagName('li');
  21. for (let listItem of listItems) {
  22. if (listItem.textContent === textContent) {
  23. listItem.click();
  24. return;
  25. }
  26. }
  27. };
  28.  
  29. const switchModel = (model = DEFAULT_MODEL) => {
  30. setTimeout(() => clickListItemByTextContent(model), 0);
  31. };
  32.  
  33. const callback = (mutationRecords) => {
  34. for (const mutationRecord of mutationRecords) {
  35. if (mutationRecord.addedNodes.length) {
  36. for (const addedNode of mutationRecord.addedNodes) {
  37. if (addedNode.nodeType === Node.ELEMENT_NODE) {
  38. const buttons = addedNode.querySelectorAll('button');
  39. for (let button of buttons) {
  40. if (BUTTON_INFOS.includes(button.textContent)) {
  41. button.click();
  42. switchModel();
  43. return;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. };
  51.  
  52. const observer = new MutationObserver(callback);
  53. observer.observe(document.getElementById('__next'), {
  54. childList: true,
  55. subtree: true,
  56. });
  57. })();