Greasy Fork

Greasy Fork is available in English.

치지직 채팅 닉네임 색상

치지직 채팅의 닉네임 색상을 트위치와 비슷하게 변경

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         치지직 채팅 닉네임 색상
// @namespace    https://yoonu.io/
// @version      2023-12-19
// @description  치지직 채팅의 닉네임 색상을 트위치와 비슷하게 변경
// @author       Yoonu
// @match        https://chzzk.naver.com/live/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chzzk.naver.com
// @grant        none
// @license MIT
// ==/UserScript==


const color_list = [
    "rgb(255, 0, 0)",
    "rgb(0, 0, 255)",
    "rgb(0, 128, 0)",
    "rgb(178, 34, 34)",
    "rgb(255, 127, 80)",
    "rgb(154, 205, 50)",
    "rgb(255, 69, 0)",
    "rgb(46, 139, 87)",
    "rgb(218, 165, 32)",
    "rgb(210, 105, 30)",
    "rgb(95, 158, 160)",
    "rgb(30, 144, 255)",
    "rgb(255, 105, 180)",
    "rgb(138, 43, 226)",
    "rgb(0, 255, 127)"
];

(function() {
    'use strict';

    const callback = () => {
        const targetNode = document.querySelector("#layout-body > section > aside > div[role='log'] > div");
        if(targetNode) {
            colorizeChat(targetNode)
            observer.disconnect();
        }
    }

    const observer = new MutationObserver(callback);
    observer.observe(document, { attributes: false, childList: true, subtree: true });
})();

const colorizeChat = (chatNode) => {
    const callback = (mutationList, observer) => {
        for (const mutation of mutationList) {
            if (mutation.type !== "childList")
                continue

            for(let addedNode of mutation.addedNodes) {
                const nickNode = addedNode.querySelector(".name_text__yQG50");
                setNicknameColor(nickNode)
            }
        }
    };

    const observer = new MutationObserver(callback);
    observer.observe(chatNode, { attributes: false, childList: true, subtree: true });
}
const setNicknameColor = (node) => {
    const nickname = node.innerText;
    let val = 0;
    if (nickname.length > 0) {
        for (let i = 0; i < nickname.length; i++)
            val += nickname.charCodeAt(i);
    }

    node.style.color = color_list[val % color_list.length];
}