Greasy Fork镜像 支持简体中文。

ChatGPT、豆包、Poe 宽屏模式

页面大于1080的屏幕撑开,显示更宽,看的更多,目前适用于Chatgpt、豆包(doubao)ai网站,后续会适配更多网站,欢迎提供网站,谢谢!

  1. // ==UserScript==
  2. // @name ChatGPT、豆包、Poe 宽屏模式
  3. // @namespace https://gf.qytechs.cn/
  4. // @version 1.2.5
  5. // @description 页面大于1080的屏幕撑开,显示更宽,看的更多,目前适用于Chatgpt、豆包(doubao)ai网站,后续会适配更多网站,欢迎提供网站,谢谢!
  6. // @author Await
  7. // @match *://chat.openai.com/
  8. // @match *://chat.openai.com/c/*
  9. // @match *://chat.openai.com/?*
  10. // @match *://poe.com/
  11. // @match *://poe.com/chat/*
  12. // @match *://www.doubao.com/chat/*
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. "use strict";
  18. const desiredMinWidth = 1280;
  19. const transitionClass = "await-transition";
  20. const transition_widthClass = "await-transition-width";
  21. const transitionEaseClass = "await-transition-ease";
  22. const maxCount = 10;
  23. const hostname = window.location.hostname;
  24. const awaits = {
  25. await_key: 0,
  26. await_MaxWidth: "90rem",
  27. await_attributeKey: "await-attribute",
  28. await_btnId: "await-btn",
  29. await_btnShowTipId: "await-show-tip",
  30. await_cacheKey: "await-cache",
  31. await_cacheOpenStateKey: "await-cache-open-state",
  32. await_cacheCloseStateKey: "await-cache-close-state",
  33. await_styleId: "await-max-width",
  34. await_cacheThemeId: "theme",
  35.  
  36. await_styleCommon: "await-max-width-common",
  37.  
  38. //doubao
  39. await_doubao_aside: "aside",
  40. await_doubao_btnClass: "smlyI",
  41. await_doubao_promptFormClass: "_1agx",
  42. await_doubao_promptShellClass: "veIiy",
  43. await_doubao_promptContentClass: "cYhYx",
  44.  
  45. //poe
  46. await_poe_aside: "aside",
  47. await_poe_menuDeleteClass: "ReactModalPortal",
  48. // "ReactModal__Overlay ReactModal__Overlay--after-open Modal_overlay__qLYU1",
  49. await_poe_formClass: "ChatMessageInputFooter_footer__1cb8J",
  50. await_poe_promptFormToIndexClass: ".ChatHomeMain_container__z8q7_",
  51. await_poe_promptFormToIndexBtnClass:
  52. ".ChatMessageInputContainer_inputContainer__SQvPA",
  53. await_poe_promptBoxClass: "MainColumn_column__z1_q8",
  54. await_poe_promptAllMsgClass:
  55. ".ChatPageMain_container__1aaCT.ChatPageMain_narrowChatPage__fWwXM",
  56. await_poe_themeDark: "dark",
  57. await_poe_themeLight: "light",
  58.  
  59. //gpt
  60. await_gpt_nav: "nav",
  61. await_gpt_navDeleteClass: "absolute",
  62. await_gpt_form: "form",
  63. await_gpt_msgClass: ".xl\\:max-w-3xl",
  64. await_gpt_msgBox: "flex flex-col text-sm dark:bg-gray-800",
  65. await_gpt_themeDark: "dark",
  66. await_gpt_themeLight: "light",
  67. await_gpt_bodyClass: "antialiased",
  68. await_gpt_inputClass: "grow",
  69. };
  70.  
  71. !(function () {
  72. //判断是来自哪个网站 0等于doubao 1等于poe 2等于gpt
  73. if (hostname.indexOf("doubao") > -1) {
  74. awaits.await_key = 0;
  75. awaits.await_MaxWidth = "100%";
  76. } else if (hostname.indexOf("poe") > -1) {
  77. awaits.await_key = 1;
  78. awaits.await_MaxWidth = "100%";
  79. } else if (hostname.indexOf("chat.openai") > -1) {
  80. awaits.await_key = 2;
  81. awaits.await_MaxWidth = "90rem";
  82. }
  83. })();
  84.  
  85. console.log("awaits", awaits, window.location);
  86. // try {
  87. // var d = document.documentElement,
  88. // c = d.classList;
  89. // c.remove("light", "dark");
  90. // var e = localStorage.getItem("theme");
  91. // if ("system" === e || (!e && true)) {
  92. // var t = "(prefers-color-scheme: dark)",
  93. // m = window.matchMedia(t);
  94. // if (m.media !== t || m.matches) {
  95. // d.style.colorScheme = "dark";
  96. // c.add("dark");
  97. // } else {
  98. // d.style.colorScheme = "light";
  99. // c.add("light");
  100. // }
  101. // } else if (e) {
  102. // c.add(e || "");
  103. // }
  104. // if (e === "light" || e === "dark") d.style.colorScheme = e;
  105. // } catch (e) {}
  106. // })();
  107.  
  108. function set_common_style_edit(e, className) {
  109. e.classList.add(className || awaits.await_styleId);
  110. }
  111. function set_common_style_remove(e, className) {
  112. e.classList.remove(className || awaits.await_styleId);
  113. }
  114.  
  115. function setCache(key, value) {
  116. localStorage.setItem(key, value);
  117. }
  118. function getCache(key) {
  119. return localStorage.getItem(key);
  120. }
  121.  
  122. function getByClass(className) {
  123. const func = function (name) {
  124. return document.getElementsByClassName(name);
  125. };
  126. return gets(func, className);
  127. }
  128.  
  129. function getQuery(name) {
  130. const func = function (names) {
  131. return document.querySelector(names);
  132. };
  133. return gets(func, name);
  134. }
  135.  
  136. function getById(id) {
  137. const func = function (ids) {
  138. return document.getElementById(ids);
  139. };
  140. return gets(func, id);
  141. }
  142.  
  143. function gets(fun, name, count = 0) {
  144. const btn = fun(name);
  145. if (!btn) {
  146. if (count > maxCount) {
  147. return null; //防止死循环
  148. }
  149. setTimeout(function () {
  150. return gets(fun, name, count + 1);
  151. }, 1000);
  152. }
  153. return btn;
  154. }
  155.  
  156. function debounce(fn, delay, immediate = false) {
  157. let timer = null;
  158. let isInvoke = false;
  159. const _debounce = function (...args) {
  160. return new Promise((resolve, reject) => {
  161. if (timer) clearTimeout(timer);
  162. if (immediate && !isInvoke) {
  163. const result = fn.apply(this, args);
  164. resolve(result);
  165. isInvoke = true;
  166. } else {
  167. timer = setTimeout(() => {
  168. const result = fn.apply(this, args);
  169. resolve(result);
  170. isInvoke = false;
  171. timer = null;
  172. }, delay);
  173. }
  174. });
  175. };
  176. _debounce.cancel = function () {
  177. if (timer) clearTimeout(timer);
  178. timer = null;
  179. isInvoke = false;
  180. };
  181. return _debounce;
  182. }
  183.  
  184. function mutationObserverRemoveNodesListener(el, className, fun) {
  185. const observer = new MutationObserver((mutations, observe) => {
  186. mutations.forEach(function (mutation) {
  187. if (!document.contains(el)) {
  188. observe.disconnect();
  189. return;
  190. }
  191. if (mutation.type === "childList") {
  192. mutation.removedNodes.forEach((node) => {
  193. if (node.className && node.className.indexOf(className) > -1) {
  194. fun.apply(this);
  195. }
  196. });
  197. }
  198. });
  199. });
  200. observer.observe(document.body, {
  201. // attributes: true,
  202. childList: true,
  203. });
  204. }
  205.  
  206. function set_style_remove(el, className, isTran = true) {
  207. if (isTran && !el.classList.contains(transitionClass)) {
  208. el.classList.add(transitionClass);
  209. }
  210. // el.style.transition = "max-width 1s";
  211. // setTimeout(function () {
  212. // el.style.transition = "";
  213. // }, 1000);
  214. switch (awaits.await_key) {
  215. case 0:
  216. case 1:
  217. case 2:
  218. set_common_style_remove(el, className);
  219. break;
  220. default:
  221. break;
  222. }
  223. }
  224.  
  225. function set_style_edit(el, className, isTran = true) {
  226. if (isTran && !el.classList.contains(transitionClass)) {
  227. el.classList.add(transitionClass);
  228. }
  229. // setTimeout(() => {
  230. // el.classList.remove(transitionClass);
  231. // }, 1000);
  232. switch (awaits.await_key) {
  233. case 0:
  234. case 1:
  235. case 2:
  236. set_common_style_edit(el, className);
  237. break;
  238. default:
  239. break;
  240. }
  241. }
  242.  
  243. function set_style() {
  244. const style = document.createElement("style");
  245. style.innerHTML = `
  246. .${awaits.await_styleCommon} {width: ${awaits.await_MaxWidth} !important;}
  247. .${awaits.await_styleId} {max-width: ${awaits.await_MaxWidth} !important;}
  248. .${transitionClass}{transition: max-width 1s ease-in-out !important;}
  249. .${transition_widthClass}{transition: width 1s ease-in-out !important;}
  250. .${transitionEaseClass}{transition: width 0.5s ease-in-out;}
  251. .${transitionEaseClass}.active {transition: width 0.5s ease-in-out;}
  252. `;
  253. document.head.appendChild(style);
  254. }
  255.  
  256. function set_body_see_toKey() {
  257. switch (awaits.await_key) {
  258. case 0:
  259. break;
  260. case 1:
  261. break;
  262. case 2:
  263. // set_gpt_body_s();
  264. break;
  265. default:
  266. break;
  267. }
  268. }
  269.  
  270. function set_btn_add(tt = false, count = 0) {
  271. const promptTextarea = get_btn_toKey(awaits.await_key);
  272. if (!promptTextarea) {
  273. if (!tt) {
  274. return;
  275. } else {
  276. if (count > maxCount) {
  277. return;
  278. }
  279. setTimeout(function () {
  280. set_btn_add(tt, count + 1);
  281. }, 1000);
  282. return;
  283. }
  284. }
  285. if (tt && promptTextarea.hasAttribute(awaits.await_attributeKey)) {
  286. setTimeout(() => {
  287. set_btn_add(tt, count + 1);
  288. }, 100);
  289. return;
  290. }
  291. if (!promptTextarea.hasAttribute(awaits.await_attributeKey)) {
  292. //判断promptTextarea中的属性
  293. get_btn_prompt_toKey(promptTextarea);
  294. set_btn_promptContent_toKey();
  295. set_theme_toKey();
  296. run_info();
  297. promptTextarea.setAttribute(awaits.await_attributeKey, true);
  298. }
  299. }
  300.  
  301. function get_btn_toKey(key) {
  302. if (key === 0) {
  303. return getByClass(awaits.await_doubao_btnClass)[0];
  304. } else if (key === 1) {
  305. return getQuery("." + awaits.await_poe_formClass);
  306. } else if (key === 2) {
  307. return getQuery(`.${awaits.await_gpt_inputClass}:not([class*=' '])`);
  308. }
  309. }
  310.  
  311. function get_btn_prompt_toKey(e, isFirst = false) {
  312. switch (awaits.await_key) {
  313. case 0:
  314. if (!getById(awaits.await_btnId)) {
  315. e.insertAdjacentHTML(
  316. "afterbegin",
  317. `<button id="${awaits.await_btnId}"
  318. class="semi-button semi-button-primary semi-button-light
  319. semi-button-with-icon semi-button-with-icon-only"
  320. type="button"
  321. </button>`
  322. );
  323. }
  324. break;
  325. case 1:
  326. if (!getById(awaits.await_btnId)) {
  327. e.insertAdjacentHTML(
  328. isFirst == true ? "afterbegin" : "beforeend",
  329. `<button id="${awaits.await_btnId}" style="margin-left:unset"
  330. class="Button_buttonBase__0QP_m Button_flat__1hj0f
  331. ChatBreakButton_button__EihE0
  332. ChatMessageInputFooter_chatBreakButton__hqJ3v"</button> `
  333. );
  334. }
  335. if (!getById(awaits.await_btnId + "-" + awaits.await_cacheThemeId)) {
  336. e.insertAdjacentHTML(
  337. isFirst == true ? "afterbegin" : "beforeend",
  338. `<button id="${awaits.await_btnId}-${awaits.await_cacheThemeId}"
  339. style="margin-left:unset" class="Button_buttonBase__0QP_m
  340. Button_flat__1hj0f ChatBreakButton_button__EihE0
  341. ChatMessageInputFooter_chatBreakButton__hqJ3v"</button> `
  342. );
  343. }
  344. break;
  345. case 2:
  346. if (!getById(awaits.await_btnId + "-" + awaits.await_cacheThemeId)) {
  347. e.insertAdjacentHTML(
  348. "afterend",
  349. // `<div class="flex items-center md:items-end"><div style="opacity: 1;"><button id="${await_btnId}" class="btn relative whitespace-nowrap -z-0 border-0 md:border ${await_btnId}"></button> </div></div>`
  350. `<div class="flex items-center md:items-end">
  351. <div style="opacity: 1;">
  352. <button id="${awaits.await_btnId}-${awaits.await_cacheThemeId}"
  353. as="button" class="btn btn-neutral whitespace-nowrap -z-0 ">
  354. </button>
  355. </div>
  356. </div>`
  357. );
  358. }
  359. if (!getById(awaits.await_btnId)) {
  360. e.insertAdjacentHTML(
  361. "afterend",
  362. // `<div class="flex items-center md:items-end"><div style="opacity: 1;"><button id="${await_btnId}" class="btn relative whitespace-nowrap -z-0 border-0 md:border ${await_btnId}"></button> </div></div>`
  363. `<div class="flex items-center md:items-end">
  364. <div style="opacity: 1;">
  365. <button id="${awaits.await_btnId}" as="button"
  366. class="text-gray-600 dark:text-gray-200 btn btn-neutral
  367. whitespace-nowrap -z-0 "></button>
  368. </div>
  369. </div>`
  370. );
  371. }
  372. break;
  373. default:
  374. break;
  375. }
  376. }
  377.  
  378. function set_btn_promptContent_toKey(type = 0) {
  379. switch (awaits.await_key) {
  380. case 0:
  381. set_doubao_btn_msgEdit();
  382. break;
  383. case 1:
  384. if (type === 1) return set_poe_btn_msgEdit(false);
  385. else set_poe_btn_msgEdit();
  386. break;
  387. case 2:
  388. set_gpt_btn_msgEdit();
  389. break;
  390. default:
  391. break;
  392. }
  393. }
  394.  
  395. function set_theme_toKey() {
  396. switch (awaits.await_key) {
  397. case 1:
  398. set_poe_theme_add();
  399. break;
  400. case 2:
  401. set_gpt_theme_add();
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407.  
  408. function set_btn_prompt_edit(el) {
  409. if (el && !el.hasAttribute(awaits.await_attributeKey)) {
  410. el.addEventListener("click", function () {
  411. setCache(
  412. awaits.await_cacheKey,
  413. getCache(awaits.await_cacheKey) === awaits.await_cacheOpenStateKey
  414. ? awaits.await_cacheCloseStateKey
  415. : awaits.await_cacheOpenStateKey
  416. );
  417. run_info(true);
  418. set_btn_promptContent_toKey();
  419. });
  420. el.setAttribute(awaits.await_attributeKey, true);
  421. }
  422. }
  423.  
  424. function set_cache_add() {
  425. const cache = getCache(awaits.await_cacheKey);
  426. if (!cache) {
  427. setCache(awaits.await_cacheKey, true);
  428. }
  429. }
  430.  
  431. function setStyle(cache, el, className = "", isTran = true) {
  432. if (cache === awaits.await_cacheOpenStateKey) {
  433. set_style_edit(el, className, isTran);
  434. } else {
  435. set_style_remove(el, className, isTran);
  436. }
  437. }
  438.  
  439. function set_tip_show() {
  440. switch (awaits.await_key) {
  441. case 0:
  442. break;
  443. case 1:
  444. break;
  445. case 2:
  446. set_gpt_show();
  447. break;
  448. default:
  449. break;
  450. }
  451. }
  452.  
  453. function set_nav_click() {
  454. switch (awaits.await_key) {
  455. case 0:
  456. set_doubao_nav_click(true);
  457. break;
  458. case 1:
  459. set_poe_nav_click(true);
  460. break;
  461. case 2:
  462. set_gpt_nav_click(true);
  463. break;
  464. default:
  465. break;
  466. }
  467. }
  468.  
  469. function get_form_toKey(operation) {
  470. switch (awaits.await_key) {
  471. case 0:
  472. set_doubao_form(operation);
  473. set_doubao_content();
  474. break;
  475. case 1:
  476. // if (!operation) return;
  477. set_poe_promptBox(operation);
  478. break;
  479. case 2:
  480. get_gpt_form();
  481. set_gpt_form_content();
  482. break;
  483. default:
  484. break;
  485. }
  486. }
  487.  
  488. //#region poe
  489.  
  490. function set_poe_nav_click(tt = false, count = 0) {
  491. const toggleButton = getQuery(awaits.await_poe_aside);
  492. if (!toggleButton) {
  493. if (!tt) return;
  494. else {
  495. if (count > maxCount) {
  496. return;
  497. }
  498. setTimeout(function () {
  499. set_poe_nav_click(tt, count + 1);
  500. }, 1000);
  501. return;
  502. }
  503. }
  504. if (tt && toggleButton.hasAttribute(awaits.await_attributeKey)) {
  505. setTimeout(function () {
  506. set_poe_nav_click(tt, count + 1);
  507. }, 1000);
  508. return;
  509. }
  510. if (!toggleButton.hasAttribute(awaits.await_attributeKey)) {
  511. const debounceMenu = debounce(
  512. () => {
  513. //判断是否主页面
  514. if (window.location.pathname.length < 2) {
  515. set_poe_promptIndex();
  516. } else {
  517. run_all(true);
  518. run_info(true);
  519. }
  520. },
  521. 1000,
  522. false
  523. );
  524. mutationObserverRemoveNodesListener(
  525. toggleButton,
  526. awaits.await_poe_menuDeleteClass,
  527. debounceMenu
  528. );
  529. // toggleButton.addEventListener("click", function () {
  530. // setTimeout(function () {
  531. // run_all(true);
  532. if (window.location.pathname.length < 2) {
  533. setTimeout(() => {
  534. set_poe_promptIndex();
  535. }, 800);
  536. }
  537. run_info(true);
  538. // }, 1000);
  539. // });
  540. toggleButton.setAttribute(awaits.await_attributeKey, true);
  541. }
  542. }
  543.  
  544. function set_poe_promptIndex(count = 0) {
  545. const promptTextarea = getQuery("." + awaits.await_poe_promptBoxClass);
  546. if (!promptTextarea) {
  547. if (count > maxCount) {
  548. return;
  549. }
  550. setTimeout(function () {
  551. set_poe_promptIndex(count + 1);
  552. }, 1000);
  553. return;
  554. }
  555. if (promptTextarea) count = 0;
  556. const boxContent = getQuery(awaits.await_poe_promptFormToIndexClass);
  557. if (!boxContent) {
  558. if (count > maxCount) {
  559. return;
  560. }
  561. setTimeout(function () {
  562. set_poe_promptIndex(count + 1);
  563. }, 1000);
  564. return;
  565. }
  566. if (boxContent) count = 0;
  567. const boxBtn = getQuery(awaits.await_poe_promptFormToIndexBtnClass);
  568. if (!boxBtn) {
  569. if (count > maxCount) {
  570. return;
  571. }
  572. setTimeout(function () {
  573. set_poe_promptIndex(count + 1);
  574. }, 1000);
  575. return;
  576. }
  577. if (boxContent && promptTextarea && boxBtn) {
  578. const cache = getCache(awaits.await_cacheKey);
  579. if (!promptTextarea.classList.contains(transition_widthClass)) {
  580. promptTextarea.classList.add(transition_widthClass);
  581. }
  582. debounce(
  583. () => {
  584. promptTextarea.style.width =
  585. cache === awaits.await_cacheOpenStateKey ? "85%" : "";
  586. },
  587. 100,
  588. false
  589. )();
  590. get_btn_prompt_toKey(boxBtn, true);
  591. const btn = set_btn_promptContent_toKey(1);
  592. set_theme_toKey();
  593. if (btn && !btn.hasAttribute(awaits.await_attributeKey)) {
  594. btn.addEventListener("click", function () {
  595. setCache(
  596. awaits.await_cacheKey,
  597. getCache(awaits.await_cacheKey) === awaits.await_cacheOpenStateKey
  598. ? awaits.await_cacheCloseStateKey
  599. : awaits.await_cacheOpenStateKey
  600. );
  601. set_poe_promptIndex();
  602. });
  603. btn.setAttribute(awaits.await_attributeKey, true);
  604. }
  605. }
  606. }
  607.  
  608. function set_poe_theme_add() {
  609. const cache = getCache(awaits.await_cacheThemeId);
  610. const el = getById(awaits.await_btnId + "-" + awaits.await_cacheThemeId);
  611. if (!el) return;
  612. el.innerHTML = "";
  613. if (cache !== awaits.await_gpt_themeLight) {
  614. el.insertAdjacentHTML(
  615. "afterbegin",
  616. `<span id="${awaits.await_btnId}-${awaits.await_poe_themeDark}"
  617. >🌞</span>`
  618. );
  619. } else {
  620. el.insertAdjacentHTML(
  621. "afterbegin",
  622. `<span id="${awaits.await_btnId}-${awaits.await_poe_themeLight}"
  623. >🌙</span>`
  624. );
  625. }
  626. set_gpt_textInformation_s(el);
  627. set_gpt_textInformation_s(
  628. getById(
  629. awaits.await_btnId + "-" + cache === awaits.await_poe_themeDark
  630. ? awaits.await_poe_themeDark
  631. : awaits.await_poe_themeLight
  632. )
  633. );
  634. }
  635.  
  636. function set_poe_btn_msgEdit(isAdd = true) {
  637. const cache2 = getCache(awaits.await_cacheKey);
  638. const btn = getById(awaits.await_btnId);
  639. btn.innerHTML = "";
  640. if (cache2 === awaits.await_cacheOpenStateKey) {
  641. btn.insertAdjacentHTML(
  642. "afterbegin",
  643. `<span class="${transitionEaseClass}">📘</span>`
  644. );
  645. } else {
  646. btn.insertAdjacentHTML(
  647. "afterbegin",
  648. `<span class="${transitionEaseClass}">📖</span>`
  649. );
  650. }
  651. if (isAdd) {
  652. set_btn_prompt_edit(btn);
  653. }
  654. return btn;
  655. }
  656.  
  657. function set_poe_promptBox(tt = false, count = 0) {
  658. const box = getQuery("." + awaits.await_poe_promptBoxClass);
  659. if (!box) {
  660. if (!tt) return;
  661. else {
  662. if (count > maxCount) {
  663. return;
  664. }
  665. setTimeout(function () {
  666. set_poe_promptBox(tt, count + 1);
  667. }, 1000);
  668. return;
  669. }
  670. }
  671. if (box) count = 0;
  672. const boxContent = getQuery(awaits.await_poe_promptAllMsgClass);
  673. if (!boxContent) {
  674. if (!tt) return;
  675. else {
  676. if (count > maxCount) {
  677. return;
  678. }
  679. setTimeout(function () {
  680. set_poe_promptBox(tt, count + 1);
  681. }, 1000);
  682. return;
  683. }
  684. }
  685. if (boxContent && box) {
  686. const cache = getCache(awaits.await_cacheKey);
  687. setStyle(cache, boxContent);
  688. debounce(
  689. () => {
  690. if (!box.classList.contains(transition_widthClass)) {
  691. box.classList.add(transition_widthClass);
  692. }
  693. setStyle(cache, box, awaits.await_styleCommon);
  694. },
  695. 200,
  696. false
  697. )();
  698. }
  699. }
  700.  
  701. //#endregion
  702.  
  703. //#region doubao
  704.  
  705. function set_doubao_form(operation = false) {
  706. var elementForm = getByClass(awaits.await_doubao_promptFormClass)[0];
  707. if (!elementForm) {
  708. setTimeout(function () {
  709. set_doubao_form(operation);
  710. }, 1000);
  711. return;
  712. }
  713. if (!elementForm.hasAttribute(awaits.await_attributeKey) || operation) {
  714. const cache = getCache(awaits.await_cacheKey);
  715. setStyle(cache, elementForm);
  716. elementForm.setAttribute(awaits.await_attributeKey, true);
  717. }
  718. }
  719.  
  720. function set_doubao_content() {
  721. var elementForm = getByClass(awaits.await_doubao_promptShellClass)[0];
  722. if (!elementForm || elementForm.length === 0) {
  723. setTimeout(function () {
  724. set_doubao_content();
  725. }, 1000);
  726. return;
  727. }
  728. if (elementForm.hasAttribute(awaits.await_attributeKey)) {
  729. return;
  730. }
  731. const cache = getCache(awaits.await_cacheKey);
  732. setStyle(cache, elementForm);
  733. elementForm
  734. .querySelectorAll("." + awaits.await_doubao_promptContentClass)
  735. .forEach(function (flexDiv) {
  736. setStyle(cache, flexDiv);
  737. });
  738.  
  739. var observer = new MutationObserver((mutations) => {
  740. mutations.forEach(function (mutation) {
  741. if (!document.contains(elementForm)) {
  742. observer.disconnect();
  743. return;
  744. }
  745. mutation.addedNodes.forEach((addedNode) => {
  746. if (addedNode instanceof Document || addedNode instanceof Element) {
  747. addedNode
  748. .querySelectorAll("." + awaits.await_doubao_promptContentClass)
  749. .forEach(function (node) {
  750. setStyle(cache, node);
  751. });
  752. }
  753. });
  754. });
  755. });
  756. var config = { childList: true, subtree: true };
  757. observer.observe(document.body, config);
  758. }
  759.  
  760. function set_doubao_btn_msgEdit() {
  761. const cache2 = getCache(awaits.await_cacheKey);
  762. const btn = getById(awaits.await_btnId);
  763. btn.innerHTML = "";
  764. if (cache2 === awaits.await_cacheOpenStateKey) {
  765. btn.insertAdjacentHTML(
  766. "afterbegin",
  767. `<span class="${transitionEaseClass} semi-button-content">
  768. 📘
  769. </span>`
  770. );
  771. } else {
  772. btn.insertAdjacentHTML(
  773. "afterbegin",
  774. `<span class="${transitionEaseClass} semi-button-content">
  775. 📖
  776. </span>`
  777. );
  778. }
  779. set_btn_prompt_edit(btn);
  780. }
  781.  
  782. function set_doubao_nav_click(tt = false, count = 0) {
  783. const toggleButton = getQuery(awaits.await_doubao_aside);
  784. if (!toggleButton) {
  785. if (!tt) return;
  786. else {
  787. if (count > maxCount) {
  788. return;
  789. }
  790. setTimeout(function () {
  791. set_doubao_nav_click(tt, count + 1);
  792. }, 1000);
  793. return;
  794. }
  795. }
  796. if (tt && toggleButton.hasAttribute(awaits.await_attributeKey)) {
  797. setTimeout(function () {
  798. set_doubao_nav_click(tt, count + 1);
  799. }, 1000);
  800. return;
  801. }
  802. if (!toggleButton.hasAttribute(awaits.await_attributeKey)) {
  803. toggleButton.addEventListener("click", function () {
  804. setTimeout(function () {
  805. run_all();
  806. run_info();
  807. }, 1000);
  808. });
  809. toggleButton.setAttribute(awaits.await_attributeKey, true);
  810. }
  811. }
  812.  
  813. //#endregion
  814.  
  815. //#region gpt
  816.  
  817. function get_gpt_form() {
  818. var elementForm = getQuery(awaits.await_gpt_form);
  819. if (!elementForm || elementForm.length === 0) {
  820. setTimeout(function () {
  821. get_gpt_form();
  822. }, 1000);
  823. return;
  824. }
  825. const cache = getCache(awaits.await_cacheKey);
  826. if (elementForm.className.indexOf("xl:max-w-3xl") > -1) {
  827. setStyle(cache, elementForm);
  828. }
  829. }
  830.  
  831. function set_gpt_form_content() {
  832. var parentElement = document.getElementsByClassName(
  833. awaits.await_gpt_msgBox
  834. )[0];
  835. if (!parentElement) {
  836. setTimeout(function () {
  837. set_gpt_form_content();
  838. }, 1000);
  839. return;
  840. }
  841. const cache = getCache(awaits.await_cacheKey);
  842. parentElement
  843. .querySelectorAll(awaits.await_gpt_msgClass)
  844. .forEach(function (flexDiv) {
  845. setStyle(cache, flexDiv);
  846. });
  847. var observer = new MutationObserver((mutations) => {
  848. mutations.forEach(function (mutation) {
  849. if (!document.contains(parentElement)) {
  850. observer.disconnect();
  851. return;
  852. }
  853. mutation.addedNodes.forEach(function (addedNode) {
  854. if (addedNode instanceof Document || addedNode instanceof Element) {
  855. var flexDivList = addedNode.querySelectorAll(
  856. awaits.await_gpt_msgClass
  857. );
  858. flexDivList.forEach(function (flexDiv) {
  859. setStyle(cache, flexDiv);
  860. });
  861. }
  862. });
  863. });
  864. });
  865. var config = { childList: true, subtree: true };
  866. observer.observe(document.body, config);
  867. }
  868. function set_gpt_theme_add() {
  869. const cache = getCache(awaits.await_cacheThemeId);
  870. const el = getById(awaits.await_btnId + "-" + awaits.await_cacheThemeId);
  871. if (!el) return;
  872. el.innerHTML = "";
  873. if (cache !== awaits.await_gpt_themeLight) {
  874. el.insertAdjacentHTML(
  875. "afterbegin",
  876. `<div id="${awaits.await_btnId}-${awaits.await_gpt_themeDark}"
  877. class="flex w-full gap-2 items-center justify-center">🌞</div>`
  878. );
  879. } else {
  880. el.insertAdjacentHTML(
  881. "afterbegin",
  882. `<div id="${awaits.await_btnId}-${awaits.await_gpt_themeLight}"
  883. class="flex w-full gap-2 items-center justify-center">🌙</div>`
  884. );
  885. }
  886. set_gpt_textInformation_s(el);
  887. set_gpt_textInformation_s(
  888. getById(
  889. awaits.await_btnId + "-" + cache === awaits.await_gpt_themeDark
  890. ? awaits.await_gpt_themeDark
  891. : awaits.await_gpt_themeLight
  892. )
  893. );
  894. }
  895.  
  896. function set_gpt_btn_msgEdit() {
  897. const cache2 = getCache(awaits.await_cacheKey);
  898. const btn = getById(awaits.await_btnId);
  899. btn.innerHTML = "";
  900. if (cache2 === awaits.await_cacheOpenStateKey) {
  901. btn.insertAdjacentHTML(
  902. "afterbegin",
  903. // `<div id="${awaits.await_btnId}-open"
  904. `<div class="${transitionEaseClass} flex w-full gap-2 items-center justify-center">📘</div>`
  905. // `<div class="flex w-full gap-2 items-center justify-center">
  906. // <svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
  907. // <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><line x1="9" y1="3" x2="9" y2="21"></line>
  908. // </svg>📘</div>`
  909. );
  910. } else {
  911. btn.insertAdjacentHTML(
  912. "afterbegin",
  913. // `<div id="${awaits.await_btnId}-open"
  914. `<div class="${transitionEaseClass} flex w-full gap-2 items-center justify-center">📖</div>`
  915. // `<div class="flex w-full gap-2 items-center justify-center">
  916. // <svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
  917. // <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><line x1="9" y1="3" x2="9" y2="21"></line>
  918. // </svg>📖</div>`
  919. );
  920. }
  921. set_btn_prompt_edit(btn);
  922. }
  923. function set_gpt_textInformation_s(el) {
  924. if (el && !el.hasAttribute(awaits.await_attributeKey)) {
  925. el.addEventListener("click", function () {
  926. const cache = getCache(awaits.await_cacheThemeId);
  927. //修改html中的style跟class
  928. const html = getQuery("html");
  929. const currentTheme =
  930. cache !== awaits.await_gpt_themeLight
  931. ? awaits.await_gpt_themeLight
  932. : awaits.await_gpt_themeDark;
  933. html.className = "";
  934. html.className = currentTheme;
  935. html.style.colorScheme = currentTheme;
  936. setCache(awaits.await_cacheThemeId, currentTheme);
  937. set_gpt_theme_add();
  938. });
  939. el.setAttribute(awaits.await_attributeKey, true);
  940. }
  941. }
  942.  
  943. function set_gpt_body_s() {
  944. const body = getQuery("." + awaits.await_gpt_bodyClass);
  945. if (!body) {
  946. return;
  947. }
  948. const observer = new MutationObserver((mutationsList, observer) => {
  949. for (const mutation of mutationsList) {
  950. if (
  951. mutation.type === "attributes" &&
  952. mutation.attributeName === "style"
  953. ) {
  954. const newStyle = body.getAttribute("style");
  955. if (!newStyle) {
  956. // set_btn_add(true);
  957. }
  958. }
  959. }
  960. });
  961. const config = { attributes: true, attributeFilter: ["style"] };
  962. observer.observe(body, config);
  963. }
  964.  
  965. function set_gpt_show() {
  966. const toggleButton = getQuery(awaits.await_gpt_nav);
  967. if (!toggleButton) {
  968. return;
  969. }
  970. toggleButton.insertAdjacentHTML(
  971. "beforeend",
  972. `<div id="${awaits.await_btnShowTipId}" style="position:fixed;top:3rem;left:15rem;z-index:9999;background-color:rgba(0,0,0,0.5);color:#fff;padding:10px;border-radius:5px;">如果页面宽度未展开,请重新点击此树结构导航栏<br>或者直接<span style="color:red">点击我</span><br>提示内容十秒后自动消失</div>`
  973. );
  974. const btn = getById(awaits.await_btnShowTipId);
  975. if (!btn.hasAttribute(awaits.await_attributeKey)) {
  976. btn.addEventListener("click", function () {
  977. run_all();
  978. });
  979. setTimeout(function () {
  980. btn.remove();
  981. }, 10000);
  982. btn.setAttribute(awaits.await_attributeKey, true);
  983. }
  984. }
  985. function set_gpt_nav_click(operation = false, count = 0) {
  986. const toggleButton = getQuery(awaits.await_gpt_nav);
  987. if (!toggleButton) {
  988. if (!operation) {
  989. return;
  990. } else {
  991. if (count > maxCount) {
  992. return;
  993. }
  994. setTimeout(function () {
  995. set_gpt_nav_click(operation, count + 1);
  996. }, 1000);
  997. return;
  998. }
  999. }
  1000. if (operation && toggleButton.hasAttribute(awaits.await_attributeKey)) {
  1001. setTimeout(() => {
  1002. set_gpt_nav_click(operation, count + 1);
  1003. }, 100);
  1004. return;
  1005. }
  1006. if (!toggleButton.hasAttribute(awaits.await_attributeKey)) {
  1007. mutationObserverRemoveNodesListener(
  1008. toggleButton,
  1009. awaits.await_gpt_navDeleteClass,
  1010. () => {
  1011. run_all(true);
  1012. set_gpt_nav_click(true);
  1013. }
  1014. );
  1015. toggleButton.addEventListener("click", function () {
  1016. setTimeout(function () {
  1017. run_all(true);
  1018. set_gpt_nav_click(true);
  1019. }, 1000);
  1020. });
  1021. toggleButton.setAttribute(awaits.await_attributeKey, true);
  1022. }
  1023. }
  1024.  
  1025. //#endregion
  1026.  
  1027. function run_all(operation) {
  1028. set_btn_add(operation);
  1029. set_theme_toKey();
  1030. }
  1031. function run_info(operation) {
  1032. get_form_toKey(operation);
  1033. }
  1034. window.addEventListener("resize", run_all);
  1035. window.onload = function () {
  1036. if (window.innerWidth < desiredMinWidth) {
  1037. console.log("页面宽度小于1280,不执行脚本");
  1038. return;
  1039. }
  1040. set_cache_add();
  1041. set_style();
  1042. // set_tip_show();
  1043. set_nav_click();
  1044. // set_body_see_toKey();
  1045. setTimeout(function () {
  1046. run_all();
  1047. }, 2000);
  1048. };
  1049. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址