Kekeke Highlight

Highlight same user in Kekeke chat

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Kekeke Highlight
// @name:zh-TW   Kekeke Highlight
// @namespace    https://greasyfork.org
// @version      0.0.1
// @description  Highlight same user in Kekeke chat
// @description:zh-tw 在kekeke聊天室中,嗨賴指定使用者的留言。
// @author       george7551858
// @icon         http://www.google.com/s2/favicons?domain=https://kekeke.cc/
// @include      https://kekeke.cc/*
// @include      https://www.kekeke.cc/*
// @license      MIT
// @grant        none
// ==/UserScript==

window.addEventListener('load', function() {
    'use strict';

    var highLightColor = 'yellow';
    var lastTargetColor;

    console.log('Kekeke Highlight: start');

    document.addEventListener('click', function (e) {
        if (e.originalTarget.classList.contains('SquareCssResource-message')
            || e.originalTarget.classList.contains('SquareCssResource-messageContainer')) {
            doHighLight(e.originalTarget);
        }
    });

    var doHighLight = function(target){
        var targetChatContent = target.closest('.SquareCssResource-chatContent');
        var targetColorNickname = targetChatContent.querySelector('.GlobalCssResource-colorNickname');
        var targetNameColor = targetColorNickname.style.color;
        console.log('Kekeke Highlight: %c' + targetColorNickname.innerText + ' ' + targetNameColor,
                    'color:' + targetNameColor);

        if (targetNameColor == lastTargetColor) {
            console.log('Kekeke Highlight: cancel');
            targetNameColor = '?';
        }

        document.querySelectorAll('.SquareCssResource-chatContent').forEach(function(item){
            item.style.backgroundColor = ''; // clear all highlight

            var chatNameColor = item.querySelector('.GlobalCssResource-colorNickname').style.color;
            if (chatNameColor == targetNameColor) {
                item.style.backgroundColor = highLightColor;
            }
        });

        lastTargetColor = targetNameColor;
    };
});