FE Chat Highlighter

Highlight FE chat

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         FE Chat Highlighter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Highlight FE chat
// @author       Natty_Boh
// @include      https://www.finalearth.com/*
// @include      https://finalearth.com/*
// ==/UserScript==

highlight()
listen()

/*
********
USER EDITABLE SECTION STARTS HERE

keywordsToHighlight -- highlight username by default.
Add additional keywords by adding them inside double quotes and comma separated (case insensitive), examples [userName, "natty", "nat"]

userNameColor - color of your name in message you sent

keywordHighlightColor - highlight color of messages containing your selected keywords

https://www.w3schools.com/colors/colors_names.asp see options here for different colors you can replace with to customize your color scheme

********
*/

let keywordsToHighlight = [userName]
let userNameColor = "crimson"
let keywordHighlightColor = "lightPink"

/*
********
USER EDITABLE SECTION ENDS HERE
********
*/

function listen() {
   var observer = new MutationObserver(function(mutations) {
			mutations.forEach(function(m) {
				if (m.addedNodes[1] && m.addedNodes[1].classList && m.addedNodes[1].classList.contains("message")) {
                    highlight()
				}
			}
		)});

    var target = document.querySelector(".chat-box-wrap");
    var config = {
        childList: true,
        subtree: true
    }

    observer.observe(target, config);

}

function highlight(){
    document.querySelectorAll('a').forEach( e => {
        if (e.textContent.includes(userName)) {
            e.style.color = 'crimson'
        }
    });
     document.querySelectorAll('.message > span').forEach( e => {
         var text = e.textContent.toLowerCase();
        if (keywordsToHighlight.some(element => text.includes(element.toLowerCase()))) {
            e.style.backgroundColor = 'lightPink'
        }
    });



}