Character.AI Text Color

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

目前為 2023-08-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Character.AI Text Color
// @namespace   Character.AI Text Color by Vishanka
// @match       https://*.character.ai/*
// @grant       none
// @license     MIT
// @version     1.3
// @author      Vishanka via chatGPT
// @description Changes the color of all text except the text within "Quotation Marks"
// @icon        https://i.imgur.com/ynjBqKW.png
// ==/UserScript==

(function() {
var css = "p { color: #958C7F !important; font-family: 'Noto Sans', sans-serif !important; }";



  var head = document.getElementsByTagName("head")[0];
  var style = document.createElement("style");
  style.setAttribute("type", 'text/css');
  style.innerHTML = css;
  head.appendChild(style);
})();

function changeColors() {
    const pTags = document.getElementsByTagName('p');
    for (let i = 0; i < pTags.length; i++) {
        const pTag = pTags[i];
        if (
            pTag.dataset.colorChanged === 'true' ||
            pTag.querySelector('code') ||
            pTag.querySelector('img')
        ) {
            continue;
    }
    let text = pTag.innerHTML;

    const aTags = pTag.getElementsByTagName('a'); // Get all <a> tags within the <p> tag

    // Remove the <a> tags temporarily
    for (let j = 0; j < aTags.length; j++) {
      const aTag = aTags[j];
      text = text.replace(aTag.outerHTML, 'REPLACE_ME_' + j); // Use a placeholder to be able to restore the links later
    }


        //Changes Text within Quotation Marks to white
        if (text.match(/(["“”«»].*?["“”«»])/)) {
        text = text.replace(/(["“”«»].*?["“”«»])/g, '<span style="color: #FFFFFF">$1</span>');
        }
        //Changes Text within Quotation Marks and a comma at the end to orange
        if (text.match(/(["“”«»][^"]*?,["“”«»])/)) {
        text = text.replace(/(["“”«»][^"]*?,["“”«»])/g, '<span style="color: #E0DF7F">$1</span>');
        }
        //Changes Italic Text to gold
        if (text.match(/<em>(.*?)<\/em>/)) {
        text = text.replace(/<em>(.*?)<\/em>/g, '<span style="color: #E0DF7F; font-style: italic;">$1</span>');
        }
        if (text.match(/(seems)/)) {
        text = text.replace(/(seems)/g, '<span style="color: #E0DF7F">$1</span>');
        }

    // Restore the <a> tags
    for (let j = 0; j < aTags.length; j++) {
      const aTag = aTags[j];
      text = text.replace('REPLACE_ME_' + j, aTag.outerHTML);
    }

    pTag.innerHTML = text;
    pTag.dataset.colorChanged = 'true';
  }
  console.log('Changed colors');
}

// Observe changes in the document and call changeColors() whenever mutations occur
const observer = new MutationObserver(changeColors);
observer.observe(document, { subtree: true, childList: true });

// Initially apply the color changes
changeColors();