OpenRaid Highlight

Highlights the selected keyword in the chat when it's posted

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         OpenRaid Highlight
// @version      1.1
// @namespace	 chawan
// @description  Highlights the selected keyword in the chat when it's posted
// @author       Chawan
// @match        http://openraid.eu/chat
// @match	 http://openraid.us/chat
// ==/UserScript==

var ChatBoxBody;
var Keyword = "";
var matchAll = true;

$(document).ready(function() {
     ChatBoxBody = document.getElementById("body");

    if(ChatBoxBody !== null) {
        AddInputBox();

        $("#matchButton").click(function() {
            changeMatch();
        });
        $("#highlightKeyword").on('input', function() {
           Keyword = $("#highlightKeyword").val().toLowerCase();
           console.log(Keyword);
        });
        setInterval(HighlightMessage, 1000);
    }
});

function AddInputBox() {
    console.log("We have the chatbox body and content");

    var inputField = document.createElement("input");
    inputField.setAttribute("id", "highlightKeyword");
    inputField.setAttribute("size", "100");
    inputField.setAttribute("autocomplete", "off");
    inputField.setAttribute("placeholder", "Enter a keyword to highlight in chat");
    inputField.style.float = "left";
    inputField.style.border = "1px solid #004455";
    inputField.style.borderRadius = "5px";
    inputField.style.marginLeft = "0px";
    inputField.style.marginTop = "5px";
    inputField.style.background = "#0F1219";
    inputField.style.color = "White";
    inputField.style.fontSize = "14px";

    var matchButton = document.createElement("button");
    matchButton.setAttribute("class", "btn btn-success");
    matchButton.setAttribute("id", "matchButton");
    matchButton.innerHTML = "Match all";
    matchButton.style.top = "1px";
    matchButton.style.position = "relative";
    matchButton.style.marginLeft = "5px";
    matchButton.style.marginTop = "5px";

    ChatBoxBody.appendChild(inputField);
    ChatBoxBody.appendChild(matchButton);
}

function HighlightMessage() {
    $(".chatline").each(function(index) {
        //console.log($(this).find(".messageText").text());
        if(wordInString($(this).find(".messageText").text().toLowerCase(), Keyword) && $(this).find(".messageText").css("background-color") != "rgb(255, 0, 0)" && Keyword.length > 0) {
            $(this).css("background-color", "rgb(255, 0, 0)");
        }
        else if($(this).css("background-color") == "rgb(255, 0, 0)") {
            $(this).css("background-color", "");
        }
    });
}

function changeMatch() {
    if (matchAll) {
        matchAll = false;
        $("#matchButton").html("Match word");
    } else {
        $("#matchButton").html("Match all");
        matchAll = true;
    }
}

function wordInString(s, word) {
    if (matchAll == true) {
        return s.indexOf(word) >= 0;
    } else {
        return new RegExp( '\\b' + word + '\\b', 'i').test(s);
    }
}