Character.AI Text Color

Changes the color of all text except the text within "Quotation Marks"

当前为 2023-08-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Character.AI Text Color
  3. // @namespace Character.AI Text Color by Vishanka
  4. // @match https://*.character.ai/*
  5. // @grant none
  6. // @license MIT
  7. // @version 1.2
  8. // @author Vishanka via chatGPT
  9. // @description Changes the color of all text except the text within "Quotation Marks"
  10. // @icon https://i.imgur.com/ynjBqKW.png
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. var css = "p { color: #958C7F !important; font-family: 'Noto Sans', sans-serif !important; }";
  15.  
  16.  
  17.  
  18. var head = document.getElementsByTagName("head")[0];
  19. var style = document.createElement("style");
  20. style.setAttribute("type", 'text/css');
  21. style.innerHTML = css;
  22. head.appendChild(style);
  23. })();
  24.  
  25. function changeColors() {
  26. const pTags = document.getElementsByTagName('p');
  27. for (let i = 0; i < pTags.length; i++) {
  28. const pTag = pTags[i];
  29. if (pTag.dataset.colorChanged === 'true' || pTag.querySelector('code')) {
  30. continue;
  31. }
  32. let text = pTag.innerHTML;
  33.  
  34. const aTags = pTag.getElementsByTagName('a'); // Get all <a> tags within the <p> tag
  35.  
  36. // Remove the <a> tags temporarily
  37. for (let j = 0; j < aTags.length; j++) {
  38. const aTag = aTags[j];
  39. text = text.replace(aTag.outerHTML, 'REPLACE_ME_' + j); // Use a placeholder to be able to restore the links later
  40. }
  41.  
  42.  
  43. //Changes Text within Quotation Marks to white
  44. if (text.match(/(["“”«»].*?["“”«»])/)) {
  45. text = text.replace(/(["“”«»].*?["“”«»])/g, '<span style="color: #FFFFFF">$1</span>');
  46. }
  47.  
  48. //Changes Italic Text to gold
  49. if (text.match(/<em>(.*?)<\/em>/)) {
  50. text = text.replace(/<em>(.*?)<\/em>/g, '<span style="color: #E0DF7F; font-style: italic;">$1</span>');
  51. }
  52.  
  53.  
  54. // Restore the <a> tags
  55. for (let j = 0; j < aTags.length; j++) {
  56. const aTag = aTags[j];
  57. text = text.replace('REPLACE_ME_' + j, aTag.outerHTML);
  58. }
  59.  
  60. pTag.innerHTML = text;
  61. pTag.dataset.colorChanged = 'true';
  62. }
  63. console.log('Changed colors');
  64. }
  65.  
  66. // Observe changes in the document and call changeColors() whenever mutations occur
  67. const observer = new MutationObserver(changeColors);
  68. observer.observe(document, { subtree: true, childList: true });
  69.  
  70. // Initially apply the color changes
  71. changeColors();

QingJ © 2025

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