DeKleineKobini / TORN: Faction Armory Log

// ==UserScript==
// @name         TORN: Faction Armory Log
// @version      1.0.1
// @author       DeKleineKobini
// @description  Highlight the log with certain words.
// @namespace    dekleinekobini.factionarmorylog
// @require      https://openuserjs.org/src/libs/DeKleineKobini/DKK_Torn_Utilities.js
// @match        https://www.torn.com/factions.php?*
// @license      MIT
// @updateURL    https://openuserjs.org/meta/DeKleineKobini/TORN_Faction_Armory_Log.meta.js
// @connect      api.torn.com
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

var settings = {
    highlight: [
        "Xanax",
        "Can of",
        "Feathery Hotel Coupon"
    ]
};

setDebug(false);

/* --------------------
CODE - EDIT ON OWN RISK
-------------------- */
setPrefixEasy("FAL");

var observer;

checkListeners();

$(window).bind('hashchange', function() {
    checkListeners();
});

function checkListeners() {
    let hash = window.location.hash;
    if (!hash.includes("tab")) {
        observeMutations(document, "#tab4-4", true, function(mut, obs) {
            observeMutationsFull($("#tab4-4 > ul").get(0), function(mut, obs) {
                let list = $("#tab4-4 > ul > li");


                list.each(function() {
                    let row = $(this);
                    let text = row.html();

                    let found = false;
                    for (let i in settings.highlight) {
                        let word = settings.highlight[i];
                        if (!text.includes(word)) continue;

                        log(`Found '${word}' in '${text}'.`)
                        found = true;
                        break;
                    }

                    if (found) {
                        row.css("background", "gold");
                    }
                });
            });
        }, { childList: true, subtree: true });
    } else {
        observer.disconnect();
        observer = null;
    }
}