Kekeke Highlight

在kekeke聊天室中,嗨賴指定使用者的留言。

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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;
    };
});