IdlePixel Chat Highlighter

Highlights messages containing specified words.

目前为 2023-03-10 提交的版本。查看 最新版本

// ==UserScript==
// @name         IdlePixel Chat Highlighter
// @namespace    lbtechnology.info
// @version      1.0.0
// @description  Highlights messages containing specified words.
// @author       Lux-Ferre
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require      https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
// ==/UserScript==
 
(function() {
    'use strict';
 
    class HighlightPlugin extends IdlePixelPlusPlugin {
        constructor() {
            super("highlighting", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                },
                config: [{
                    type: "label",
                    label: "Message Highlighting:"
                },
                {
                    id: "wordList",
                    label: "List of trigger words. Separate each trigger word with a comma",
                    type: "string",
                    max: 2000,
                    default: ""
                },
                {
                    id: "soundsEnabled",
                    label: "Play a sound when being pinged?",
                    type: "boolean",
                    default: true
                },
                {
                    id: "ignoreCase",
                    label: "Ignore case-sensitivity?",
                    type: "boolean",
                    default: true
                }
            ]
            });
            this.previous = "";
        }

        addHighlightedMessage(message) {
            const username = message.username;
            const sigil = message.sigil;
            const level = message.level;
            const chatMessage = message.message;
            const newMessage = `<div style="background-color: rgba(0, 255, 0, 0.15)"><span class="color-green">${Chat._get_time()} </span> <img src="https://d1xsc8x7nc5q8t.cloudfront.net/images/${sigil}.png"> <span class=""></span> <a target="_blank" class="chat-username" href="https://idle-pixel.com/hiscores/search?username=${username}" style="color: rgb(198, 70, 0);">${username}</a><span class="color-grey"> (${level}): </span>${chatMessage}</div>`
            $("#chat-area").append(newMessage);
        }
  
        onChat(data) {
            const ignoreCase = this.getConfig("ignoreCase");
            const rawWordList = this.getConfig("wordList").split(',');
            if (ignoreCase) {
                var message = data.message.toLowerCase();
                var wordList = rawWordList.map(word => word.toLowerCase());
            }
            else {
                var message = data.message;
                var wordList = rawWordList;
            }
           
            if (wordList.some(word => message.includes(word))) {
                const element = $("#chat-area > *").last();
                this.addHighlightedMessage(data);
                element.remove();
                if (this.getConfig("soundsEnabled")){Sounds.play(Sounds.VARIABLE_POWER_UP);}
            }
        }
     }
 
    const plugin = new HighlightPlugin();
    IdlePixelPlus.registerPlugin(plugin);
 
})();