colorblind text helper

change all red text color to preferred one

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         colorblind text helper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  change all red text color to preferred one
// @author       Something begins
// @license      none
// @include       https://*
// @grant        none
// ==/UserScript==

const shadeCoef = 80;
const toColor = "purple";
// Function to check if an element is a text element
function isTextElement(element) {
    return element.nodeType === Node.TEXT_NODE;
}

// Function to check if a text element has a red color
function isRedText(element) {
    const parentElement = element.parentElement;
    if (!parentElement) {
        return false;
    }

    const computedStyle = window.getComputedStyle(parentElement);
    const color = computedStyle.color;

    if (color.startsWith('rgb(')) {
        const rgb = color.match(/\d+/g);
        const red = parseInt(rgb[0]);
        const green = parseInt(rgb[1]);
        const blue = parseInt(rgb[2]);

        if (red > green + shadeCoef && red > blue + shadeCoef) {
            return true;
        }
    } else if (color.startsWith('#')) {
        const hex = color.substr(1);
        const red = parseInt(hex.substr(0, 2), 16);
        const green = parseInt(hex.substr(2, 2), 16);
        const blue = parseInt(hex.substr(4, 2), 16);

        if (red > green + shadeCoef && red > blue + shadeCoef) {
            return true;
        }
    }

    return false;
}

// Get all text nodes on the page
const walker = document.createTreeWalker(
    document.body,
    NodeFilter.SHOW_TEXT,
    { acceptNode: node => NodeFilter.FILTER_ACCEPT }
);

const textNodes = [];
while (walker.nextNode()) {
    textNodes.push(walker.currentNode);
}

// Filter text nodes that are red
const redTextNodes = textNodes.filter(isRedText);

// Log red text nodes
redTextNodes.forEach(textNode => {
    console.log('Red text:', textNode);
    textNode.parentElement.style.color = toColor;
});