Style for Coze Bot App mode

Make Coze Bot looks better!

  1. // ==UserScript==
  2. // @name Style for Coze Bot App mode
  3. // @namespace https://www.velhlkj.com/
  4. // @version 1.1.5
  5. // @description Make Coze Bot looks better!
  6. // @author Velade
  7. // @match https://www.coze.com/store/bot/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @run-at document-body
  11. // @license Apache 2.0
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const style = document.createElement('style');
  18. style.textContent = `
  19. /*官方阴影*/
  20. .ULoOs2TMkJkb2BgT_MKa {
  21. display: none !important;
  22. }
  23. /*新对话按钮*/
  24. .NyvVfPwFXFYvQFyXUtTl {
  25. padding-left: 0 !important;
  26. }
  27. /*标题列*/
  28. .nZxnu8KzOis7qKnDx66E {
  29. position: fixed !important;
  30. top: 5px !important;
  31. right: 5px !important;
  32. width: 80px !important;
  33. height: 40px !important;
  34. filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.5)) !important;
  35. }
  36.  
  37. .nZxnu8KzOis7qKnDx66E > div:first-child {
  38. display: none !important;
  39. }
  40.  
  41. .nZxnu8KzOis7qKnDx66E > div:nth-child(2) > div:nth-child(2){
  42. display: none !important;
  43. }
  44. /*对话区域主体*/
  45. .O4fwdEnt3QgzBjrYtohO {
  46. -webkit-mask: linear-gradient(180deg,hsla(0,0%,100%,0) 5px, #fff calc(8.11% + 5px), #fff 91.89%, hsla(0,0%,100%,0)) !important;
  47. mask: linear-gradient(180deg,hsla(0,0%,100%,0) 5px, #fff calc(8.11% + 5px), #fff 91.89%, hsla(0,0%,100%,0)) !important;
  48. }
  49. /*底部声明:改为导航栏占位*/
  50. .pStAbHgTdAlDVUlpMOGP {
  51. opacity: 0 !important;
  52. height: 5px !important;
  53. }
  54. .pStAbHgTdAlDVUlpMOGP > span {
  55. display: none;
  56. }
  57. /*斜体样式*/
  58. .flow-markdown-body em.proced{
  59. display: none !important;
  60. }
  61. .flow-markdown-body em.vel-em-action {
  62. display: block !important;
  63. clear: both !important;
  64. color: #FF69B4 !important;
  65. font-style: normal !important;
  66. }
  67. .flow-markdown-body em.vel-em-other {
  68. display: inline-block !important;
  69. clear: none !important;
  70. color: #FF69B4 !important;
  71. font-style: normal !important;
  72. }
  73. `;
  74. document.head.appendChild(style);
  75. let pendingNodes = new Array();
  76.  
  77. let timer = null;
  78.  
  79. let observer = new MutationObserver(mutations=>{
  80. mutations.forEach(mutation=>{
  81. if(mutation.type === 'childList' || mutation.type === "characterData"){
  82. let newPush = false;
  83. mutation.addedNodes.forEach((node)=>{
  84. if(node.matches && (node.matches(".vel-em-action") || node.matches(".vel-em-other"))) return;
  85. pendingNodes.push(node);
  86. newPush = true;
  87. })
  88. if(newPush) PostProc();
  89. }
  90. })
  91. });
  92. // 获取textnode
  93. function getTextNodes(ele) {
  94. if (ele.nodeType == 3) return [ele];
  95. const nodes = ele.childNodes;
  96. const textnodes = [];
  97. for (const i in nodes) {
  98. if (nodes[i].nodeType == 3) {
  99. textnodes.push(nodes[i]);
  100. } else {
  101.  
  102. const r = getTextNodes(nodes[i]);
  103. for (const tn of r) {
  104. textnodes.push(tn);
  105. }
  106. }
  107. }
  108. return textnodes;
  109. }
  110. // 后处理
  111. function PostProc(delay = 50) {
  112. if(timer) clearTimeout(timer);
  113. timer = setTimeout(()=>{
  114. const _pendingNodes = [...new Set(pendingNodes)];
  115. let node;
  116. while(node = _pendingNodes.shift()) {
  117. if(!node.querySelectorAll) continue;
  118. if(node.textContent.match(/\*\([^\)]+?\)\*/)) {
  119. const nl = getTextNodes(node);
  120. for(const n of nl) {
  121. if(n.nodeValue.match(/\*\([^\)]+?\)\*/)){
  122. const newNode = document.createElement("span");
  123. newNode.innerHTML = n.nodeValue.replaceAll(/\*\(([^\)]+?)\)\*/g, `<em class="vel-em-action">$1</em>`);
  124. n.replaceWith(newNode);
  125. }
  126. }
  127. }else if(node.tagName.toLowerCase() == "em") {
  128. if(node.matches(".proced") || node.matches(".vel-em-action") || node.matches(".vel-em-other")) continue;
  129. if(node.textContent.match(/^[\((].+?[\))]$/)) {
  130. const em = document.createElement("em");
  131. em.textContent = node.textContent.replaceAll(/[\(\)()]/g,"");
  132. em.classList.add("vel-em-action");
  133. node.classList.add("proced");
  134. node.after(em);
  135. }
  136. else node.classList.add("vel-em-other");
  137. }else if(node.matches(".math-inline")){
  138. if(node.parentElement.querySelector(".vel-em-action")) continue;
  139. const em = document.createElement("em");
  140. em.textContent = node.textContent.replaceAll(/[\(\)()]/g,"");
  141. em.classList.add("vel-em-action");
  142. node.parentElement.classList.remove("vel-em-other");
  143. node.parentElement.classList.add("proced");
  144. node.parentElement.after(em);
  145. }else{
  146. node.querySelectorAll(`em:not(.vel-em-action, .vel-em-other)`).forEach(n=>{
  147. if(n.textContent.match(/^[\((].+?[\))]$/)) {
  148. if(n.parentElement.querySelector(".vel-em-action")) return;
  149. const em = document.createElement("em");
  150. em.textContent = n.textContent.replaceAll(/[\(\)()]/g,"");
  151. em.classList.add("vel-em-action");
  152. n.classList.add("proced");
  153. n.after(em);
  154. }
  155. else n.classList.add("vel-em-other");
  156. })
  157. }
  158. }
  159. }, delay);
  160. }
  161. const config = { childList: true, subtree: true,characterData: true };
  162. const targetNode = document.body;
  163. observer.observe(targetNode, config);
  164. })();