Character.AI Text Color

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

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

  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.3
  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 (
  30. pTag.dataset.colorChanged === 'true' ||
  31. pTag.querySelector('code') ||
  32. pTag.querySelector('img')
  33. ) {
  34. continue;
  35. }
  36. let text = pTag.innerHTML;
  37.  
  38. const aTags = pTag.getElementsByTagName('a'); // Get all <a> tags within the <p> tag
  39.  
  40. // Remove the <a> tags temporarily
  41. for (let j = 0; j < aTags.length; j++) {
  42. const aTag = aTags[j];
  43. text = text.replace(aTag.outerHTML, 'REPLACE_ME_' + j); // Use a placeholder to be able to restore the links later
  44. }
  45.  
  46.  
  47. //Changes Text within Quotation Marks to white
  48. if (text.match(/(["“”«»].*?["“”«»])/)) {
  49. text = text.replace(/(["“”«»].*?["“”«»])/g, '<span style="color: #FFFFFF">$1</span>');
  50. }
  51. //Changes Text within Quotation Marks and a comma at the end to orange
  52. if (text.match(/(["“”«»][^"]*?,["“”«»])/)) {
  53. text = text.replace(/(["“”«»][^"]*?,["“”«»])/g, '<span style="color: #E0DF7F">$1</span>');
  54. }
  55. //Changes Italic Text to gold
  56. if (text.match(/<em>(.*?)<\/em>/)) {
  57. text = text.replace(/<em>(.*?)<\/em>/g, '<span style="color: #E0DF7F; font-style: italic;">$1</span>');
  58. }
  59. if (text.match(/(seems)/)) {
  60. text = text.replace(/(seems)/g, '<span style="color: #E0DF7F">$1</span>');
  61. }
  62.  
  63. // Restore the <a> tags
  64. for (let j = 0; j < aTags.length; j++) {
  65. const aTag = aTags[j];
  66. text = text.replace('REPLACE_ME_' + j, aTag.outerHTML);
  67. }
  68.  
  69. pTag.innerHTML = text;
  70. pTag.dataset.colorChanged = 'true';
  71. }
  72. console.log('Changed colors');
  73. }
  74.  
  75. // Observe changes in the document and call changeColors() whenever mutations occur
  76. const observer = new MutationObserver(changeColors);
  77. observer.observe(document, { subtree: true, childList: true });
  78.  
  79. // Initially apply the color changes
  80. changeColors();